예제 #1
0
        /// <summary> 构造函数

        public FsmStateNode(MainFsm finiteStateMachine, FsmBase fsmBase, string name = null) : base()
        {
            _mainFsm   = finiteStateMachine;
            this._fsm  = fsmBase;
            this._name = name ?? this.GetType().ToString();
            fsmBase.AddNode(this);
        }
예제 #2
0
        // ----------------------
        /// <summary> 构造函数 </summary>
        public SubFsm(MainFsm mainFsm, string name, FsmBase fsmBelongTo = null)
        {
            this._mainFsm     = mainFsm;
            this._fsmBelongTo = fsmBelongTo ?? mainFsm;
            transitionList    = new List <StateTransition>();

            inState      = new IntoState(this._mainFsm, this);
            outState     = new OutState(this._mainFsm, this);
            _currentNode = inState;

            this._name = name ?? this.GetType().ToString();
            mainFsm.AddNode(this);
        }
예제 #3
0
        /// <summary> 构造函数 </summary>
        public StateTransition(IFsmNode from, IFsmNode to, MainFsm mainFsm, FsmBase fsmBelongTo = null)
        {
            if (from == to)
            {
                //Todo Error
                return;
            }
            this._mainFsm    = mainFsm;
            this.fsmBelongTo = fsmBelongTo ?? mainFsm;
            this.from        = from;
            this.to          = to;
            _conditionSet    = new HashSet <Func <bool> >();

            this.from.AddTransition(this);
        }
예제 #4
0
        protected override void InitFsm()
        {
            _fsm = new MainFsm(typeof(EBoolCondition), typeof(EFloatCondition));
            //创建默认
            var idle = new IdleState(_fsm, _fsm, "Idle");

            //设置Idle为默认
            _fsm.TransitionFactoty(_fsm.intoState, idle);
            //or By HelperMethod
            var idle2 = _fsm.FsmStateFactory("Idle2");
            //创建跑
            var run = new FsmState(_fsm, _fsm, "Run", () => Debug("I am going to run"), () => Debug("I dont run anymore"), () => Debug("I am runing"));

            //设置条件,如果速度大于0.1 且 在地面上,就run
            _fsm.TransitionFactoty(idle, run)
            .AddCondition(() => GetFloat(EFloatCondition.SpeedMagnitute) > 0.1f && GetBool(EBoolCondition.IsGrounded));
            //反之,速度<=0.1
            _fsm.TransitionFactoty(run, idle)
            .AddCondition(() => GetFloat(EFloatCondition.SpeedMagnitute) <= 0.1f && GetBool(EBoolCondition.IsGrounded));
            //创建飞,trigger为飞
            var flySubFsm = new SubFsm(_fsm, "FlyFsm");
            var tran      = new StateTransition(_fsm.anyState, flySubFsm, _fsm);

            //Anystate,Triggger为Fly,就进入Fly子状态机
            tran.AddCondition(() => GetTrigger(ETriggerCondition.Fly));
            //到地面上,就回到idle
            _fsm.TransitionFactoty(flySubFsm, idle)
            .AddCondition(() => GetBool(EBoolCondition.IsGrounded));
            //坠落,速度大于0.1
            var drop = new FsmState(_fsm, flySubFsm, "Drop", () => Debug("I am going to drop !"));

            flySubFsm.TransitionFactoty(flySubFsm.inState, drop)
            .AddCondition(() => GetFloat(EFloatCondition.SpeedMagnitute) > 0.1f);
            //回到地上,变为idle
            flySubFsm.TransitionFactoty(drop, flySubFsm.outState)
            .AddCondition(() => GetBool(EBoolCondition.IsGrounded));
            //状态机启动
            _fsm.StartOrRestart();
        }
예제 #5
0
 public MoveState(MainFsm mainFsm, FsmBase fsmBase, string name = null) : base(mainFsm, fsmBase, name)
 {
 }
예제 #6
0
 public IntoState(MainFsm mainFsm, FsmBase fsmBase) : base(mainFsm, fsmBase, "enter")
 {
 }
예제 #7
0
 public OutState(MainFsm mainFsm, FsmBase fsmBase) : base(mainFsm, fsmBase, "exit")
 {
 }
예제 #8
0
 /// <summary> 构造函数
 public FsmState(MainFsm finiteStateMachine, FsmBase fsmBase, string name, Action onStateEnter = null, Action onStateExit = null, Action onStateUpdate = null) : base(finiteStateMachine, fsmBase, name)
 {
     this.onStateEnter  = onStateEnter;
     this.onStateExit   = onStateExit;
     this.onStateUpdate = onStateUpdate;
 }