37 lines
859 B
C#
37 lines
859 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace MedievalParty.Core
|
|
{
|
|
public abstract class StateBehaviour: MonoBehaviour
|
|
{
|
|
private IState _currentState;
|
|
private IState _onHoldState;
|
|
|
|
protected virtual void Start()
|
|
{
|
|
_onHoldState = new OnHoldState();
|
|
_currentState = _onHoldState;
|
|
}
|
|
|
|
protected virtual void Update()
|
|
{
|
|
_currentState.OnUpdate();
|
|
}
|
|
|
|
protected void ChangeState() => ChangeState(_onHoldState);
|
|
protected void ChangeState(IState state)
|
|
{
|
|
_currentState.OnExit();
|
|
_currentState = state;
|
|
_currentState.OnEnter();
|
|
}
|
|
}
|
|
|
|
internal class OnHoldState : IState
|
|
{
|
|
public void OnEnter() { }
|
|
public void OnExit() { }
|
|
public void OnUpdate() { }
|
|
}
|
|
} |