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
+48
View File
@@ -0,0 +1,48 @@
using UnityEngine;
namespace DefaultNamespace.FSM
{
public class IdleState : IState
{
private GameObject _owner;
private PlayerController _player;
private float _viewAngle;
private float _cosViewAngle;
public IdleState(GameObject owner, PlayerController player, float viewAngle)
{
_owner = owner;
_player = player;
_cosViewAngle = Mathf.Cos(viewAngle * Mathf.Deg2Rad);
}
public void Enter(IFiniteStateMachine ctx)
{
Debug.Log("IDLE: Enter");
}
public void Update(IFiniteStateMachine ctx)
{
Debug.Log("IDLE: Update");
float angle = Vector3.Angle(_owner.transform.forward, _player.transform.position - _owner.transform.position);
// if (angle > _viewAngle)
// if (cosAngle > _cosViewAngle)
// player visibility check
if (Physics.Raycast(_owner.transform.position, _owner.transform.forward, out RaycastHit hit))
{
if (hit.transform.GetComponent<PlayerController>() == _player)
{
ctx.SetState(new ChasePlayerState(_owner, _player));
}
}
}
public void Exit(IFiniteStateMachine ctx)
{
Debug.Log("IDLE: Exit");
}
}
}