This commit is contained in:
Gerard Gascón 2025-04-24 17:37:25 +02:00
commit 341a877b4a
2338 changed files with 1346408 additions and 0 deletions

46
Assets/Scripts/Loader.cs Normal file
View file

@ -0,0 +1,46 @@
using System;
using System.Collections;
using System.Collections.Generic;
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");
}
static IEnumerator LoadSceneAsync(int 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 0;
}
}
public static void LoaderCallback(){
if(onLoaderCallback != null){
onLoaderCallback();
onLoaderCallback = null;
}
}
}