Skip to content

Commit

Permalink
Merge pull request #17 from techno-dwarf-works/feature/clean-up
Browse files Browse the repository at this point in the history
Version 0.1.10
  • Loading branch information
OpOpYaDev committed May 21, 2024
1 parent 35b1624 commit 79cefb9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
19 changes: 12 additions & 7 deletions Runtime/Implementations/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public async Task ChangeStateAsync(TState state, CancellationToken cancellationT
_transitionTokenSource?.Cancel();
await TransitionTask;

if (cancellationToken.IsCancellationRequested)
{
return;
}

var modules = _modulesLocator.GetElements();
foreach (var module in modules)
{
Expand All @@ -136,18 +141,18 @@ public async Task ChangeStateAsync(TState state, CancellationToken cancellationT
var rootState = CurrentState;

OnStatePreChanged(state);
await _sequence.PreProcessingAsync(rootState, state, cancellationToken);
_sequence.OnPreProcessing(rootState, state);

var sequenceResult = await _sequence.ProcessingAsync(rootState, state, cancellationToken);
_stateChangeCompletionSource.TrySetResult(true);
_stateChangeCompletionSource = null;

if (!cancellationToken.IsCancellationRequested
&& await _sequence.ProcessingAsync(rootState, state, cancellationToken))
if (sequenceResult && !cancellationToken.IsCancellationRequested)
{
CurrentState = state;
await _sequence.PostProcessingAsync(rootState, state, cancellationToken);
_sequence.OnPostProcessing(rootState, state);
OnStateChanged(CurrentState);
}

_stateChangeCompletionSource.TrySetResult(true);
_stateChangeCompletionSource = null;
}

public Task ChangeStateAsync<T>(CancellationToken cancellationToken)
Expand Down
9 changes: 3 additions & 6 deletions Runtime/Sequences/DefaultSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ namespace Better.StateMachine.Runtime.Sequences
[Serializable]
public class DefaultSequence<TState> : Sequence<TState> where TState : BaseState
{
protected internal override Task PreProcessingAsync(TState fromState, TState toState, CancellationToken cancellationToken)
protected internal override void OnPreProcessing(TState fromState, TState toState)
{
return Task.CompletedTask;
}

protected internal override async Task<bool> ProcessingAsync(TState fromState, TState toState, CancellationToken cancellationToken)
Expand All @@ -38,12 +37,10 @@ protected internal override async Task<bool> ProcessingAsync(TState fromState, T
return success;
}

protected internal override Task PostProcessingAsync(TState fromState, TState toState, CancellationToken cancellationToken)
protected internal override void OnPostProcessing(TState fromState, TState toState)
{
fromState?.OnExited();
toState?.OnEntered();

return Task.CompletedTask;
toState.OnEntered();
}
}
}
4 changes: 2 additions & 2 deletions Runtime/Sequences/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Better.StateMachine.Runtime.Sequences
[Serializable]
public abstract class Sequence<TState> where TState : BaseState
{
protected internal abstract Task PreProcessingAsync(TState fromState, TState toState, CancellationToken cancellationToken);
protected internal abstract void OnPreProcessing(TState fromState, TState toState);
protected internal abstract Task<bool> ProcessingAsync(TState fromState, TState toState, CancellationToken cancellationToken);
protected internal abstract Task PostProcessingAsync(TState fromState, TState toState, CancellationToken cancellationToken);
protected internal abstract void OnPostProcessing(TState fromState, TState toState);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.tdw.better.statemachine",
"displayName": "Better State Machine",
"version": "0.1.9",
"version": "0.1.10",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit 79cefb9

Please sign in to comment.