This commit is contained in:
CortexCore
2024-03-31 23:31:00 +08:00
parent e179d2eb53
commit b7b89ee71a
641 changed files with 31286 additions and 22134 deletions

View File

@@ -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);
}
}
}