chore: bumped dotnet version to 10
This commit is contained in:
@@ -14,23 +14,22 @@ public class State : BaseEntity, IState
|
||||
|
||||
private readonly List<StateTransition> transitions = [];
|
||||
private readonly Dictionary<string, StateTransition> possibleTransitions = [];
|
||||
private string _name = "Default State Name";
|
||||
|
||||
public IReadOnlyList<StateTransition> Transitions => transitions;
|
||||
public IReadOnlyDictionary<string, StateTransition> PossibleTransitions => possibleTransitions;
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if (_name.CompareTo(value) == 0)
|
||||
if (field.CompareTo(value) == 0)
|
||||
return;
|
||||
|
||||
string previousName = _name;
|
||||
_name = value;
|
||||
string previousName = field;
|
||||
field = value;
|
||||
OnNameChanged?.Invoke(this, new(previousName));
|
||||
}
|
||||
}
|
||||
} = "Default State Name";
|
||||
|
||||
public void RemoveTransition(string name)
|
||||
{
|
||||
|
||||
@@ -10,20 +10,19 @@ public abstract class StateBehaviourBase : Behaviour, IState
|
||||
public Event<IState, IState.StateTransitionReadyArguments> OnStateTransitionReady { get; } = new();
|
||||
public Event<INameable, INameable.NameChangedArguments> OnNameChanged { get; } = new();
|
||||
|
||||
private string _name = string.Empty;
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if (_name.CompareTo(value) == 0)
|
||||
if (field.CompareTo(value) == 0)
|
||||
return;
|
||||
|
||||
string previousName = _name;
|
||||
_name = value;
|
||||
string previousName = field;
|
||||
field = value;
|
||||
OnNameChanged?.Invoke(this, new(previousName));
|
||||
}
|
||||
}
|
||||
} = string.Empty;
|
||||
|
||||
protected virtual void OnUpdateState() { }
|
||||
public void Update()
|
||||
|
||||
@@ -9,33 +9,26 @@ public class StateMachine : Behaviour, IUpdate
|
||||
|
||||
private readonly Event<IState, IState.StateTransitionReadyArguments>.EventHandler delegateOnStateTransitionReady = null!;
|
||||
|
||||
private IState _state = new State();
|
||||
|
||||
public StateMachine()
|
||||
{
|
||||
delegateOnStateTransitionReady = OnStateTransitionReady;
|
||||
}
|
||||
|
||||
[Serialize]
|
||||
public IState State
|
||||
{
|
||||
get => _state;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if (_state == value)
|
||||
if (field == value)
|
||||
return;
|
||||
|
||||
IState previousState = _state;
|
||||
IState previousState = field;
|
||||
previousState.OnStateTransitionReady.RemoveListener(delegateOnStateTransitionReady);
|
||||
|
||||
_state = value;
|
||||
field = value;
|
||||
previousState.TransitionFrom(value);
|
||||
value.TransitionTo(_state);
|
||||
value.TransitionTo(field);
|
||||
OnStateChanged?.Invoke(this, new(value, previousState));
|
||||
|
||||
value.OnStateTransitionReady.AddListener(delegateOnStateTransitionReady);
|
||||
}
|
||||
}
|
||||
} = new State();
|
||||
|
||||
private void OnStateTransitionReady(IState sender, IState.StateTransitionReadyArguments args)
|
||||
{
|
||||
@@ -55,5 +48,10 @@ public class StateMachine : Behaviour, IUpdate
|
||||
State.Update();
|
||||
}
|
||||
|
||||
public StateMachine()
|
||||
{
|
||||
delegateOnStateTransitionReady = OnStateTransitionReady;
|
||||
}
|
||||
|
||||
public readonly record struct StateChangedArguments(IState CurrentState, IState PreviousState);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user