Ejemplo n.º 1
0
        public ChangeResult ChangeTo(string stateName)
        {
            BaseState enterState = null;

            if (!m_StateMap.TryGetValue(stateName, out enterState))
            {
                return(ChangeResult.NotExist);
            }
            if (m_curState != null && m_curState.GetName() == stateName)
            {
                CurState.OnReEnter();
                return(ChangeResult.SameState);
            }
            else  //enter new state
            {
                if (DebugLog)
                {
                    LogManager.LogError("current state is " + CurState.GetName() + "chang to " + stateName);
                }
                if (CurState)
                {
                    CurState.OnLeaveState();
                }
                m_curState = enterState;
                CurState.OnEnterState();
                if (m_stateEvent != null)
                {
                    m_stateEvent(stateName);
                }
                return(ChangeResult.Success);
            }
        }