コード例 #1
0
        public ActionState AddActionState(string name, Action actionEnter, Action actionUpdate, Action actionExit)
        {
            ActionState actionState = new ActionState(name, actionEnter, actionUpdate, actionExit);
            _listState.Add(actionState);

            return actionState;
        }
コード例 #2
0
        public Transition AddTransition(ActionState actionStateStart, ActionState actionStateEnd, Func<bool> condition)
        {
            Transition transition = new Transition(actionStateStart, actionStateEnd, condition);
            _listTransition.Add(transition);

            return transition;
        }
コード例 #3
0
 public Transition AddTransition(ActionState actionStateEnd, Func<bool> condition)
 {
     return AddTransition(null, actionStateEnd, condition);
 }
コード例 #4
0
 public Transition(ActionState actionStateStart, ActionState actionStateEnd, Func<bool> condition)
 {
     ActionStateStart = actionStateStart;
     ActionStateEnd = actionStateEnd;
     Condition = condition;
 }
コード例 #5
0
        public void Update()
        {
            foreach (Transition transition in _listTransition)
            {
                if ((transition.ActionStateStart == CurrentState || transition.ActionStateStart == null) && transition.Condition())
                {
                    if (IsDebug)
                    {
                        if (transition.ActionStateStart == null)
                            Debug.Log("FSM " + this.MachineName + " : / to " + transition.ActionStateEnd.Name);
                        else
                            Debug.Log("FSM " + this.MachineName + " : " + transition.ActionStateStart.Name + " to " + transition.ActionStateEnd.Name);
                    }

                    if (CurrentState.ActionExit != null)
                        CurrentState.ActionExit();

                    CurrentState = transition.ActionStateEnd;

                    if(CurrentState.ActionEnter != null)
                        CurrentState.ActionEnter();

                    break;
                }
            }

            if(CurrentState.ActionUpdate != null)
                CurrentState.ActionUpdate();
        }