unity工具相关: FSM Scenes( Unity 2018.4.14+ ) 案例笔记

https://nodecanvas.paradoxnotion.com/downloads/

Example Scenes ( Unity 2018.4.14+ )

 

1.Character Point & Click Control

(1).FSM首先继承自Graph的。Finite State Machine有限状态机。

 抽象而言:关键概念和BTree一致(Node和Connection)(节点和连线)

      Connection连线上有ConditionTask的概念

      根据当前currentState节点的状态的outConnection,去Check要不要进行state的切换:

      下面枚举决策什么时候进行outConnect的check:(调用FSMState内的CheckTransitions函数)

       public enum TransitionEvaluationMode
        {
            CheckContinuously,
            CheckAfterStateFinished,
            CheckManually
        }

    如果默认finish,即Connection Condition为null,则本FSMNode不是running则进行切换。  

CheckTransitions函数:

        if ( ( condition != null && condition.Check(graphAgent, graphBlackboard) ) || ( condition == null && status != Status.Running ) ) {
                    FSM.EnterState((FSMState)connection.targetNode, connection.transitionCallMode);
                    connection.status = Status.Success; //editor vis
                    return true;
                }

  

(2).状态机切换后有强制回到上一个状态机的Stacked模式:

    

        public enum TransitionCallMode
        {
            Normal = 0,
            Stacked = 1,
            Clean = 2,
        }

  

  The transition to this state is [Stacked]. That means that no matter what transition we are currently in when this transition takes place, the FSM will return (pop) back that previous state once this state is Finished.

Stacked Call Mode will push the current state to the stack and pop return to it later when any other state without outgoing transitions has been encountered. If you decide to use this feature make sure that you are not cycle stacking states

(3)SuperActionState   针对切状态需要设置一次的行为,这个更实用一些。在Enter和Exit的时候执行单帧的ActionList。当然Enter也可以执行running的多帧,但最好放在updateList里吧。

        [SerializeField]
        private ActionList _onEnterList;
        [SerializeField]
        private ActionList _onUpdateList;
        [SerializeField]
        private ActionList _onExitList;

  The Super Action State provides finer control on when to execute actions. This state is never Finished by it's own if there is any Actions in the OnUpdate list and thus OnFinish transitions will never be called in that case. OnExit Actions are only called for 1 frame when the state exits."

(4)Enter、Exit 和Graph绑定。Graph开始和Stop后执行的ActionList

 

 

 

(5).ConcurrentState : FSMNode, IUpdatable 继承自IUpdatable 的并行节点。

在Graph的tick刷新驱动内,(目前ConcurrentState和AnyState)继承自IUpdatable的节点,是主FSM外围的节点,受到Graph的驱动。

在满足condition的前提下,ConcurrentState并行和主FSM一起执行。AnyState会打断主FSM进入指定的ActionState。

Execute a number of Actions with optional conditional requirement and in parallel to any other state, as soon as the FSM is started. All actions will prematurely be stoped as soon as the FSM stops as well. This is not a state per-se and thus can have neither incomming, nor outgoing transitions."

 

和BTree相比较,FSM更注重状态的切换,实际上FSM的功能BTree也都能实现。而且BTree的装饰器和组合器更灵活。感觉用BTree实现游戏对象逻辑比较直观和可扩展(先不说flowcanvas)。

 

总结:1.FSM主题是 Node和Connection Condition的组合。

      2.外围有ConcurrentState 和 AnyState进行并行执行和中断当前状态

   3.外围有Graph Enter和Exit进行全局初始进入和退出行为

   4.SuperActionState 更适合做状态+初始化行为+退出行为的逻辑处理

   5.IStateCallbackReceiver继承后可以对其他非FSM的类进行交互。

注意:和其他组件通过Action进行交互;FSM外围的处理。

 

posted @ 2022-04-06 19:08  sun_dust_shadow  阅读(69)  评论(0编辑  收藏  举报