Unity

[Unity]비동기 Scene 로드하기

Guk-blog 2019. 3. 27. 14:43
728x90
반응형

AsyncOperation

SceneManager.LoadSceneAsync("SceneName");

AsyncOperation과 LoadSceneAsysc를 이용해 메인에서 Start()함수에서 미리 Scene을 로드하고 allowSceneActivation를 false로 설정해 바로 시작하지 않게 만든다


ex)

AsyncOperation async;


void Start(){

StartCoroutine(LoadScene());

}



IEnumerator LoadScene() { yield return null; AsyncOperation async = SceneManager.LoadSceneAsync(GameScene, LoadSceneMode.Additive); async.allowSceneActivation = false; while (!async.isDone) { Debug.Log("async progress : " + (async.progress) + "%" + "\nasync.allowSceneActivation = " + async.allowSceneActivation); if (_gamePlay&&async.progress>=0.9f) async.allowSceneActivation = true; yield return null; } }



void StartGame(){

_gamePlay=true;

}


출처 :https://m.blog.naver.com/PostView.nhn?blogId=pxkey&logNo=221307916592&proxyReferer=https%3A%2F%2Fwww.google.com%2F

728x90
반응형