/// <summary> /// 设置当前场景 /// </summary> /// <param name="State"></param> /// <param name="LoadSceneName"></param> public void SetState(ISceneState State, bool IsNow = true, bool isAsync = false) { Debug.Log("SetState:" + State.ToString()); isSceneBegin = false; // 通知前一個State結束 if (CurState != null) { CurState.StateEnd(); } // 載入場景 if (IsNow) { if (isAsync) { UILoading.nextScene = State.StateName; LoadScene("Loading"); } else { LoadScene(State.StateName); } } //设置当前场景 CurState = State; }
//private Dictionary<string, ISceneState> stateDict; // <StateName, SceneState>对应字典 ///// <summary> ///// 设置当前场景(加载场景) ///// </summary> ///// <typeparam name="T">需要加载的场景类</typeparam> ///// <param name="isNow"></param> ///// <param name="isAsync"></param> //public void SetState<T>(bool isNow = true, bool isAsync = false) where T: ISceneState, new() //{ // // 用泛型方法<T>创建新场景状态state,并将state添加到dict,通过state.SceneName加载对应场景 // ISceneState state = new T(); // if (stateDict.ContainsKey(state.SceneName)) // { // Debug.Log(state.SceneName + "is contained."); // state = stateDict[state.SceneName]; // 替换掉原来的state // } // else // { // state.Awake(this); // stateDict.Add(state.SceneName, state); // } //} #endregion /// <summary> /// 设置当前场景(加载场景) /// </summary> public void SetState(SceneState sceneState, bool isNow = true, bool isAsync = false) { ISceneState state; switch (sceneState) { case SceneState.StartScene: state = new StartScene(this); break; case SceneState.LoginScene: state = new ProjectScript.LoginScene(this); break; default: return; } Debug.Log("SetState:" + state.ToString()); isSceneBegin = false; // 通知前一个State结束 if (CurrentState != null) { CurrentState.StateEnd(); } // 载入场景 if (isNow) { if (isAsync) { UILoading.nextScene = state.SceneName; LoadScene("Loading"); } else { LoadScene(state.SceneName); } } // 设置当前场景 CurrentState = state; }
/// <summary> /// 设置当前场景 /// </summary> public void SetState(SceneState sceneState, bool isNow = true, bool isAsync = false) { ISceneState State; switch (sceneState) { case SceneState.StartState: State = new StartState(this); break; default: return; } Debug.Log("SetState:" + State.ToString()); isSceneBegin = false; // 通知前一個State結束 if (CurState != null) { CurState.StateEnd(); } // 載入場景 if (isNow) { if (isAsync) { UILoading.nextScene = State.StateName; LoadScene("Loading"); } else { LoadScene(State.StateName); } } //设置当前场景 CurState = State; }
/// <summary> /// 设置当前场景 /// </summary> public void SetState(SceneState sceneState, bool isNow = true, bool isAsync = false) { ISceneState State; switch (sceneState) { case SceneState.StartState: State = new StartState(this); break; case SceneState.MainScene: State = new MainScene(this); break; case SceneState.TrainScene: State = new TrainScene(this); break; case SceneState.VillageScene: State = new VillageScene(this); break; case SceneState.TutorialScene: State = new TutorialScene(this); break; case SceneState.BattleEyeball: State = new BattleEyeball(this); break; case SceneState.BattleMonster: State = new BattleMonster(this); break; case SceneState.BattleStrongKnight: State = new BattleStrongKnight(this); break; case SceneState.BattleFantasy: State = new BattleFantasy(this); break; case SceneState.BattleForestNight: State = new BattleForestNight(this); break; case SceneState.BattleForestDay: State = new BattleForestDay(this); break; default: return; } Debug.Log("切换场景:" + State.ToString()); isSceneBegin = false; // 通知前一個State結束 if (CurState != null) { CurState.StateEnd(); } // 载入场景 if (isNow) { if (isAsync) { UILoading.nextScene = State.StateName; LoadScene("Loading"); } else { LoadScene(State.StateName); } } //设置当前场景 CurState = State; }