Add files via upload
This commit is contained in:
parent
82aab308f0
commit
310f5c8838
54 changed files with 2357 additions and 0 deletions
61
Tools/SceneManager/Loader.cs
Normal file
61
Tools/SceneManager/Loader.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public static class Loader{
|
||||
|
||||
class LoadingMonoBehaviour : MonoBehaviour { }
|
||||
|
||||
static Action onLoaderCallback;
|
||||
static AsyncOperation loadingAsyncOperation;
|
||||
|
||||
public static void Load(int scene){
|
||||
onLoaderCallback = () => {
|
||||
GameObject loadingGameObject = new GameObject("LoadingGameObject");
|
||||
loadingGameObject.AddComponent<LoadingMonoBehaviour>().StartCoroutine(LoadSceneAsync(scene));
|
||||
};
|
||||
|
||||
SceneManager.LoadScene("Loading");
|
||||
}
|
||||
public static void Load(string scene){
|
||||
onLoaderCallback = () => {
|
||||
GameObject loadingGameObject = new GameObject("LoadingGameObject");
|
||||
loadingGameObject.AddComponent<LoadingMonoBehaviour>().StartCoroutine(LoadSceneAsync(scene));
|
||||
};
|
||||
|
||||
SceneManager.LoadScene("Loading");
|
||||
}
|
||||
|
||||
static IEnumerator LoadSceneAsync(int scene){
|
||||
yield return null;
|
||||
loadingAsyncOperation = SceneManager.LoadSceneAsync(scene);
|
||||
|
||||
while (!loadingAsyncOperation.isDone){
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
static IEnumerator LoadSceneAsync(string scene){
|
||||
yield return null;
|
||||
loadingAsyncOperation = SceneManager.LoadSceneAsync(scene);
|
||||
|
||||
while (!loadingAsyncOperation.isDone){
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetLoadingProgress(){
|
||||
if(loadingAsyncOperation != null){
|
||||
return loadingAsyncOperation.progress;
|
||||
}else{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoaderCallback(){
|
||||
if(onLoaderCallback != null){
|
||||
onLoaderCallback();
|
||||
onLoaderCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue