Added AI Unity project

Added FSM examples
This commit is contained in:
2026-04-20 18:37:00 +02:00
parent cc260fa480
commit 10f61fd5d9
79 changed files with 7891 additions and 0 deletions
@@ -0,0 +1,68 @@
using System;
using UnityEngine;
namespace AI.FSM
{
public class ChaseStateMachine : MonoBehaviour, IFiniteStateMachine
{
[SerializeField] private Transform player;
private IState _currentState;
// private IdleState _idleState;
// private PlayerDetectedState _playerDetectedState;
// // ...
// private void Awake()
// {
// _idleState = new IdleState();
// _playerDetectedState = new PlayerDetectedState();
// // ...
// }
private void OnEnable()
{
ChangeState(new IdleState(gameObject, player, 30.0f));
}
private void OnDisable()
{
ChangeState(null);
}
public void Update()
{
_currentState?.Update(this);
}
public void ChangeState(IState state)
{
_currentState?.Exit(this);
_currentState = state;
_currentState?.Enter(this);
}
// public void ChangeState(States state)
// {
// _currentState?.Exit(this);
//
// switch (state)
// {
// case States.Idle:
// _currentState = _idleState;
// break;
// case States.PlayerDetected:
// _currentState = _playerDetectedState;
// break;
// case States.PlayerInRange:
// break;
// case States.PlayerOutOfRange:
// break;
// default:
// throw new ArgumentOutOfRangeException(nameof(state), state, null);
// }
//
// _currentState?.Enter(this);
// }
}
}