using System; using Unity.Behavior; using UnityEngine; using Action = Unity.Behavior.Action; using Unity.Properties; using Colosseum.Combat; using Colosseum.Enemy; [Serializable, GeneratePropertyBag] [NodeDescription(name: "FindTarget", story: "[타겟] 탐색", category: "Action", id: "bb947540549026f3c5625c6d19213311")] public partial class FindTargetAction : Action { [SerializeReference] public BlackboardVariable Target; [SerializeReference] public BlackboardVariable Tag = new BlackboardVariable("Player"); protected override Status OnStart() { if (Tag.Value == null || string.IsNullOrEmpty(Tag.Value)) { return Status.Failure; } // 모든 타겟 후보 검색 GameObject[] candidates = GameObject.FindGameObjectsWithTag(Tag.Value); if (candidates == null || candidates.Length == 0) { return Status.Failure; } EnemyBase enemy = GameObject.GetComponent(); if (enemy != null && enemy.UseThreatSystem) { GameObject threatTarget = enemy.GetHighestThreatTarget(Target?.Value, Tag.Value); if (threatTarget != null) { Target.Value = threatTarget; return Status.Success; } } // 사망하지 않은 타겟 찾기 foreach (GameObject candidate in candidates) { IDamageable damageable = candidate.GetComponent(); // IDamageable이 없거나 살아있는 경우 타겟으로 선택 if (damageable == null || !damageable.IsDead) { Target.Value = candidate; return Status.Success; } } // 살아있는 타겟이 없음 return Status.Failure; } }