Exemplo n.º 1
0
    public override void SwitchTo(System.Type state)
    {
        if (CurState.GetType() == state)
        {
            return;
        }

        T to_state;

        if (!m_state_pool.TryGetValue(state, out to_state))
        {
            throw new System.Exception("'" + Name + "' not fount '" + state.Name + "' state");
        }

        var mes = new FSMStateSwitchMessage();

        mes.LastStateType = CurState.GetType();
        mes.CurStateType  = to_state.GetType();

        CurState.Exit(mes);

        CurState.Enter(mes);

        CurState = to_state;
    }
    /// <summary>
    /// Transitions to a new state.
    /// </summary>
    /// <param name="newState">The new FSMState to transition to.</param>
    public void Transition(FSMState newState)
    {
        //Exit current state
        if (CurState != null)
        {
            CurState.Exit();
        }

        CurState = newState;
        CurState.StateMachine = this;
        CurStateName          = CurState.GetType().Name;

        //Debug.Log("Transitioned to: " + CurStateName);

        //Enter the new state
        if (CurState != null)
        {
            CurState.Enter();
        }
        else
        {
            Debug.LogWarning("Current state passed in is null!");
        }
    }