씬을 비동기로 Load하고 싶을 때

2022. 1. 19. 17:39Unity3D/경험 기록

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

 

Unity - Scripting API: SceneManagement.SceneManager.LoadSceneAsync

You can provide the full Scene path, the path shown in the Build Settings window, or just the Scene name. If you only provide the Scene name, Unity loads the first Scene in the list that matches. If you have multiple Scenes with the same name but different

docs.unity3d.com

https://notyu.tistory.com/33

 

유니티 씬(Scene)과 씬 전환 (Scene Transition)

1. 씬 (Scene) 경찰, 범죄 등과 관련된 영화나 드라마를 보게 되면, Crime Scene이라는 노란색 테이프로 현장을 막아놓은 장면들이 나온다. 범죄에 사용된 물건, 사물 등이 존재하는 사건 현장이 씬이

notyu.tistory.com

보통 LoadScene을 하면

그 문장 이후의 코드는 실행 될 수 없다.

 

그러나 LoadSceneAsync는 

씬을 로드 완료 한 뒤, 그 밑의 문장까지 실행 가능하게 해준다.

 

예시)

        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2");

        // Wait until the asynchronous scene fully loads
        while (!asyncLoad.isDone)
        {
            yield return null;
        }

예시2)

            AsyncOperation operation = SceneManager.LoadSceneAsync("GameScene");
            operation.completed += (oper) => {
                GameMain gameMain = GameObject.FindObjectOfType<GameMain>();
                gameMain.Init(prefabName);