/// <summary> /// 読込開始 /// </summary> /// <param name="id"></param> /// <param name="addtive"></param> /// <param name="async"></param> public SceneLoader(SceneDefine.SCENE_ID id, bool addtive, bool async) { SceneID = id; Name = SceneDefine.SceneNames[(int)id]; this.addtive = addtive; this.async = async; if (async) { var param = new UnityEngine.SceneManagement.LoadSceneParameters(); if (addtive) { param.loadSceneMode = UnityEngine.SceneManagement.LoadSceneMode.Additive; } else { param.loadSceneMode = UnityEngine.SceneManagement.LoadSceneMode.Single; } asyncOperation = UnitySceneManager.LoadSceneAsync(Name, param); } else { if (addtive) { UnitySceneManager.LoadScene(Name, UnityEngine.SceneManagement.LoadSceneMode.Additive); } else { UnitySceneManager.LoadScene(Name, UnityEngine.SceneManagement.LoadSceneMode.Single); } } }
/// <summary> /// セットアップ(読込完了) /// </summary> /// <param name="id"></param> public void Setup(SceneDefine.SCENE_ID id, UnityScene unityScene) { SceneID = id; UnityScene = unityScene; Loaded(); }
private void Update() { for (int i = 0; i < sceneLoaderList.Count; i++) { SceneLoader loader = sceneLoaderList[i]; bool loaded = loader.Update(); if (loaded) { SceneDefine.SCENE_ID id = loader.SceneID; UnityScene unityScene = UnitySceneManager.GetSceneByName(loader.Name); SceneBase scene = GameObject.Find(unityScene.name).GetComponent <SceneBase>(); sceneList.Add(scene); sceneLoaderList.RemoveAt(i); UnitySceneManager.SetActiveScene(unityScene); scene.Setup(id, unityScene); break; } } for (int i = 0; i < sceneList.Count; i++) { // アンロード処理 if (sceneList[i] == null) { sceneList.RemoveAt(i); break; } } }
/// <summary> /// シーンをアクティブする。 /// </summary> /// <param name="id"></param> public static void SetActiveScene(SceneDefine.SCENE_ID id) { List <SceneBase> sceneList = Instance.sceneList; for (int i = 0; i < sceneList.Count; i++) { if (sceneList[i].SceneID == id) { UnitySceneManager.SetActiveScene(sceneList[i].UnityScene); break; } } }
/// <summary> /// シーンを破棄する /// </summary> public static void UnloadScene(SceneDefine.SCENE_ID id) { List <SceneBase> sceneList = Instance.sceneList; for (int i = 0; i < sceneList.Count; i++) { if (sceneList[i].SceneID == id) { sceneList[i].StartUnload(); UnitySceneManager.UnloadSceneAsync(sceneList[i].UnityScene.name); break; } } }
/// <summary> /// 読込終了したか? /// </summary> /// <returns></returns> public static bool IsLoaded(SceneDefine.SCENE_ID id) { List <SceneLoader> loaderList = Instance.sceneLoaderList; for (int i = 0; i < loaderList.Count; i++) { if (loaderList[i].SceneID == id) { return(true); } } return(false); }
/// <summary> /// シーンをロードする。 /// </summary> public static void LoadScene(SceneDefine.SCENE_ID id, bool async = true, bool addtive = false) { Instance.sceneLoaderList.Add(new SceneLoader(id, addtive, async)); }