add unity project

add FSM examples
This commit is contained in:
2025-04-09 07:51:22 +02:00
parent 8f18ee3b79
commit fccc1849fe
81 changed files with 7706 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
using System;
using UnityEngine;
namespace DefaultNamespace.FSM
{
public class ChaseSystem : MonoBehaviour, IFiniteStateMachine
{
[SerializeField] private IState _defaultState;
[SerializeField] private PlayerController _player;
private IState _currentState = null;
private void Awake()
{
// _currentState = _defaultState; // isn't working, because an interface can't be serialized by the Unity Serializer
_currentState = new IdleState(gameObject, _player, 60.0f);
}
private void Start()
{
_currentState?.Enter(this);
}
private void Update()
{
// if (_currentState == null) return;
_currentState?.Update(this);
}
public void SetState(IState state)
{
_currentState.Exit(this);
_currentState = state;
_currentState.Enter(this);
}
}
}