[Unity]비동기 Scene 로드하기
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;
}