From 0e8f13b369301c58906539f450fce165275949db Mon Sep 17 00:00:00 2001 From: Adam Ramberg Date: Sat, 21 Mar 2020 22:59:30 +0100 Subject: [PATCH] FSM docs --- .../FiniteStateMachine/FiniteStateMachine.cs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Packages/FSM/Runtime/FiniteStateMachine/FiniteStateMachine.cs b/Packages/FSM/Runtime/FiniteStateMachine/FiniteStateMachine.cs index 860710b4..835b92bc 100644 --- a/Packages/FSM/Runtime/FiniteStateMachine/FiniteStateMachine.cs +++ b/Packages/FSM/Runtime/FiniteStateMachine/FiniteStateMachine.cs @@ -9,7 +9,6 @@ namespace UnityAtoms.FSM { /// /// This is an implementation of an FSM in Unity Atoms. It is build using a set of states and a set of transitions. A set can only change through dispatching commands defined by the transitions. - /// See the website docs for more info on usage. /// [EditorIcon("atom-icon-delicate")] [CreateAssetMenu(menuName = "Unity Atoms/FSM/Finite State Machine", fileName = "FiniteStateMachine")] @@ -116,6 +115,11 @@ namespace UnityAtoms.FSM _onStateCooldown = null; } + /// + /// Calls the handler on every Update. + /// + /// The handler to called. + /// The gameObject where this handler is setup. public void OnUpdate(Action handler, GameObject gameObject) { Action extendedHandler = null; @@ -134,6 +138,11 @@ namespace UnityAtoms.FSM _onUpdate += extendedHandler; } + /// + /// Calls the handler on every FixedUpdate. + /// + /// The handler to called. + /// The gameObject where this hook is setup. public void OnFixedUpdate(Action handler, GameObject gameObject) { Action extendedHandler = null; @@ -152,6 +161,9 @@ namespace UnityAtoms.FSM _onFixedUpdate += extendedHandler; } + /// + /// Define a command that is going to automatically be dispatched when the condition provided is met. + /// public void DispatchWhen(string command, Func func, GameObject gameObject) { Action extendedHandler = null; @@ -172,6 +184,12 @@ namespace UnityAtoms.FSM _dispatchWhen += extendedHandler; } + /// + /// Called on every state cooldown. + /// + /// The state where we want to do something on the cool down. + /// Handler to be called on cooldown. + /// The gameObject where this hook is setup. public void OnStateCooldown(string state, Action handler, GameObject gameObject) { Action extendedHandler = null; @@ -193,6 +211,10 @@ namespace UnityAtoms.FSM _onStateCooldown += extendedHandler; } + /// + /// Reset + /// + /// Should we trigger Change Events. public override void Reset(bool shouldTriggerEvents = false) { Validate(); @@ -265,8 +287,6 @@ namespace UnityAtoms.FSM protected override bool ValueEquals(string other) => false; // Always trigger events even if changing to the same state as previous - - private void Validate() { for (var i = 0; i < _transitions.List.Count; ++i)