1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
@@ -31,6 +32,8 @@ namespace BITKit.StateMachine
|
||||
}
|
||||
public TState CurrentState { get; set; }
|
||||
public event Action<TState, TState> OnStateChanged;
|
||||
public event Action<TState> OnStateRegistered;
|
||||
public event Action<TState> OnStateUnRegistered;
|
||||
|
||||
[SerializeReference, SubclassSelector] public List<TState> states = new();
|
||||
[SerializeField,ReadOnly] private string _currentStateName;
|
||||
@@ -48,10 +51,10 @@ namespace BITKit.StateMachine
|
||||
state.Initialize();
|
||||
StateDictionary.Add(state.GetType(), state);
|
||||
}
|
||||
if (states.Count > 0)
|
||||
{
|
||||
TransitionState(states[0]);
|
||||
}
|
||||
// if (states.Count > 0)
|
||||
// {
|
||||
// TransitionState(states[0]);
|
||||
// }
|
||||
}
|
||||
public void UpdateState(float deltaTime)
|
||||
{
|
||||
@@ -101,13 +104,23 @@ namespace BITKit.StateMachine
|
||||
{
|
||||
BIT4Log.Log<MonoStateMachine<TState>>($"TransitionState from {_currentStateName} to {newState.GetType().Name}");
|
||||
}
|
||||
|
||||
newState.OnStateEntry(oldState);
|
||||
CurrentState = newState;
|
||||
newState.OnStateEntry(oldState);
|
||||
OnStateChanged?.Invoke(oldState, newState);
|
||||
_currentStateName = newState.GetType().Name;
|
||||
newState.Enabled = true;
|
||||
}
|
||||
public virtual void Register(TState newState)=>StateMachineUtils.Register(this,newState);
|
||||
public virtual void UnRegister(TState newState)=>StateMachineUtils.UnRegister(this,newState);
|
||||
public void InvokeOnStateRegistered(TState state)
|
||||
{
|
||||
OnStateRegistered?.Invoke(state);
|
||||
}
|
||||
|
||||
public void InvokeOnStateUnRegistered(TState state)
|
||||
{
|
||||
OnStateUnRegistered?.Invoke(state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user