유니티 C#

유니티에서 비동기적으로 scene을 불러오며 progress를 얻는 방법

죽은쥐 2018. 1. 3. 16:06

using UnityEngine;

using System.Collections;


public delegate void ProgressDelegate(float progress);


public class MyScript {


public void OnStartMyScene() {

StartCoroutine(LoadSceneAsyncByName("MySceneName", OnLoadLevelProgressUpdate));

}

public static IEnumerator LoadSceneAsyncByName(string nextLevel, ProgressDelegate progressDelegate) {

AsyncOperation async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(nextLevel);

while (!async.isDone) {

progressDelegate (async.progress);

async.allowSceneActivation = async.progress > 0.8;

yield return null;

}

}


private void OnLoadLevelProgressUpdate(float progress) {

Debug.Log ("async.progress: " + progress);

}

}





출처: http://crowjdh.blogspot.kr/2016/07/scene-progress-c.html