public ActionState AddActionState(string name, Action actionEnter, Action actionUpdate, Action actionExit) { ActionState actionState = new ActionState(name, actionEnter, actionUpdate, actionExit); _listState.Add(actionState); return actionState; }
public Transition AddTransition(ActionState actionStateStart, ActionState actionStateEnd, Func<bool> condition) { Transition transition = new Transition(actionStateStart, actionStateEnd, condition); _listTransition.Add(transition); return transition; }
public Transition AddTransition(ActionState actionStateEnd, Func<bool> condition) { return AddTransition(null, actionStateEnd, condition); }
public Transition(ActionState actionStateStart, ActionState actionStateEnd, Func<bool> condition) { ActionStateStart = actionStateStart; ActionStateEnd = actionStateEnd; Condition = condition; }
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(); }