protected override void SingletonAwake()
        {
            base.SingletonAwake();

            _constManagers   = new List <IManagerBase>();
            _dynamicManagers = new List <IManagerBase>();

            // 异常场景委托
            _evtOnExceptionPopupContinue = delegate()
            {
                GameStateManager.Instance.SetNextState(GameStateConf.GetInstance().ExceptionGameState);
            };
            _evtOnExceptionPopupConfirm = delegate()
            {
                --_loadLevelExceptionCount;
            };

            // 挂接不释放脚本
            DontDestroy _dontDestroy = this.GetComponent <DontDestroy>();

            if (null == _dontDestroy)
            {
                this.gameObject.AddComponent <DontDestroy> ();
            }

            DownLoad(DownLoadSuccess, DownLoadFail);
        }
        /// <summary>
        /// 创建UI Root
        /// </summary>
        public void CreateUIRoot()
        {
            GameStateConf _stateConf = GameStateConf.GetInstance();

            if (null == _stateConf)
            {
                this.Error("CreateUIRoot()::The game state conf is invalid!!!");
                return;
            }

            var prefab = DataLoader.Load <GameObject>(_stateConf.Data.uiRootPath);

            if (prefab == null)
            {
                Error("CreateUIRoot(): UIRoot prefab cannot find: {0}", _stateConf.Data.uiRootPath);
                return;
            }

            UIRoot      = UnityEngine.Object.Instantiate(prefab);
            UIRoot.name = prefab.name;
            UICamera    = GameObject.Find(_stateConf.Data.uiCameraName).GetComponent <Camera>();
            foreach (var uiInfo in _uiMainPool)
            {
                uiInfo.Value.SetParent(UIRoot.transform);
                uiInfo.Value.SetCamera(UICamera);
            }
        }
        protected override void SingletonAwake()
        {
            GameStateConf _stateConf = GameStateConf.GetInstance();

            if (null == _stateConf)
            {
                this.Error("SingletonAwake()::The game state conf is invalid!!!");
                return;
            }

            if (UIRoot == null)
            {
                UIRoot = GameObject.Find(_stateConf.Data.uiRootName);
            }

            if (UIRoot == null)
            {
                CreateUIRoot();
            }

            if (UICamera == null)
            {
                UICamera = GameObject.Find(_stateConf.Data.uiCameraName).GetComponent <Camera>();
            }

            _initialized = true;
        }
        /// <summary>
        /// 状态开始
        /// </summary>
        /// <param name="currStateName"></param>
        /// <param name="nextStateName"></param>
        public void OnBeginStateEnter(string currStateName, string nextStateName)
        {
            _loadLevelExceptionCount = 0;
            CreateDynamicManager();

            GameStateConf _stateConf = GameStateConf.GetInstance();

            if (null == _stateConf)
            {
                this.Error("OnBeginStateEnter()::The game state conf is invalid!!!");
                return;
            }

            GameStateInfo _nextStateInfo = Array.Find(
                _stateConf.States.ToArray(), c => c.Name == nextStateName);

            if (null != _nextStateInfo)
            {
                List <string> _managerNames = _nextStateInfo.Managers;
                if ((null != _managerNames) && (0 < _managerNames.Count))
                {
                    try
                    {
                        AddDynamicManager(_managerNames.ToArray());
                    }
                    catch (Exception e)
                    {
                        ShowExceptionPopup(e, _evtOnExceptionPopupConfirm, "AddDynamicManager");
                    }
                }
            }

            for (int i = 0; i < _constManagers.Count; i++)
            {
                IManagerBase manager = _constManagers[i];
                try
                {
                    manager.OnBeginStateEnter(currStateName, nextStateName);
                }
                catch (Exception e)
                {
                    ShowExceptionPopup(e, _evtOnExceptionPopupConfirm, manager.GetType().Name);
                }
            }

            for (int i = 0; i < _dynamicManagers.Count; i++)
            {
                IManagerBase mgr = _dynamicManagers[i];
                try
                {
                    mgr.OnBeginStateEnter(currStateName, nextStateName);
                }
                catch (Exception e)
                {
                    ShowExceptionPopup(e, _evtOnExceptionPopupConfirm, mgr.GetType().Name);
                }
            }
        }
Exemple #5
0
        protected override void SingletonAwake()
        {
            base.SingletonAwake();

            GameStateConf _instance = GameStateConf.GetInstance();

            if (null == _instance)
            {
                this.Error("SingletonAwake()::GameStateConf is not found!!!");
                return;
            }

            this.states = GameStateHelper.GetGameStates(_instance.States);
            if ((null == this.states) || (0 >= this.states.Count))
            {
                this.Error("SingletonAwake()::The game states is empty");
                return;
            }
            _initialized = true;
        }
        /// <summary>
        /// 初始化游戏
        /// </summary>
        void InitGame()
        {
            GameStateConf _conf = GameStateConf.GetInstance();

            if (null == _conf)
            {
                this.Error("the Game config asset not found!!");
                return;
            }

            Screen.sleepTimeout         = _conf.SleepTimeout;
            Application.targetFrameRate = _conf.FPS;

            _constManagerLayer = new GameObject("Constant");
            _constManagerLayer.transform.parent = transform;

            try
            {
                AddConstantManager(_conf.Managers.ToArray());
            }
            catch (Exception e)
            {
                _initException = e;
            }
            finally
            {
                _initialized = true;
                if (_initException == null)
                {
                    GameStateManager.Instance.SetNextState(_conf.FirstGameState);
                }
                else
                {
                    ShowExceptionPopup(_initException, _evtOnExceptionPopupContinue, "ConstantManager");
                }
            }
        }