static bool m_IsSwitch = false; // 是否在切换场景中 true 表示切换中 /// <summary> /// 切换场景 /// </summary> public static IEnumerator SwitchToScence(object obj) { SceneSwitchBase sceneSwitcher = obj as SceneSwitchBase; IEnumerator itor = null; if (sceneSwitcher != null) { if (sceneSwitcher != null) { if (sceneSwitcher.CanSwitch) { itor = sceneSwitcher.OnReleaseCachedData(); while (itor.MoveNext()) { yield return(null); } //itor = sceneSwitcher.PrepareSwitch(); //while (itor.MoveNext()) //{ // yield return null; //} sceneSwitcher.IsCreatingScene = true; itor = SwitchingControl.ShowSwitching(true, 100); while (itor.MoveNext()) { yield return(null); } //itor = sceneSwitcher.BeginSwitch(); //while (itor.MoveNext()) //{ // yield return null; //} //itor = unityLogic.DestoryAllUIAsync(); //while (itor.MoveNext()) //{ // yield return null; //} itor = sceneSwitcher.LoadSceneAnimation(); while (itor.MoveNext()) { yield return(null); } if (!string.IsNullOrEmpty(sceneSwitcher.SceneName)) { itor = SceneLoader.LoadStageScene(sceneSwitcher.SceneName); while (itor.MoveNext()) { yield return(null); } } else { Debug.LogError("SceneSwitchBase.SwitchToScence SceneName can not be null"); } IScenceType curScene = sceneSwitcher.AddComponent(); //itor = sceneSwitcher.CreateScenePlayer(); //while (itor.MoveNext()) //{ // yield return null; //} if (curScene != null) { SceneBehaviourBase sceneBehaviourBase = CommonLogicData.CurrentSceneBehaviour; if (sceneBehaviourBase != null) { sceneBehaviourBase.CurScene = curScene; } itor = curScene.IEPlayerEnterScene(true); while (itor.MoveNext()) { yield return(null); } } itor = sceneSwitcher.PrepareUIAndData(); while (itor.MoveNext()) { yield return(null); } sceneSwitcher.IsCreatingScene = false; itor = sceneSwitcher.FinishSwitch(); while (itor.MoveNext()) { yield return(null); } SwitchingControl.HideSwitching(); //unityLogic.HideSwitching(); } else { Debug.LogError("SceneSwitchMgr.SwitchToScence unityLogic can not be null"); } } else { Debug.LogError("SceneSwitchMgr.SwitchToScence sceneSwitcher can not be null"); } } }
/// <summary> /// 尝试切换场景 /// </summary> /// <param name="sceneSwitcher">切换实例</param> public static void TrySwitch(SceneSwitchBase sceneSwitcher) { TrySwitch(SwitchToScence, sceneSwitcher); }