- Assets/_Game/ 하위로 게임 에셋 통합 - External/ 패키지 벤더별 분류 (Synty, Animations, UI) - 에셋 네이밍 컨벤션 확립 및 적용 (Data_Skill_, Data_SkillEffect_, Prefab_, Anim_, Model_, BT_ 등) - pre-commit hook으로 네이밍 컨벤션 자동 검사 추가 - RESTRUCTURE_CHECKLIST.md 작성 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
|