Exemplo n.º 1
0
    public bool nextState()
    {
        NextStateInfo nextStateInfo = null;

        for (int i = m_stateInfoList.Count - 1; i >= 0; --i)
        {
            if (m_stateInfoList[i].stateType != IState.StateType.None)
            {
                nextStateInfo = m_stateInfoList[i];
                if (nextStateInfo.isUse == false)
                {
                    nextStateInfo.isUse = true;
                    break;
                }
            }
        }

        return(SetCurrState(nextStateInfo.stateType, nextStateInfo));
    }
Exemplo n.º 2
0
    public bool SetCurrState(IState.StateType stateType, NextStateInfo nextStateInfo = null)
    {
        if (null != m_curState && m_curState.GetStateType() == stateType)
        {
            return(false);
        }

        IState newState = null;

        m_dictState.TryGetValue((int)stateType, out newState);
        if (null == newState)
        {
            return(false);
        }

        IState oldState = m_curState;

        if (null != m_curState)
        {
            m_curState.OnLeave(0);
        }

        m_curState = newState;

        if (null != m_curState)
        {
            if (nextStateInfo != null)
            {
                m_curState.ExecuteState(this, oldState, nextStateInfo.mParam1, nextStateInfo.mParam2);
            }
            //else
            //{
            //    m_curState.ExecuteState(this, oldState, null, null);
            //}
        }

        return(true);
    }