Improve Scene Loading
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class CallAfterDelay : MonoBehaviour
|
||||
{
|
||||
float delay;
|
||||
System.Action action;
|
||||
|
||||
// Will never call this frame, always the next frame at the earliest
|
||||
public static CallAfterDelay Create(float delay, System.Action action)
|
||||
{
|
||||
CallAfterDelay cad = new GameObject("CallAfterDelay").AddComponent<CallAfterDelay>();
|
||||
cad.delay = delay;
|
||||
cad.action = action;
|
||||
return cad;
|
||||
}
|
||||
|
||||
float age;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (age > delay)
|
||||
{
|
||||
action();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
void LateUpdate()
|
||||
{
|
||||
age += Time.deltaTime;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d30491b056a700f48b6af3b340ae0caf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,7 +7,8 @@ using UnityEngine.SceneManagement;
|
||||
public class UmaSceneController:MonoBehaviour
|
||||
{
|
||||
public static UmaSceneController instance;
|
||||
|
||||
public GameObject CavansPrefab;
|
||||
public GameObject CavansInstance;
|
||||
private void Awake()
|
||||
{
|
||||
if (instance)
|
||||
@@ -18,19 +19,21 @@ public class UmaSceneController:MonoBehaviour
|
||||
DontDestroyOnLoad(this);
|
||||
}
|
||||
|
||||
public void LoadScene(string name, Action onNewSceneLoaded, Action onPrevSceneUnLoaded)
|
||||
public void LoadScene(string name, Action OnSceneloaded, Action OnLastSceneUnloaded)
|
||||
{
|
||||
StartCoroutine(LoadLiveSceneAsync("LiveScene", onNewSceneLoaded, onPrevSceneUnLoaded));
|
||||
StartCoroutine(LoadLiveSceneAsync(name, OnSceneloaded, OnLastSceneUnloaded));
|
||||
}
|
||||
|
||||
IEnumerator LoadLiveSceneAsync(string sceneName, Action onNewSceneLoaded, Action onPrevSceneUnLoaded)
|
||||
IEnumerator LoadLiveSceneAsync(string sceneName, Action OnSceneloaded, Action OnLastSceneUnloaded)
|
||||
{
|
||||
AsyncOperation asyncTransitionLoad = SceneManager.LoadSceneAsync("TransitionScene", LoadSceneMode.Additive);
|
||||
yield return new WaitUntil(() => asyncTransitionLoad.isDone);
|
||||
|
||||
Animation loadingCanvas = GameObject.Find("LoadingCanvas").GetComponent<Animation>();
|
||||
loadingCanvas.Play("SceneTransition_s");
|
||||
yield return new WaitUntil(() => !loadingCanvas.isPlaying);
|
||||
if (CavansInstance)
|
||||
{
|
||||
Destroy(CavansInstance);
|
||||
}
|
||||
CavansInstance = Instantiate(CavansPrefab, transform);
|
||||
var animation = CavansInstance.GetComponent<Animation>();
|
||||
animation.Play("SceneTransition_s");
|
||||
yield return new WaitUntil(() => !animation.isPlaying);
|
||||
|
||||
// Set the current Scene to be able to unload it later
|
||||
Scene currentScene = SceneManager.GetActiveScene();
|
||||
@@ -41,21 +44,17 @@ public class UmaSceneController:MonoBehaviour
|
||||
// Wait until the last operation fully loads to return anything
|
||||
yield return new WaitUntil(()=> asyncLoad.isDone);
|
||||
|
||||
onNewSceneLoaded.Invoke();
|
||||
OnSceneloaded.Invoke();
|
||||
|
||||
// Unload the previous Scene
|
||||
AsyncOperation asyncUnLoad = SceneManager.UnloadSceneAsync(currentScene);
|
||||
yield return new WaitUntil(() => asyncUnLoad.isDone);
|
||||
|
||||
OnLastSceneUnloaded.Invoke();
|
||||
|
||||
onPrevSceneUnLoaded.Invoke();
|
||||
|
||||
loadingCanvas.Play("SceneTransition_e");
|
||||
yield return new WaitUntil(() => !loadingCanvas.isPlaying);
|
||||
|
||||
// Unload the Transition Scene
|
||||
AsyncOperation asyncTransitionUnLoad = SceneManager.UnloadSceneAsync("TransitionScene");
|
||||
yield return new WaitUntil(() => asyncTransitionUnLoad.isDone);
|
||||
animation.Play("SceneTransition_e");
|
||||
yield return new WaitUntil(() => !animation.isPlaying);
|
||||
Destroy(CavansInstance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -665,10 +665,8 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
{
|
||||
GameObject MainLive = new GameObject("Live");
|
||||
GameObject Director = new GameObject("Director");
|
||||
//Gallop.Live.Director.instance.Play();
|
||||
List<GameObject> transferObjs = new List<GameObject>() {
|
||||
MainLive,
|
||||
Director,
|
||||
GameObject.Find("ViewerMain"),
|
||||
GameObject.Find("Camera"),
|
||||
GameObject.Find("Directional Light"),
|
||||
@@ -678,7 +676,6 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
UmaSceneController.instance.LoadScene("LiveScene",
|
||||
delegate ()
|
||||
{
|
||||
|
||||
// Move the GameObject (you attach this in the Inspector) to the newly loaded Scene
|
||||
transferObjs.ForEach(o => SceneManager.MoveGameObjectToScene(o, SceneManager.GetSceneByName("LiveScene")));
|
||||
|
||||
@@ -699,11 +696,10 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
LoadLiveUma(characters);
|
||||
|
||||
Gallop.Live.Director.instance.InitializeTimeline();
|
||||
|
||||
},
|
||||
delegate ()
|
||||
{
|
||||
Gallop.Live.Director.instance.InitializeTimeline();
|
||||
Gallop.Live.Director.instance.Play(live.MusicId, characters[0].CharaEntry.Id);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -198,6 +198,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
public void LoadedAssetsAdd(UmaDatabaseEntry entry)
|
||||
{
|
||||
if (!LoadedAssetsPanel) return;
|
||||
foreach (UmaUIContainer ui in LoadedAssetsPanel.GetComponentsInChildren<UmaUIContainer>())
|
||||
{
|
||||
if (ui.Name == Path.GetFileName(entry.Name)) return;
|
||||
@@ -589,9 +590,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
{
|
||||
LiveTime = true;
|
||||
SetEyeTrackingEnable(false);
|
||||
CallAfterDelay.Create(0, () => {
|
||||
Builder.LoadLive(currentLive, new List<LiveCharacterSelect>(selectlist));
|
||||
});
|
||||
Builder.LoadLive(currentLive, new List<LiveCharacterSelect>(selectlist));
|
||||
LiveSelectPannel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user