Пример #1
0
    void _ChangeState(System.Type stateType, params object[] userdata)
    {
        if (typeof(FSMState).IsAssignableFrom(stateType))
        {
            FSMState stateTo = GetState(stateType);

            if (stateTo)
            {
                if (stateTo.CallInit(userdata))
                {
                    FSMState stateFrom = (m_stackedStates.Count > 0) ? m_stackedStates.Peek() : null;
                    if (stateFrom != null)
                    {
                        stateFrom.CallExit(stateTo);
                        m_stackedStates.Pop();
                    }

                    m_stackedStates.Push(stateTo);
                    stateTo.CallEnter(stateFrom);

                    if (stateFrom != null)
                    {
                        stateFrom.CallRelease();
                    }
                }
                else
                {
                    Debug.LogError("FSM : state " + stateType.GetType().Name + " failed to initialize.");
                    stateTo.CallRelease();
                }
            }
        }
    }