[AI] Behavior Actions 시스템 추가

Ultraworked with [Sisyphus](https://github.com/code-yeonggu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-03-11 17:52:16 +09:00
parent 035a87e032
commit a8e8e59c29
30 changed files with 588 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
using System;
using Unity.Behavior;
using UnityEngine;
using Action = Unity.Behavior.Action;
using Unity.Properties;
[Serializable, GeneratePropertyBag]
[NodeDescription(name: "ChaseTarget", story: "타겟 추적", category: "Action", id: "0889fbb015b8bf414ef569af08bb6868")]
public partial class ChaseTargetAction : Action
{
[SerializeReference]
public BlackboardVariable<GameObject> Target;
[SerializeReference]
public BlackboardVariable<float> Speed = new BlackboardVariable<float>(0f);
[SerializeReference]
public BlackboardVariable<float> StopDistance = new BlackboardVariable<float>(2f);
private UnityEngine.AI.NavMeshAgent agent;
protected override Status OnStart()
{
if (Target.Value == null)
{
return Status.Failure;
}
agent = GameObject.GetComponent<UnityEngine.AI.NavMeshAgent>();
if (agent == null)
{
Debug.LogWarning("[ChaseTarget] NavMeshAgent not found");
return Status.Failure;
}
// Speed가 0 이하면 NavMeshAgent의 기존 speed 유지 (EnemyData에서 설정한 값)
if (Speed.Value > 0f)
{
agent.speed = Speed.Value;
}
agent.stoppingDistance = StopDistance.Value;
agent.isStopped = false;
return Status.Running;
}
protected override Status OnUpdate()
{
if (Target.Value == null)
{
return Status.Failure;
}
// 이미 사거리 내에 있으면 성공
float distance = Vector3.Distance(GameObject.transform.position, Target.Value.transform.position);
if (distance <= StopDistance.Value)
{
agent.isStopped = true;
return Status.Success;
}
// 타겟 위치로 이동
agent.SetDestination(Target.Value.transform.position);
return Status.Running;
}
protected override void OnEnd()
{
if (agent != null)
{
agent.isStopped = true;
}
}
}