示例#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;
    }
示例#2
0
    protected override void DoAction(AgentAction action)
    {
        if (action == null)
        {
            return;
        }

        if (CurState.HandleSameAction(action) == true)
        {
            return;
        }

        FsmState preState = CurState;

        if (action is AgentActionGoTo)
        {
            CurState = GetState((int)FsmStateType.GOTO_POS);
        }
        else if (action is AgentActionCombatMove)
        {
            CurState = GetState((int)FsmStateType.COMBAT_MOVE);
        }
        else if (action is AgentActionAttackMelee)
        {
            CurState = GetState((int)FsmStateType.ATTACK_MELEE);
        }
        else if (action is AgentActionInjury)
        {
            CurState = GetState((int)FsmStateType.INJURY);
        }
        else if (action is AgentActionDeath)
        {
            CurState = GetState((int)FsmStateType.DEATH);
        }
        else if (action is AgentActionKnockdown)
        {
            CurState = GetState((int)FsmStateType.KNOCKDOWN);
        }
        else if (action is AgentActionBlock)
        {
            CurState = GetState((int)FsmStateType.BLOCK);
        }

        preState.Exit();
        CurState.Enter(action);
    }
示例#3
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);
    }
示例#4
0
 void Start()
 {
     CurState.Enter(null);
 }
示例#5
0
 protected override void InitCurState()
 {
     CurState = mStateMachineDic[ActorStateType.Idle];
     CurState.Enter(this);
 }
示例#6
0
    protected override void DoAction(AgentAction action)
    {
        FsmState preState = CurState;

        // ------------------------------ 无要执行的action ------------------------------
        if (action == null)
        {
            //if (_blackBoard.curAction != null && _blackBoard.curAction.Type == AgentAction.ActionType.MOVE)
            if ((_blackBoard.curAction as AgentActionMove) != null)
            {
                CurState = GetState((int)FsmStateType.IDLE); // 转入idle状态
                preState.Exit();
                CurState.Enter(action);
            }
            return;
        }

        // ------------------------------ 有要执行的action ------------------------------

        // 执行同样行为

        /*if (_blackBoard.curAction != null && _blackBoard.curAction.Type == action.Type)
         * {
         *  CurState.HandleSameAction(action);
         *  return;
         * }*/
        if (CurState.HandleSameAction(action))
        {
            return;
        }


        //if (action.Type == AgentAction.ActionType.DEATH)
        if (action as AgentActionDeath != null)
        {
            CurState = GetState((int)FsmStateType.DEATH);
        }
        //else if (action.Type == AgentAction.ActionType.INJURY && _blackBoard.curAction.Type != AgentAction.ActionType.DEATH)
        else if (action as AgentActionInjury != null && _blackBoard.curAction as AgentActionDeath == null)
        {
            CurState = GetState((int)FsmStateType.INJURY);
        }
        else if (_blackBoard.curAction == null) // 当前是idle状态
        {
            switch (action.Type)
            {
            case AgentActionType.MOVE:
                CurState = GetState((int)FsmStateType.MOVE);
                break;

            case AgentActionType.ROLL:
                CurState = GetState((int)FsmStateType.ROLL);
                break;

            case AgentActionType.ATTACK_MELEE:
                CurState = GetState((int)FsmStateType.ATTACK_MELEE);
                break;

            default:
                return;
            }
        }
        //else if (_blackBoard.curAction.Type == AgentAction.ActionType.MOVE)
        else if (_blackBoard.curAction as AgentActionMove != null) // 当前是move状态
        {
            switch (action.Type)
            {
            case AgentActionType.ROLL:
                CurState = GetState((int)FsmStateType.ROLL);
                break;

            case AgentActionType.ATTACK_MELEE:
                CurState = GetState((int)FsmStateType.ATTACK_MELEE);
                break;

            default:
                return;
            }
        }
        else if (_blackBoard.curAction.Type == AgentActionType.ATTACK_MELEE) // 当前是attack状态
        {
            switch (action.Type)
            {
            case AgentActionType.ROLL:
                CurState = GetState((int)FsmStateType.ROLL);
                break;

            default:
                return;
            }
        }
        else
        {
            return;
        }

        preState.Exit();
        CurState.Enter(action);

        /*FsmState preState = CurState;
         * if (action == null && _blackBoard.curAction != null && _blackBoard.curAction.Type == AgentAction.ActionType.MOVE)
         * {
         *  CurState = GetState((int)FsmStateType.IDLE);
         *  return;
         * }
         * else if (action == null)
         * {
         *  return;
         * }
         * else if (_blackBoard.curAction != null && _blackBoard.curAction.Type == action.Type)
         * {
         *  CurState.HandleSameAction(action);
         *  return;
         * }
         * else if (action.Type == AgentAction.ActionType.DEATH)
         * {
         *  CurState = GetState((int)FsmStateType.DEATH);
         * }
         * else if (action.Type == AgentAction.ActionType.INJURY && _blackBoard.curAction.Type != AgentAction.ActionType.DEATH)
         * {
         *  CurState = GetState((int)FsmStateType.INJURY);
         * }
         * else if (CurState == DefState) // 当前是idle状态
         * {
         *  switch (action.Type)
         *  {
         *      case AgentAction.ActionType.MOVE:
         *          CurState = GetState((int)FsmStateType.MOVE);
         *          break;
         *      case AgentAction.ActionType.ROLL:
         *          CurState = GetState((int)FsmStateType.ROLL);
         *          break;
         *      case AgentAction.ActionType.ATTACK_MELEE:
         *          CurState = GetState((int)FsmStateType.ATTACK_MELEE);
         *          break;
         *      default:
         *          return;
         *  }
         * }
         * else
         * {
         *  return;
         * }
         *
         * preState.Exit();
         * CurState.Enter(action);*/
    }