#if GRAPH_DESIGNER using UnityEngine; using Opsive.BehaviorDesigner.Runtime.Tasks; using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals; using BaseGames.Enemies; namespace BaseGames.Enemies.AI { /// /// BD Conditional:判断目标坐标是否超出指定区域边界。 /// /// /// 未配置 PatrolZone 时返回 Failure(表示"无限制",等同于不超界)。 /// 超界 → Success;区域内 → Failure。 /// /// /// 典型用法:在 Patrol BT 子树中用 BD_IsOutsideZone 检查敌人坐标, /// 超出巡逻区域时触发归位序列。 /// [TaskName("Is Outside Zone")] [TaskCategory("BaseGames/Enemy/Zone")] [TaskDescription("判断敌人/玩家坐标是否超出巡逻或追击区域;无 Zone 时返回 Failure(不限制)")] public sealed class BD_IsOutsideZone : Conditional { [Tooltip("true = 检查追击区域,false = 检查巡逻区域")] [SerializeField] private bool m_CheckChaseZone = false; [Tooltip("true = 检查敌人自身坐标,false = 检查玩家坐标")] [SerializeField] private bool m_CheckEnemy = true; private EnemyBase _enemy; public override void OnAwake() => _enemy = gameObject.GetComponent(); public override TaskStatus OnUpdate() { if (_enemy == null) return TaskStatus.Failure; var zone = _enemy.PatrolZone; if (zone == null) return TaskStatus.Failure; // 无区域 = 不限制 Vector2 pos; if (m_CheckEnemy) { pos = _enemy.transform.position; } else { if (_enemy.PlayerTransform == null) return TaskStatus.Failure; pos = _enemy.PlayerTransform.position; } bool inside = m_CheckChaseZone ? zone.ContainsChase(pos) : zone.ContainsPatrol(pos); return inside ? TaskStatus.Failure : TaskStatus.Success; } } } #endif