You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
556 B
30 lines
556 B
using UnityEngine;
|
|
|
|
public interface IState
|
|
{
|
|
public void Enter(StateHandler excutor);
|
|
public void Excute();
|
|
public void Exit();
|
|
}
|
|
|
|
public class StateHandler : MonoBehaviour
|
|
{
|
|
public IState CurrentState { get; private set; }
|
|
|
|
void Update()
|
|
{
|
|
if (CurrentState is null) return;
|
|
CurrentState.Excute();
|
|
}
|
|
|
|
public void ChangeState(IState state)
|
|
{
|
|
if(CurrentState != null)
|
|
{
|
|
CurrentState.Exit();
|
|
}
|
|
|
|
CurrentState = state;
|
|
CurrentState?.Enter(this);
|
|
}
|
|
}
|