Пример #1
0
        ///
        /// 设备的状态发生改变的时候
        ///
        public void handleStateChg(DeviceState NowState)
        {
            ConsoleEx.DebugLog("Device Status Changed. " + mPreState.ToString() + " -> " + NowState.ToString(), ConsoleEx.RED);

            mPreState = mNowState;
            mNowState = NowState;

            StateParam <DeviceState> param = new StateParam <DeviceState>();

            param.NowGameState  = mNowState;
            param.prevGameState = mPreState;

            //优先处理核心处理层
            foreach (IDeviceState listener in Owner)
            {
                switch (NowState)
                {
                case DeviceState.GameLaunched:
                    listener.OnGameLaunched(param);
                    break;

                case DeviceState.GamePaused:
                    listener.OnPaused(param);
                    break;

                case DeviceState.GameResume:
                    listener.OnResume(param);
                    break;

                case DeviceState.GameQuit:
                    listener.OnQuit(param);
                    break;
                }
            }

            EntityManager entityMgr = Core.EntityMgr;

            //再处理控制层
            foreach (LogicalType controller in binder.IControllerDevice)
            {
                ControllerEx ctrl = entityMgr.getEntityByLogicalType(controller);
                if (ctrl != null && ctrl is IDeviceState)
                {
                    IDeviceState idev = ctrl as IDeviceState;
                    switch (NowState)
                    {
                    case DeviceState.GameLaunched:
                        idev.OnGameLaunched(param);
                        break;

                    case DeviceState.GamePaused:
                        idev.OnPaused(param);
                        break;

                    case DeviceState.GameResume:
                        idev.OnResume(param);
                        break;

                    case DeviceState.GameQuit:
                        idev.OnQuit(param);
                        break;
                    }
                }
            }
        }
Пример #2
0
        ///
        /// 游戏逻辑的状态发生改变的时候
        ///
        public void handleStateChg(StateParam <GameState> param, GameState NowState)
        {
            ConsoleEx.DebugLog("GamePlay Status Changed. " + mPreState.ToString() + " -> " + NowState.ToString(), ConsoleEx.RED);

            mPreState           = mNowState;
            mNowState           = NowState;
            param.NowGameState  = mNowState;
            param.prevGameState = mPreState;

            //优先处理核心处理层
            foreach (IGameState listener in Owner)
            {
                switch (NowState)
                {
                case GameState.DayChanged:
                    break;

                case GameState.Logined:
                    listener.OnLogin(param);
                    break;

                case GameState.Logout:

                    break;

                case GameState.LevelChanged:
                    listener.OnLevelChanged(param);

                    LevelChanged lvl = param.obj as LevelChanged;
                    if (lvl != null)
                    {
                        lastScene = lvl.curLevel;
                    }
                    break;
                }
            }


            EntityManager entityMgr = Core.EntityMgr;

            //再处理控制层
            foreach (LogicalType controller in binder.IControllerGamePlay)
            {
                ControllerEx ctrl = entityMgr.getEntityByLogicalType(controller);
                if (ctrl != null && ctrl is IGameState)
                {
                    IGameState igame = ctrl as IGameState;
                    switch (NowState)
                    {
                    case GameState.DayChanged:
                        break;

                    case GameState.Logined:
                        igame.OnLogin(param);
                        break;

                    case GameState.Logout:
                        break;

                    case GameState.LevelChanged:
                        igame.OnLevelChanged(param);
                        break;
                    }
                }
            }
        }