How to load new scene asynchronously while displaying progress in Unity(in C#)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
댓글
댓글 쓰기