Ejemplo n.º 1
0
        private void AddState(Type iType)
        {
            ICoreState state = Activator.CreateInstance(iType) as ICoreState;

            if (state == null)
            {
                return;
            }

            CoreStateAttribute attr = Attribute.GetCustomAttribute(iType, typeof(CoreStateAttribute)) as CoreStateAttribute;

            if (attr == null)
            {
                Debug.LogErrorFormat("[CoreStatemanager] ICoreState: {0} has no CoreStateAttribute.", state.GetType().FullName);
                return;
            }

            if (stateDic.ContainsKey(attr.id))
            {
                Debug.LogErrorFormat("[CoreStatemanager] ICoreState: {0} is duplicated.", attr.id);
                return;
            }

            stateDic.Add(attr.id, state);
        }
Ejemplo n.º 2
0
        private CoreStateManager()
        {
            stateDic = new Dictionary <int, ICoreState>(8);

            ICoreState idleState = new IdleCoreState();

            globalState  = idleState;
            currentState = idleState;
            lastState    = idleState;
        }
Ejemplo n.º 3
0
        public void ChangeGlobalState(int iStateID)
        {
            if (stateDic.ContainsKey(iStateID))
            {
                globalState.OnDisable();
                globalState = stateDic[iStateID];
                globalState.OnEnable();
                return;
            }

            Debug.LogErrorFormat("[CoreStatemanager] ICoreState isn't exsist.", iStateID);
        }
Ejemplo n.º 4
0
        public void OnUpdate()
        {
            globalState.OnUpdate();
            currentState.OnUpdate();

            if (nextState == null)
            {
                return;
            }

            currentState.OnDisable();

            lastState    = currentState;
            currentState = nextState;
            nextState    = null;

            currentState.OnEnable();
        }