Files
gpd-326-en/AI/Assets/Scripts/FSM/StateMachines/ChaseStateMachine.cs
T

71 lines
1.9 KiB
C#

using System;
using UnityEngine;
namespace AI.FSM
{
public class ChaseStateMachine : MonoBehaviour, IFiniteStateMachine
{
[SerializeField] private Transform _playerTransform = null;
private IState _currentState = null;
// private IdleState _idleState = null;
// private PlayerDetectedState _playerDetectedState = null;
//
// private void Awake()
// {
// _idleState = new IdleState();
// _playerDetectedState = new PlayerDetectedState();
// }
private void OnEnable()
{
// ChangeState(States.Idle);
ChangeState(new IdleState(transform, _playerTransform, 60.0f));
}
private void OnDisable()
{
ChangeState(null);
}
public void Update()
{
_currentState?.Update(this);
}
public void ChangeState(IState newState)
{
_currentState?.Exit(this);
_currentState = newState;
_currentState?.Enter(this);
}
// public void ChangeState(States newState)
// {
// _currentState?.Exit(this);
//
// switch (newState)
// {
// case States.Idle:
// _currentState = _idleState;
// break;
// case States.PlayerDetected:
// _currentState = _playerDetectedState;
// break;
// case States.PlayerInRange:
// _currentState = null;
// break;
// case States.PlayerOutOfRange:
// _currentState = null;
// break;
// default:
// throw new ArgumentOutOfRangeException(nameof(newState), newState, null);
// }
//
// _currentState?.Enter(this);
// }
}
}