Ejemplo 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;
    }
Ejemplo n.º 2
0
    public MonoFSMContorl(MonoBehaviour mono, string contorl_name, Dictionary <Type, T> state_pool, Type default_type) : base(mono, contorl_name, state_pool, default_type)
    {
        Name = contorl_name;

        m_state_pool = state_pool;

        T temp;

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

        CurState = temp;

        var mes = new FSMStateSwitchMessage();

        mes.LastStateType = null;

        mes.CurStateType = CurState.GetType();

        CurState.Enter(mes);
    }