Update SceneManager (WIP)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class UmaSceneController:MonoBehaviour
|
||||
{
|
||||
public static UmaSceneController instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
instance = this;
|
||||
DontDestroyOnLoad(this);
|
||||
}
|
||||
|
||||
public void LoadScene(string name, Action onNewSceneLoaded, Action onPrevSceneUnLoaded)
|
||||
{
|
||||
StartCoroutine(LoadLiveSceneAsync("LiveScene", onNewSceneLoaded, onPrevSceneUnLoaded));
|
||||
}
|
||||
|
||||
IEnumerator LoadLiveSceneAsync(string sceneName, Action onNewSceneLoaded, Action onPrevSceneUnLoaded)
|
||||
{
|
||||
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);
|
||||
|
||||
// Set the current Scene to be able to unload it later
|
||||
Scene currentScene = SceneManager.GetActiveScene();
|
||||
|
||||
// The Application loads the Scene in the background at the same time as the current Scene.
|
||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
|
||||
|
||||
// Wait until the last operation fully loads to return anything
|
||||
yield return new WaitUntil(()=> asyncLoad.isDone);
|
||||
|
||||
onNewSceneLoaded.Invoke();
|
||||
|
||||
// Unload the previous Scene
|
||||
AsyncOperation asyncUnLoad = SceneManager.UnloadSceneAsync(currentScene);
|
||||
yield return new WaitUntil(() => asyncUnLoad.isDone);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 281012d668bdb724b978234aacdc0ef2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -663,70 +663,53 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
public void LoadLive(LiveEntry live, List<LiveCharacterSelect> characters)
|
||||
{
|
||||
characters.ForEach(a =>
|
||||
{
|
||||
if (a.CharaEntry == null || a.CostumeId == "")
|
||||
{
|
||||
//a.CharaEntry = Main.Characters[Random.Range(0, Main.Characters.Count)];
|
||||
//a.CostumeId = "00";
|
||||
}
|
||||
});//fill empty
|
||||
|
||||
GameObject MainLive = new GameObject("Live");
|
||||
GameObject Director = new GameObject("Director");
|
||||
|
||||
Gallop.Live.Director mController = Director.AddComponent<Gallop.Live.Director>();
|
||||
mController.live = live;
|
||||
Instantiate(mController, MainLive.transform);
|
||||
|
||||
Destroy(Director);
|
||||
|
||||
LoadLiveUma(characters);
|
||||
|
||||
Gallop.Live.Director.instance.InitializeTimeline();
|
||||
|
||||
//Gallop.Live.Director.instance.Play();
|
||||
List<GameObject> transferObjs = new List<GameObject>();
|
||||
transferObjs.Add(MainLive);
|
||||
transferObjs.Add(GameObject.Find("ViewerMain"));
|
||||
transferObjs.Add(GameObject.Find("GlobalShaderController"));
|
||||
transferObjs.Add(GameObject.Find("Camera"));
|
||||
transferObjs.Add(GameObject.Find("Directional Light"));
|
||||
transferObjs.Add(GameObject.Find("AnimationCameraRoot"));
|
||||
StartCoroutine(LoadLiveSceneAsync("LiveScene", transferObjs, live.MusicId, characters[0].CharaEntry.Id));
|
||||
List<GameObject> transferObjs = new List<GameObject>() {
|
||||
MainLive,
|
||||
Director,
|
||||
GameObject.Find("ViewerMain"),
|
||||
GameObject.Find("Camera"),
|
||||
GameObject.Find("Directional Light"),
|
||||
GameObject.Find("AnimationCameraRoot")
|
||||
};
|
||||
|
||||
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")));
|
||||
|
||||
characters.ForEach(a =>
|
||||
{
|
||||
if (a.CharaEntry == null || a.CostumeId == "")
|
||||
{
|
||||
//a.CharaEntry = Main.Characters[Random.Range(0, Main.Characters.Count)];
|
||||
//a.CostumeId = "00";
|
||||
}
|
||||
});//fill empty
|
||||
|
||||
Gallop.Live.Director mController = Director.AddComponent<Gallop.Live.Director>();
|
||||
mController.live = live;
|
||||
Instantiate(mController, MainLive.transform);
|
||||
|
||||
Destroy(Director);
|
||||
|
||||
LoadLiveUma(characters);
|
||||
|
||||
Gallop.Live.Director.instance.InitializeTimeline();
|
||||
|
||||
},
|
||||
delegate ()
|
||||
{
|
||||
Gallop.Live.Director.instance.Play(live.MusicId, characters[0].CharaEntry.Id);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
IEnumerator LoadLiveSceneAsync(string sceneName, List<GameObject> go, int songid, int charaid)
|
||||
{
|
||||
// Set the current Scene to be able to unload it later
|
||||
Scene currentScene = SceneManager.GetActiveScene();
|
||||
|
||||
// The Application loads the Scene in the background at the same time as the current Scene.
|
||||
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
|
||||
|
||||
// Wait until the last operation fully loads to return anything
|
||||
while (!asyncLoad.isDone)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Move the GameObject (you attach this in the Inspector) to the newly loaded Scene
|
||||
foreach(var obj in go)
|
||||
{
|
||||
SceneManager.MoveGameObjectToScene(obj, SceneManager.GetSceneByName(sceneName));
|
||||
}
|
||||
|
||||
|
||||
// Unload the previous Scene
|
||||
//Scene scene = SceneManager.GetSceneByName(sceneName);
|
||||
|
||||
//SceneManager.SetActiveScene(scene);
|
||||
|
||||
SceneManager.UnloadSceneAsync(currentScene);
|
||||
|
||||
Gallop.Live.Director.instance.Play(songid, charaid);
|
||||
}
|
||||
|
||||
|
||||
//Use CriWare Library
|
||||
public void LoadLiveSoundCri(int songid, UmaDatabaseEntry SongAwb)
|
||||
|
||||
@@ -589,7 +589,6 @@ public class UmaViewerUI : MonoBehaviour
|
||||
{
|
||||
LiveTime = true;
|
||||
SetEyeTrackingEnable(false);
|
||||
GameObject.Find("LoadingCanvas").GetComponent<Canvas>().enabled = true;
|
||||
CallAfterDelay.Create(0, () => {
|
||||
Builder.LoadLive(currentLive, new List<LiveCharacterSelect>(selectlist));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user