예제 #1
0
    private void Awake()
    {
        //音频内存管理器
        //LTAudio.ClearAudio.v_Instance.F_Start();
        //相机自适应
        //CameraUtils.F_Adapt();

        if (null == _gameStateTypes)
        {
            _gameStateTypes = new Dictionary <eGameState, System.Type>();
            Assembly assembly = Assembly.GetAssembly(typeof(GameState));
            foreach (System.Type t in assembly.GetTypes())
            {
                if (t.IsSubclassOf(typeof(GameState)))
                {
                    GameStateAttribute attr = (GameStateAttribute)t.GetCustomAttributes(typeof(GameStateAttribute), false) [0];
                    _gameStateTypes.Add(attr.State, t);
                }
            }
        }

#if !DEBUG || NO_DEBUG_SCREEN
        SetGameState <GameStateDownload>();
#else
        SetGameState <GameStateDebugStartScreen> ();
#endif
    }
예제 #2
0
    public void SetGameState <T>(System.Action <T> transition = null) where T : GameState
    {
        T newStateObj               = typeof(T).GetConstructor(System.Type.EmptyTypes).Invoke(null) as T;
        GameStateAttribute attr     = typeof(T).GetCustomAttributes(typeof(GameStateAttribute), false) [0] as GameStateAttribute;
        eGameState         newState = attr.State;

        StopAllCoroutines();

        if (transition != null)
        {
            transition(newStateObj);
        }

        GameState oldStateObj = _state;

        if (null != oldStateObj)
        {
            oldStateObj.End(newStateObj);
        }
        eGameState previousState = _eState;

        _eState = newState;
        _state  = newStateObj;

        PerformanceManager.Instance.OnGameStateTransition(newState);
        if (ObjectManager != null)
        {
            ObjectManager.End();
        }
        ObjectManager = new CodeObjectManager();
        ObjectManager.Start();

        mNewStateObjs.Add(newStateObj);
        moldStateObjs.Add(oldStateObj);
        EventManager.instance.Raise(new GameStateChangedEvent(previousState, newState));
    }