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);
        }
        private CoreStateManager()
        {
            stateDic = new Dictionary <int, ICoreState>(8);

            ICoreState idleState = new IdleCoreState();

            globalState  = idleState;
            currentState = idleState;
            lastState    = idleState;
        }
        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);
        }
        public void OnUpdate()
        {
            globalState.OnUpdate();
            currentState.OnUpdate();

            if (nextState == null)
            {
                return;
            }

            currentState.OnDisable();

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

            currentState.OnEnable();
        }