42 lines
822 B
C#
42 lines
822 B
C#
using UnityEngine;
|
|
|
|
public class PlayerStateMachine
|
|
{
|
|
PlayerState _state;
|
|
CECHostPlayer _characterCtrl;
|
|
|
|
public PlayerState State { get => _state; }
|
|
|
|
public void InitState(PlayerState state)
|
|
{
|
|
if (_state != null)
|
|
{
|
|
Debug.LogWarning("_state is already inited");
|
|
return;
|
|
}
|
|
_state = state;
|
|
_state.Enter();
|
|
}
|
|
|
|
public void ChangeState(PlayerState state)
|
|
{
|
|
if (_state == null )
|
|
{
|
|
Debug.LogError("you need to init state first ");
|
|
return;
|
|
}
|
|
if (_state == state)
|
|
{
|
|
Debug.LogWarning("Unchanged state");
|
|
}
|
|
_state.Exit();
|
|
_state = state;
|
|
_state.Enter();
|
|
}
|
|
public void UpdateState()
|
|
{
|
|
_state.Update();
|
|
}
|
|
|
|
}
|