using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
IEnumerator Start() {
AsyncOperation async = Application.LoadLevelAsync("MyBigLevel");
yield return async;
Debug.Log("Loading complete");
}
}
(추가설명)
유니티는 백그라운드 로딩 스레드에서 씬 안의 모든 에셋과 객체들을 완전히 불러올 것입니다.
이 기능은 사용자가 현재 진행중인 레벨을 플레이 하는 와중에 새로운 레벨을 불러올 수 있도록 해주거나,
진행 상황 바를 보여주거나 또는 사용자가 세계의 서로 각기 다른 부분들이 플레이어의 위치에 따라 끊임없이 로드되고
언로드되는 완전한 스트리밍된 세계를 게임 플레이에 지장없이 생성할 수 있도록 해줍니다.
AsyncOperation
비동기적으로 코루틴을 수행합니다. 이러한 수행이 이어지기 전까지.
yield 기능을 사용할 수 있고, isDone 또는 progress 를 사용해서 완료가 되었는지 진행중인지 수동으로 확인할 수 있습니다.
얼마나 로드되었다가 필요한게 아니라면
void OnLevelWasLoaded(int level) { } 을 사용하는 방법도 있다.
MonoBehaviour를 상속받는 스크립트드은 해당신이 로드가 완료되었을 때 위 함수를 재정의(오버라이딩) 해놓았다면,
해당 함수로 이벤트가 날라온다.
씬을 로딩 호출 한 뒤에
if(Application.isLoadingLevel == false) // 로딩 중이 아니라면
을 체크하는 방법도 있다.
유니티 5.3부터 멀티 씬 편집(Multi-Scene Editing)을 지원함에 따라
Application.LoadLevel로 씬 이동하던 방법을
SceneManager.LoadScene으로 사용하라고 권고한다.
using;UnityEngine.SceneManagement라는 네임스페이스를 필요로 한다.
이제 하이어라키 뷰에 씬이 여러개 열린다.
http://worksp.tistory.com/10 <- 참고 하여 잘 정리된 아래를 긁어왔다... 감사합니다.
// old
Application.LoadLevel(0); // 로드.
Application.LoadLevel("SceneName");
AsyncOperation ao = Application.LoadLevelAsync(0); // 로드. (비동기)
AsyncOperation ao = Application.LoadLevelAsync("SceneName");
Application.LoadLevelAdditive(0); // 씬 병합 추가.
Application.LoadLevelAdditive("SceneName");
Application.LoadLevelAdditiveAsync(0); // 씬 병합 추가. (비동기)
Application.LoadLevelAdditiveAsync("SceneName");
Application.UnloadLevel(0); // 언로드.
Application.UnloadLevel("SceneName");
Application.levelCount; // BuildSetting 에 등록 된 씬 개수.
Application.loadedLevel; // 현재 씬 인덱스.
Application.loadedLevelName; // 현재 씬 이름.
// 5.3
SceneManager.LoadScene(0); // 로드.
SceneManager.LoadScene("SceneName");
AsyncOperation ao = SceneManager.LoadSceneAsync(0); // 로드. (비동기)
AsyncOperation ao = SceneManager.LoadSceneAsync("SceneName");
SceneManager.LoadScene(0, LoadSceneMode.Additive); // 씬 병합 추가.
SceneManager.LoadScene("SceneName", LoadSceneMode.Additive);
SceneManager.LoadSceneAsync(0, LoadSceneMode.Additive); // 씬 병합 추가. (비동기)
SceneManager.LoadSceneAsync("SceneName", LoadSceneMode.Additive);
SceneManager.UnloadScene(0); // 언로드.
SceneManager.UnloadScene("SceneName");
SceneManager.sceneCount; // 현재 로드 된 씬 개수.
SceneManager.sceneCountInBuildSettings; // BuildSetting 에 등록 된 씬 개수.
SceneManager.GetActiveScene().buildIndex; // 현재 씬 인덱스.
SceneManager.GetActiveScene().name; // 현재 씬 이름.
// 씬 정보 조회.
Scene activeScene = SceneManager.GetActiveScene();
Scene scene1 = SceneManager.GetSceneAt(0);
Scene scene2 = SceneManager.GetSceneByName("SceneName");
Scene scene3 = SceneManager.GetSceneByPath("Assets/SceneName.unity");
Scene[] loadedScenes = SceneManager.GetAllScenes();
// Scene 구조체.
int buildIndex;
string name;
string path;
bool isLoaded;
bool isDirty; // 씬을 변경(수정)했는지 여부.
int rootCount; // 씬의 Root에 있는 GameObject 개수.
bool IsValid(); // 유효한 씬인지 여부.
// 기타.
Scene scene = gameObject.scene; // 게임오브젝트가 속해있는 씬을 가져오기.
GameObject go = new GameObject("New Object"); // 게임오브젝트를 생성하면 현재 씬에 추가 됨.
SceneManager.MoveGameObjectToScene(go, scene); // 게임오브젝트를 다른 씬으로 이동.
SceneManager.MergeScenes(sourceScene, destinationScene); // 씬을 병합.
// SceneManager.Get~() 으로 가져올 수 있는 것은 로드가 끝난 씬만 가능.
Scene scene = SceneManager.GetSceneByName("SceneName");
bool isValid = scene.IsValid(); // false 가 리턴 됨.
'NOTE > Unity' 카테고리의 다른 글
| [Unity] 데이터 저장(펌) (0) | 2017.01.18 |
|---|---|
| [Unity] 유니티의 친절한 설명 (0) | 2016.11.28 |
| [Unity] 알아둘 것1 (0) | 2016.11.22 |
| [Unity] ( NibiruVR SDK + NIbiruSDK )분석 및 사용법 (0) | 2016.11.21 |
| [Unity] 짧은 개념정리3 (0) | 2016.11.04 |