Esempio n. 1
0
        public void Register(string stageName, StageControllerBase stageController, bool DI = true, bool initialStage = false)
        {
            lock (this)
            {
                //是否已经添加
                if (m_DictStages.TryGetValue(stageName, out var _stage))
                {
                    if (_stage != stageController)
                    {
                        throw new DuplicateStageNameException(stageName);
                    }
                }
                else
                {
                    m_DictStages.Add(stageName, stageController);
                    m_Stages.Add(stageController);
                }

                //如果当前没有任何Stage,则指定第一个注册的Stage是初始Stage
                if (m_Stages.Count <= 1 && m_InitialStage == null)
                {
                    m_InitialStage = stageController;
                }
                else
                {
                    if (initialStage) //手动指定了初始场景
                    {
                        m_InitialStage = stageController;
                    }
                }

                //依赖注入
                if (DI)
                {
                    lock (this)
                    {
                        if (m_Started)
                        {
                            Core.Services.Inject(stageController);
                        }
                        else
                        {
                            m_DI.Add(stageController);
                        }
                    }
                }

                if (m_Started)
                {
                    stageController.OnInit(stageName);
                    if (m_InitialStage == stageController)
                    {
                        this.switchStage(m_InitialStage);
                    }
                    stageController.GameStages = this;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 实际切换Stage的内部方法
        /// </summary>
        /// <param name="newStage"></param>
        private void switchStage(StageControllerBase newStage)
        {
            if (m_CurrentStage != null)
            {
                if (m_CurrentStage == newStage)
                {
                    return;
                }
                else
                {
                    var last_stage = m_CurrentStage;

                    #region Exit Event 广播退出事件
                    XEvent.Call(GameStageEventConst.OnStageExit, new string[] { last_stage.StageName, newStage.StageName }, GameStageEventConst.GameStageEventGroupName);
                    XEvent.Call($"{GameStageEventConst.OnStageExit}{last_stage.StageName}", newStage.StageName, GameStageEventConst.GameStageEventGroupName);
                    #endregion

                    m_CurrentStage.OnExit(newStage.StageName);
                    m_CurrentStage = newStage;
                    Debug.Log($"[{GameStageConst.ServiceName}]{(XCore.GetMainInstance().IsCmnHans() ? "切换Stage:" : "Switch Stage:")}" +
                              $"<color=#{TinaX.Internal.XEditorColorDefine.Color_Normal_Pure_16}>{last_stage.StageName}</color> --> <color=#{TinaX.Internal.XEditorColorDefine.Color_Emphasize_16}>{newStage.StageName}</color>");

                    newStage.OnEnter(last_stage.StageName);

                    #region Enter Event 广播进入事件
                    XEvent.Call(GameStageEventConst.OnStageEnter, new string[] { newStage.StageName, last_stage.StageName }, GameStageEventConst.GameStageEventGroupName);
                    XEvent.Call($"{GameStageEventConst.OnStageExit}{newStage.StageName}", last_stage.StageName, GameStageEventConst.GameStageEventGroupName);
                    #endregion

                    //广播切换事件
                    XEvent.Call(GameStageEventConst.OnStageChanged, new string[] { last_stage.StageName, newStage.StageName }, GameStageEventConst.GameStageEventGroupName);
                }
            }
            else
            {
                m_CurrentStage = newStage;

                bool isHans = XCore.GetMainInstance().IsCmnHans();
                Debug.Log($"[{GameStageConst.ServiceName}]{(isHans ? "切换Stage:" : "Switch Stage:")}" +
                          $"<color=#{TinaX.Internal.XEditorColorDefine.Color_Safe_16}>*{(isHans?"空 Stage":"No Stage")}*</color> --> <color=#{TinaX.Internal.XEditorColorDefine.Color_Emphasize_16}>{newStage.StageName}</color>");


                newStage.OnEnter(string.Empty);

                //广播进入事件
                XEvent.Call(GameStageEventConst.OnStageEnter, new string[] { newStage.StageName, string.Empty }, GameStageEventConst.GameStageEventGroupName);
                XEvent.Call($"{GameStageEventConst.OnStageExit}{newStage.StageName}", string.Empty, GameStageEventConst.GameStageEventGroupName);

                //广播切换事件
                XEvent.Call(GameStageEventConst.OnStageChanged, new string[] { string.Empty, newStage.StageName }, GameStageEventConst.GameStageEventGroupName);
            }
        }
Esempio n. 3
0
 public void Register(string stageName, StageControllerBase stageControllerBase)
 {
     this.Register(stageName, stageControllerBase, true, false);
 }
Esempio n. 4
0
 public bool TryGetStage(string StageName, out StageControllerBase stage)
 {
     return(this.m_DictStages.TryGetValue(StageName, out stage));
 }