Skip to content

Add public property IsInitialized #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Samples~/Sample3d/Scripts/EnemyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Base/StateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class StateBase<TStateId> : IVisitableState
public IStateTimingManager fsm;

/// <summary>
/// Initialises a new instance of the StateBase class.
/// Initializes a new instance of the StateBase class.
/// </summary>
/// <param name="needsExitTime">Determines if the state is allowed to instantly
/// exit on a transition (false), or if the state machine should wait until
Expand All @@ -31,7 +31,7 @@ public StateBase(bool needsExitTime, bool isGhostState = false)
}

/// <summary>
/// Called to initialise the state, after values like <c>name</c> and <c>fsm</c> have been set.
/// Called to initialize the state, after values like <c>name</c> and <c>fsm</c> have been set.
/// </summary>
public virtual void Init()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Base/TransitionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TransitionBase<TStateId> : ITransitionListener
public IStateMachine<TStateId> fsm;

/// <summary>
/// Initialises a new instance of the TransitionBase class.
/// Initializes a new instance of the TransitionBase class.
/// </summary>
/// <param name="from">The name / identifier of the active state.</param>
/// <param name="to">The name / identifier of the next state.</param>
Expand All @@ -30,7 +30,7 @@ public TransitionBase(TStateId from, TStateId to, bool forceInstantly = false)
}

/// <summary>
/// Called to initialise the transition, after values like <c>fsm</c> have been set.
/// Called to initialize the transition, after values like <c>fsm</c> have been set.
/// </summary>
public virtual void Init()
{
Expand Down
4 changes: 2 additions & 2 deletions src/StateMachine/HybridStateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ private Action<HybridStateMachine<TOwnId, TStateId, TEvent>>
beforeOnLogic, afterOnLogic,
beforeOnExit, afterOnExit;

// Lazily initialised
// Lazily initialized
private ActionStorage<TEvent> actionStorage;

public Timer timer;

/// <summary>Initialises a new instance of the HybridStateMachine class.</summary>
/// <summary>Initializes a new instance of the HybridStateMachine class.</summary>
/// <param name="beforeOnEnter">A function that is called before running the sub-state's OnEnter.</param>
/// <param name="afterOnEnter">A function that is called after running the sub-state's OnEnter.</param>
/// <param name="beforeOnLogic">A function that is called before running the sub-state's OnLogic.</param>
Expand Down
13 changes: 7 additions & 6 deletions src/StateMachine/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ public StateBase<TStateId> ActiveState
public TStateId PendingStateName => pendingTransition.targetState;
public StateBase<TStateId> PendingState => GetState(PendingStateName);
public bool HasPendingTransition => pendingTransition.isPending;
public bool IsInitialized => activeState != null;

public IStateTimingManager ParentFsm => fsm;

public bool IsRootFsm => fsm == null;

/// <summary>
/// Initialises a new instance of the StateMachine class.
/// Initializes a new instance of the StateMachine class.
/// </summary>
/// <param name="needsExitTime">(Only for hierarchical states):
/// Determines whether the state machine as a state of a parent state machine is allowed to instantly
Expand All @@ -177,12 +178,12 @@ public StateMachine(bool needsExitTime = false, bool isGhostState = false, bool
}

/// <summary>
/// Throws an exception if the state machine is not initialised yet.
/// Throws an exception if the state machine is not initialized yet.
/// </summary>
/// <param name="context">String message for which action the fsm should be initialised for.</param>
/// <param name="context">String message for which action the fsm should be initialized for.</param>
private void EnsureIsInitializedFor(string context)
{
if (activeState == null)
if (!IsInitialized)
throw UnityHFSM.Exceptions.Common.NotInitialized(this, context);
}

Expand Down Expand Up @@ -406,7 +407,7 @@ public override void Init()
}

/// <summary>
/// Initialises the state machine and must be called before <c>OnLogic</c> is called.
/// Initializes the state machine and must be called before <c>OnLogic</c> is called.
/// It sets the activeState to the selected startState.
/// </summary>
public override void OnEnter()
Expand Down Expand Up @@ -525,7 +526,7 @@ public void AddState(TStateId name, StateBase<TStateId> state)
}

/// <summary>
/// Initialises a transition, i.e. sets its <c>fsm</c> attribute, and then calls its <c>Init</c> method.
/// Initializes a transition, i.e. sets its <c>fsm</c> attribute, and then calls its <c>Init</c> method.
/// </summary>
/// <param name="transition"></param>
private void InitTransition(TransitionBase<TStateId> transition)
Expand Down
2 changes: 1 addition & 1 deletion src/States/ActionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ActionState<TStateId, TEvent> : StateBase<TStateId>, IActionable<TE
private ActionStorage<TEvent> actionStorage;

/// <summary>
/// Initialises a new instance of the ActionState class.
/// Initializes a new instance of the ActionState class.
/// </summary>
/// <inheritdoc cref="StateBase{T}(bool, bool)"/>
public ActionState(bool needsExitTime, bool isGhostState = false)
Expand Down
2 changes: 1 addition & 1 deletion src/States/CoState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CoState<TStateId, TEvent> : ActionState<TStateId, TEvent>
// To allow for this and ease of use, the class has two nearly identical constructors.

/// <summary>
/// Initialises a new instance of the CoState class.
/// Initializes a new instance of the CoState class.
/// </summary>
/// <param name="mono">The MonoBehaviour of the script that should run the coroutine.</param>
/// <param name="onEnter">A function that is called when the state machine enters this state.</param>
Expand Down
2 changes: 1 addition & 1 deletion src/States/ParallelStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ParallelStates(
params StateBase<TStateId>[] states) : this(canExit, needsExitTime, false, states) { }

/// <summary>
/// Initialises a new instance of the ParallelStates class.
/// Initializes a new instance of the ParallelStates class.
/// </summary>
/// <param name="canExit">(Only if <c>needsExitTime</c> is true):
/// Function that determines if the state is ready to exit (true) or not (false).
Expand Down
2 changes: 1 addition & 1 deletion src/States/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class State<TStateId, TEvent> : ActionState<TStateId, TEvent>
public ITimer timer;

/// <summary>
/// Initialises a new instance of the State class.
/// Initializes a new instance of the State class.
/// </summary>
/// <param name="onEnter">A function that is called when the state machine enters this state.</param>
/// <param name="onLogic">A function that is called by the logic function of the state machine if this
Expand Down
2 changes: 1 addition & 1 deletion src/States/StateDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private readonly Action<StateBase<TStateId>>
afterOnExit;

/// <summary>
/// Initialises a new instance of the StateDecorator class.
/// Initializes a new instance of the StateDecorator class.
/// </summary>
public StateDecorator(
Action<StateBase<TStateId>> beforeOnEnter = null,
Expand Down
2 changes: 1 addition & 1 deletion src/Transitions/Transition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Transition<TStateId> : TransitionBase<TStateId>
private readonly Action<Transition<TStateId>> afterTransition;

/// <summary>
/// Initialises a new instance of the Transition class.
/// Initializes a new instance of the Transition class.
/// </summary>
/// <param name="condition">A function that returns true if the state machine
/// should transition to the <c>to</c> state.</param>
Expand Down
2 changes: 1 addition & 1 deletion src/Transitions/TransitionAfter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TransitionAfter<TStateId> : TransitionBase<TStateId>
private readonly Action<TransitionAfter<TStateId>> afterTransition;

/// <summary>
/// Initialises a new instance of the TransitionAfter class.
/// Initializes a new instance of the TransitionAfter class.
/// </summary>
/// <param name="delay">The delay that must elapse before the transition can occur</param>
/// <param name="condition">A function that returns true if the state machine
Expand Down
2 changes: 1 addition & 1 deletion src/Transitions/TransitionAfterDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TransitionAfterDynamic<TStateId> : TransitionBase<TStateId>
private readonly Action<TransitionAfterDynamic<TStateId>> afterTransition;

/// <summary>
/// Initialises a new instance of the TransitionAfterDynamic class.
/// Initializes a new instance of the TransitionAfterDynamic class.
/// </summary>
/// <param name="delay">A function that dynamically computes the delay time.</param>
/// <param name="condition">A function that returns true if the state machine
Expand Down