BITFALL/Assets/BITKit/Core/Interfaces/IStateMachine.cs

46 lines
1.1 KiB
C#
Raw Normal View History

2023-08-12 01:43:24 +08:00
using System;
using System.Collections.Generic;
namespace BITKit.StateMachine
{
2023-10-29 15:27:13 +08:00
public struct EmptyState:IState
{
public bool Enabled { get; set; }
public void Initialize()
{
}
public void OnStateEntry(IState old)
{
}
public void OnStateUpdate(float deltaTime)
{
}
public void OnStateExit(IState old, IState newState)
{
}
}
2023-08-12 01:43:24 +08:00
public interface IState
{
2023-08-23 01:59:40 +08:00
bool Enabled { get; set; }
2023-08-12 01:43:24 +08:00
void Initialize();
2023-08-23 01:59:40 +08:00
void OnStateEntry(IState old);
2023-08-27 02:58:19 +08:00
void OnStateUpdate(float deltaTime);
2023-08-12 01:43:24 +08:00
void OnStateExit(IState old, IState newState);
}
2023-08-23 01:59:40 +08:00
2023-08-12 01:43:24 +08:00
public interface IStateMachine<T> where T : IState
{
2023-08-23 01:59:40 +08:00
bool Enabled { get; set; }
2023-08-12 01:43:24 +08:00
T CurrentState { get; set; }
2023-08-23 01:59:40 +08:00
event Action<T,T> OnStateChanged;
2023-08-12 01:43:24 +08:00
IDictionary<Type, T> StateDictionary { get; }
2023-08-23 01:59:40 +08:00
void Initialize();
2023-08-27 02:58:19 +08:00
void UpdateState(float deltaTime);
2023-08-23 01:59:40 +08:00
void DisposeState();
void TransitionState<State>() where State : T;
void TransitionState(T state);
2023-08-12 01:43:24 +08:00
}
}