/// <summary> /// 切换场景 /// </summary> /// <param name="type">指定的场景类型</param> /// <param name="curtain">指定的帷幕</param> /// <param name="args">初始化参数</param> public void SwitchScene(Type type, ISceneCurtain curtain, params object[] args) { if (m_RunningCoroutine != null) { throw new Exception("The last operation is still in progress !"); } BaseScene nextScene = null; foreach (var scene in m_Scenes) { if (scene.GetType() == type) { nextScene = scene; break; } } if (nextScene == null) { nextScene = (BaseScene)Activator.CreateInstance(type); } m_IsDestroyingScene = true; m_RunningCoroutine = new Coroutine(SwitchScene(CurrentScene, nextScene, curtain == null ? m_DefaultCurtain : curtain, args)); }
IEnumerator SwitchScene(BaseScene origScene, BaseScene nextScene, ISceneCurtain curtain, params object[] args) { if (origScene == nextScene) { m_IsDestroyingScene = false; yield break; } //落幕 if (curtain != null) { yield return(curtain.Falls()); } //关闭现有界面 UIManager uiManager = GameFramework.GetModule <UIManager>(); if (uiManager != null) { uiManager.CloseAll(); } //卸载旧场景 if (origScene != null) { yield return(InvokeExit(origScene)); } //加载新场景 yield return(ResourceManager.Instance.LoadSceneAsync(GetURL(nextScene))); m_IsDestroyingScene = false; yield return(InvokeEnter(nextScene, args)); CurrentScene = nextScene; //揭幕 if (curtain != null) { yield return(curtain.Raise()); } }
protected IEnumerator InvokeExit(BaseScene scene) { scene.isActive = false; yield return(scene.OnExit()); }
protected void InvokeLateUpdate(BaseScene scene, float elapseSeconds, float realElapseSeconds) { scene.OnLateUpdate(elapseSeconds); }
protected IEnumerator InvokeEnter(BaseScene scene, params object[] args) { scene.isActive = true; yield return(scene.OnEnter(args)); }
protected string GetURL(BaseScene scene) { return(scene.url); }