Added: Unity scene and assets for AI state machine demo

This commit is contained in:
2026-11-05 18:29:57 +01:00
parent ad3a142d83
commit 05c3126e50
83 changed files with 8077 additions and 0 deletions
@@ -0,0 +1,71 @@
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);
// }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5584ae56d5b0404cb46ba84f0b62a341
timeCreated: 1793895715