Improve Asset Loading

This commit is contained in:
CroakFang
2023-07-13 01:41:59 +08:00
parent 9bc7e58d50
commit 060ca0f259
11 changed files with 1058 additions and 196 deletions
+27 -1
View File
@@ -1,25 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class UmaSceneController:MonoBehaviour
{
public static UmaSceneController instance;
public GameObject CavansPrefab;
public GameObject CavansInstance;
public GameObject LoadingProgressPanel;
public Slider LoadingProgressSlider;
public TextMeshProUGUI LoadingProgressText;
private void Awake()
{
if (instance)
{
Destroy(gameObject);
DestroyImmediate(gameObject);
return;
}
instance = this;
DontDestroyOnLoad(this);
}
private void Start()
{
UmaAssetManager.OnLoadProgressChange += LoadingProgressChange;
}
public static void LoadScene(string name, Action OnSceneloaded = null, Action OnLastSceneUnloaded = null)
{
instance.StartCoroutine(instance.LoadLiveSceneAsync(name, OnSceneloaded, OnLastSceneUnloaded));
@@ -58,5 +70,19 @@ public class UmaSceneController:MonoBehaviour
yield return new WaitUntil(() => !animation.isPlaying);
Destroy(CavansInstance);
}
public void LoadingProgressChange(int curren, int target)
{
if(curren == -1)
{
LoadingProgressPanel.SetActive(false);
}
else
{
LoadingProgressPanel.SetActive(true);
LoadingProgressText.text = $"Loading...({curren}/{target})";
LoadingProgressSlider.value = (float)curren / target;
}
}
}