From 704faddfcf7574e0dc5842a04cb515220ab89002 Mon Sep 17 00:00:00 2001 From: Eduardo Paez Rubio Date: Sun, 1 Jun 2025 16:41:54 +0200 Subject: [PATCH] Add public property IsInitialized - Standardize spelling to American English: replace initialise with initialize across code comments and docs --- README.md | 4 ++-- Samples~/Sample3d/Scripts/EnemyController.cs | 2 +- src/Base/StateBase.cs | 4 ++-- src/Base/TransitionBase.cs | 4 ++-- src/StateMachine/HybridStateMachine.cs | 4 ++-- src/StateMachine/StateMachine.cs | 13 +++++++------ src/States/ActionState.cs | 2 +- src/States/CoState.cs | 2 +- src/States/ParallelStates.cs | 2 +- src/States/State.cs | 2 +- src/States/StateDecorator.cs | 2 +- src/Transitions/Transition.cs | 2 +- src/Transitions/TransitionAfter.cs | 2 +- src/Transitions/TransitionAfterDynamic.cs | 2 +- 14 files changed, 24 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1b4674f..0032c57 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ As you can see, the enemy will try to stay outside of the player's viewing range )); ``` -- **Initialise the state machine** +- **Initialize the state machine** ```csharp fsm.SetStartState(id); @@ -321,7 +321,7 @@ void Start() { // ... - // Initialises the state machine and must be called before OnLogic() + // Initializes the state machine and must be called before OnLogic() // is called. fsm.Init(); } diff --git a/Samples~/Sample3d/Scripts/EnemyController.cs b/Samples~/Sample3d/Scripts/EnemyController.cs index ef93cc2..dc66b00 100644 --- a/Samples~/Sample3d/Scripts/EnemyController.cs +++ b/Samples~/Sample3d/Scripts/EnemyController.cs @@ -135,7 +135,7 @@ void Start() "ExtractIntel", (transition) => DistanceToPlayer() > playerScanningRange); - // Initialises the state machine and must be called before OnLogic() is called + // Initializes the state machine and must be called before OnLogic() is called fsm.Init(); } diff --git a/src/Base/StateBase.cs b/src/Base/StateBase.cs index 5e86cea..86d7697 100644 --- a/src/Base/StateBase.cs +++ b/src/Base/StateBase.cs @@ -15,7 +15,7 @@ public class StateBase : IVisitableState public IStateTimingManager fsm; /// - /// Initialises a new instance of the StateBase class. + /// Initializes a new instance of the StateBase class. /// /// Determines if the state is allowed to instantly /// exit on a transition (false), or if the state machine should wait until @@ -31,7 +31,7 @@ public StateBase(bool needsExitTime, bool isGhostState = false) } /// - /// Called to initialise the state, after values like name and fsm have been set. + /// Called to initialize the state, after values like name and fsm have been set. /// public virtual void Init() { diff --git a/src/Base/TransitionBase.cs b/src/Base/TransitionBase.cs index cf1bd0d..a285ed9 100644 --- a/src/Base/TransitionBase.cs +++ b/src/Base/TransitionBase.cs @@ -15,7 +15,7 @@ public class TransitionBase : ITransitionListener public IStateMachine fsm; /// - /// Initialises a new instance of the TransitionBase class. + /// Initializes a new instance of the TransitionBase class. /// /// The name / identifier of the active state. /// The name / identifier of the next state. @@ -30,7 +30,7 @@ public TransitionBase(TStateId from, TStateId to, bool forceInstantly = false) } /// - /// Called to initialise the transition, after values like fsm have been set. + /// Called to initialize the transition, after values like fsm have been set. /// public virtual void Init() { diff --git a/src/StateMachine/HybridStateMachine.cs b/src/StateMachine/HybridStateMachine.cs index bea33d8..029216d 100644 --- a/src/StateMachine/HybridStateMachine.cs +++ b/src/StateMachine/HybridStateMachine.cs @@ -18,12 +18,12 @@ private Action> beforeOnLogic, afterOnLogic, beforeOnExit, afterOnExit; - // Lazily initialised + // Lazily initialized private ActionStorage actionStorage; public Timer timer; - /// Initialises a new instance of the HybridStateMachine class. + /// Initializes a new instance of the HybridStateMachine class. /// A function that is called before running the sub-state's OnEnter. /// A function that is called after running the sub-state's OnEnter. /// A function that is called before running the sub-state's OnLogic. diff --git a/src/StateMachine/StateMachine.cs b/src/StateMachine/StateMachine.cs index ff07521..1f27d64 100644 --- a/src/StateMachine/StateMachine.cs +++ b/src/StateMachine/StateMachine.cs @@ -155,13 +155,14 @@ public StateBase ActiveState public TStateId PendingStateName => pendingTransition.targetState; public StateBase PendingState => GetState(PendingStateName); public bool HasPendingTransition => pendingTransition.isPending; + public bool IsInitialized => activeState != null; public IStateTimingManager ParentFsm => fsm; public bool IsRootFsm => fsm == null; /// - /// Initialises a new instance of the StateMachine class. + /// Initializes a new instance of the StateMachine class. /// /// (Only for hierarchical states): /// Determines whether the state machine as a state of a parent state machine is allowed to instantly @@ -177,12 +178,12 @@ public StateMachine(bool needsExitTime = false, bool isGhostState = false, bool } /// - /// Throws an exception if the state machine is not initialised yet. + /// Throws an exception if the state machine is not initialized yet. /// - /// String message for which action the fsm should be initialised for. + /// String message for which action the fsm should be initialized for. private void EnsureIsInitializedFor(string context) { - if (activeState == null) + if (!IsInitialized) throw UnityHFSM.Exceptions.Common.NotInitialized(this, context); } @@ -406,7 +407,7 @@ public override void Init() } /// - /// Initialises the state machine and must be called before OnLogic is called. + /// Initializes the state machine and must be called before OnLogic is called. /// It sets the activeState to the selected startState. /// public override void OnEnter() @@ -525,7 +526,7 @@ public void AddState(TStateId name, StateBase state) } /// - /// Initialises a transition, i.e. sets its fsm attribute, and then calls its Init method. + /// Initializes a transition, i.e. sets its fsm attribute, and then calls its Init method. /// /// private void InitTransition(TransitionBase transition) diff --git a/src/States/ActionState.cs b/src/States/ActionState.cs index aa646c8..921016e 100644 --- a/src/States/ActionState.cs +++ b/src/States/ActionState.cs @@ -12,7 +12,7 @@ public class ActionState : StateBase, IActionable actionStorage; /// - /// Initialises a new instance of the ActionState class. + /// Initializes a new instance of the ActionState class. /// /// public ActionState(bool needsExitTime, bool isGhostState = false) diff --git a/src/States/CoState.cs b/src/States/CoState.cs index c552618..8a0b277 100644 --- a/src/States/CoState.cs +++ b/src/States/CoState.cs @@ -28,7 +28,7 @@ public class CoState : ActionState // To allow for this and ease of use, the class has two nearly identical constructors. /// - /// Initialises a new instance of the CoState class. + /// Initializes a new instance of the CoState class. /// /// The MonoBehaviour of the script that should run the coroutine. /// A function that is called when the state machine enters this state. diff --git a/src/States/ParallelStates.cs b/src/States/ParallelStates.cs index 1c8ef6b..dd90684 100644 --- a/src/States/ParallelStates.cs +++ b/src/States/ParallelStates.cs @@ -64,7 +64,7 @@ public ParallelStates( params StateBase[] states) : this(canExit, needsExitTime, false, states) { } /// - /// Initialises a new instance of the ParallelStates class. + /// Initializes a new instance of the ParallelStates class. /// /// (Only if needsExitTime is true): /// Function that determines if the state is ready to exit (true) or not (false). diff --git a/src/States/State.cs b/src/States/State.cs index 64e975d..155ca16 100644 --- a/src/States/State.cs +++ b/src/States/State.cs @@ -16,7 +16,7 @@ public class State : ActionState public ITimer timer; /// - /// Initialises a new instance of the State class. + /// Initializes a new instance of the State class. /// /// A function that is called when the state machine enters this state. /// A function that is called by the logic function of the state machine if this diff --git a/src/States/StateDecorator.cs b/src/States/StateDecorator.cs index 6ed208d..507da46 100644 --- a/src/States/StateDecorator.cs +++ b/src/States/StateDecorator.cs @@ -19,7 +19,7 @@ private readonly Action> afterOnExit; /// - /// Initialises a new instance of the StateDecorator class. + /// Initializes a new instance of the StateDecorator class. /// public StateDecorator( Action> beforeOnEnter = null, diff --git a/src/Transitions/Transition.cs b/src/Transitions/Transition.cs index b44d477..340adf7 100644 --- a/src/Transitions/Transition.cs +++ b/src/Transitions/Transition.cs @@ -12,7 +12,7 @@ public class Transition : TransitionBase private readonly Action> afterTransition; /// - /// Initialises a new instance of the Transition class. + /// Initializes a new instance of the Transition class. /// /// A function that returns true if the state machine /// should transition to the to state. diff --git a/src/Transitions/TransitionAfter.cs b/src/Transitions/TransitionAfter.cs index b33de5a..0e7b450 100644 --- a/src/Transitions/TransitionAfter.cs +++ b/src/Transitions/TransitionAfter.cs @@ -17,7 +17,7 @@ public class TransitionAfter : TransitionBase private readonly Action> afterTransition; /// - /// Initialises a new instance of the TransitionAfter class. + /// Initializes a new instance of the TransitionAfter class. /// /// The delay that must elapse before the transition can occur /// A function that returns true if the state machine diff --git a/src/Transitions/TransitionAfterDynamic.cs b/src/Transitions/TransitionAfterDynamic.cs index 7a02185..3a0741c 100644 --- a/src/Transitions/TransitionAfterDynamic.cs +++ b/src/Transitions/TransitionAfterDynamic.cs @@ -19,7 +19,7 @@ public class TransitionAfterDynamic : TransitionBase private readonly Action> afterTransition; /// - /// Initialises a new instance of the TransitionAfterDynamic class. + /// Initializes a new instance of the TransitionAfterDynamic class. /// /// A function that dynamically computes the delay time. /// A function that returns true if the state machine