@
chore(ai): 移除死代码 Behavior Designer(BD_* + Opsive 包 + 宏) 敌人 AI 已迁到自研 BrainGraph,旧的 Opsive Behavior Designer 集成全线死亡: 无任何 prefab 挂 BehaviorTree,新系统也不引用 BD 任务。用户手动删除三个 com.opsive.* 包后,BD_* 文件(#if GRAPH_DESIGNER 下引用 Opsive 类型)导致 BaseGames.Enemies.AI 程序集编译失败——本提交清除死代码并恢复编译。 - 删除 ~50 个 BD_*.cs + BDTaskAttributes.cs + BaseGames.Enemies.AI.asmdef。 - 移除 Standalone 的 GRAPH_DESIGNER 脚本宏。 - 移除 com.opsive.behaviordesigner/shared/graphdesigner 嵌入包(用户已删目录)。 已扫描确认无其他程序集引用该 AI 程序集、无真实 Opsive/BD_ 类型引用 (仅注释/Tooltip 提及)。编译 0 错误。属敌人架构重构 P1(死代码清除)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> @
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 458bf9c7d1eae52438922d9630862656
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,37 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using System;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 指定 BD Task 在编辑器任务面板中显示的名称。
|
||||
/// 本版本 BehaviorDesigner 不内置此特性,由项目自行定义以保持代码可读性与前向兼容性。
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
public sealed class TaskNameAttribute : Attribute
|
||||
{
|
||||
public string Name { get; }
|
||||
public TaskNameAttribute(string name) => Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定 BD Task 在编辑器任务面板中所属分类(路径形式,如 "BaseGames/Enemy/Combat")。
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
public sealed class TaskCategoryAttribute : Attribute
|
||||
{
|
||||
public string Category { get; }
|
||||
public TaskCategoryAttribute(string category) => Category = category;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为 BD Task 提供编辑器 Tooltip 描述文本。
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
public sealed class TaskDescriptionAttribute : Attribute
|
||||
{
|
||||
public string Description { get; }
|
||||
public TaskDescriptionAttribute(string description) => Description = description;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e52f911001ee0448971afc570e5e486
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,31 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:发动攻击。
|
||||
/// CanAttack() 检查通过后调用 BeginAttack,立即返回 Success。
|
||||
/// </summary>
|
||||
[TaskName("Attack")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("执行近战攻击(单段或连击序列)")]
|
||||
public class BD_Attack : Action
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || !_enemy.CanAttack())
|
||||
return TaskStatus.Failure;
|
||||
|
||||
_enemy.BeginAttack(AttackType.Melee);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6129e08d8bc28a24ebfb02c246e2e744
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,58 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:启动 Boss 阶段过渡演出(无敌帧 + 可选定格),等待过渡完成后返回 Success。
|
||||
///
|
||||
/// 返回 Running:过渡演出进行中(BossBase.IsPhaseTransitioning = true)。
|
||||
/// 返回 Success:过渡完成或目标阶段已达到(含守护逻辑,防止重复触发)。
|
||||
/// 返回 Failure:BossBase 组件不存在。
|
||||
///
|
||||
/// 典型 BT 用法:
|
||||
/// Sequence [ BD_IsHPBelow(0.5) → BD_BossPhaseTransition(Phase=1, Duration=1.5) → Phase2战斗节点 ]
|
||||
/// 过渡完成后,此节点每 tick 因守护立即返回 Success,Sequence 直接进入后续战斗节点。
|
||||
/// </summary>
|
||||
[TaskName("Boss Phase Transition")]
|
||||
[TaskCategory("BaseGames/Enemy/Boss")]
|
||||
[TaskDescription("触发 Boss 阶段过渡演出(无敌 + 动画 + 广播事件)")]
|
||||
public class BD_BossPhaseTransition : Action
|
||||
{
|
||||
[Tooltip("切换到的目标阶段索引")]
|
||||
[SerializeField] private int m_TargetPhase = 1;
|
||||
|
||||
[Tooltip("无敌帧 + 过渡演出持续时间(秒)")]
|
||||
[SerializeField, Min(0f)] private float m_InvincibleDuration = 1.5f;
|
||||
|
||||
private BossBase _boss;
|
||||
private bool _started;
|
||||
|
||||
public override void OnAwake() => _boss = GetComponent<BossBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_started = false;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_boss == null) return TaskStatus.Failure;
|
||||
|
||||
// 防止 BT 重入时重复触发阶段过渡:目标阶段已达到则直接返回 Success
|
||||
if (_boss.CurrentPhase >= m_TargetPhase) return TaskStatus.Success;
|
||||
|
||||
if (!_started)
|
||||
{
|
||||
_boss.BeginPhaseTransition(m_TargetPhase, m_InvincibleDuration);
|
||||
_started = true;
|
||||
}
|
||||
|
||||
return _boss.IsPhaseTransitioning ? TaskStatus.Running : TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e86991de79acdb3498c9187ea96a8c3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,39 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:向半径内其他敌人广播警戒(Group Alert)。
|
||||
///
|
||||
/// 返回 Success:广播完成(不保证命中任何敌人)。
|
||||
///
|
||||
/// 典型用法:在 BD_SetAiPhase(Chase) 之后立即调用此节点,
|
||||
/// 使发现玩家的敌人将警报传播给周围同伴,实现群体索敌效果。
|
||||
///
|
||||
/// 半径优先使用 m_OverrideRadius;若为 0 则读取 EnemyStatsSO.AlertBroadcastRadius。
|
||||
/// </summary>
|
||||
[TaskName("Broadcast Alert")]
|
||||
[TaskCategory("BaseGames/Enemy/Perception")]
|
||||
[TaskDescription("向附近的友方广播警报,使其进入 Alert 状态")]
|
||||
public class BD_BroadcastAlert : Action
|
||||
{
|
||||
[Tooltip("广播半径(m);0 = 使用 EnemyStatsSO.AlertBroadcastRadius")]
|
||||
[SerializeField, Min(0f)] private float m_OverrideRadius = 0f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
float r = m_OverrideRadius > 0f ? m_OverrideRadius : (_enemy.StatsSO?.AlertBroadcastRadius ?? 0f);
|
||||
_enemy.AlertNearby(r);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93ffcd4596213bf4d8499aa565712213
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,27 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:攻击冷却是否完毕(可以发动攻击)。
|
||||
/// </summary>
|
||||
[TaskName("Can Attack?")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("检查当前是否满足近战攻击条件(距离 + 视线)")]
|
||||
public class BD_CanAttack : Conditional
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
return _enemy.CanAttack() ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 795ff4e1aa5e05b4b86fe8604822e2c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,35 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件:目标坐标从当前位置是否可到达(调用 NavAgent.CanReach,无法寻路时 Failure)。
|
||||
/// 用于 Boss 阶段切换或小怪决策能否追击到跨平台目标。
|
||||
/// </summary>
|
||||
[TaskName("Can Reach Target?")]
|
||||
[TaskCategory("BaseGames/Enemy/Perception")]
|
||||
[TaskDescription("检查 NavAgent 是否可以规划到目标的有效路径")]
|
||||
public sealed class BD_CanReachTarget : Conditional
|
||||
{
|
||||
[Tooltip("检查目标(留空则使用玩家位置)")]
|
||||
[SerializeField] private Transform m_Target;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy?.Nav == null) return TaskStatus.Failure;
|
||||
Vector2 pos = m_Target != null
|
||||
? (Vector2)m_Target.position
|
||||
: _enemy.PlayerTransform != null ? (Vector2)_enemy.PlayerTransform.position : Vector2.zero;
|
||||
return _enemy.Nav.CanReach(pos) ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 436d3fd564880ae46a899b347f9a3494
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,71 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies.Abilities;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件:abilityId 当前可用(冷却完毕且未在运行)。
|
||||
/// 可选开启范围、视线、脚踏地面等调度提示检查;
|
||||
/// 仅当所有启用的条件均满足时才返回 Success。
|
||||
/// </summary>
|
||||
[TaskName("Can Use Ability?")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("检查能力是否存在且冷却就绪,支持范围/视线/地面等调度提示检查")]
|
||||
public sealed class BD_CanUseAbility : Conditional
|
||||
{
|
||||
[Tooltip("能力 ScriptableObject(优先级高于下方字符串 ID)")]
|
||||
[SerializeField] private EnemyAbilitySO m_AbilitySO;
|
||||
|
||||
[Tooltip("能力 ID(当 AbilitySO 未赋值时使用)")]
|
||||
[SerializeField] private string m_AbilityId = "";
|
||||
|
||||
[Header("调度提示(可选)")]
|
||||
[Tooltip("启用后,检查玩家是否在 AbilitySO.preferredRange 范围内")]
|
||||
[SerializeField] private bool m_CheckRange = false;
|
||||
|
||||
[Tooltip("启用后,检查 AbilitySO.requiresLineOfSight 是否满足视线条件")]
|
||||
[SerializeField] private bool m_CheckLineOfSight = false;
|
||||
|
||||
[Tooltip("启用后,检查 AbilitySO.requiresGrounded 是否满足落地条件")]
|
||||
[SerializeField] private bool m_CheckGrounded = false;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
string id = m_AbilitySO != null ? m_AbilitySO.abilityId : m_AbilityId;
|
||||
var ab = _enemy.Abilities.Get(id);
|
||||
if (ab == null || !ab.CanUse) return TaskStatus.Failure;
|
||||
|
||||
// ── 调度提示检查(均可在 Inspector 独立开关)──────────────────────────
|
||||
var config = ab.Config;
|
||||
if (config != null)
|
||||
{
|
||||
if (m_CheckGrounded && config.requiresGrounded && !(_enemy.Movement?.IsGrounded ?? false))
|
||||
return TaskStatus.Failure;
|
||||
|
||||
if (m_CheckLineOfSight && config.requiresLineOfSight && !_enemy.IsPlayerVisible())
|
||||
return TaskStatus.Failure;
|
||||
|
||||
if (m_CheckRange && _enemy.Stats != null)
|
||||
{
|
||||
float sqrDist = _enemy.Stats.SqrDistanceToPlayer;
|
||||
float minSqr = config.preferredMinRange * config.preferredMinRange;
|
||||
float maxSqr = config.preferredMaxRange * config.preferredMaxRange;
|
||||
if (sqrDist < minSqr || sqrDist > maxSqr)
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fbc6b3634e77bf40bfeb918c7e45e5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using UnityEngine;
|
||||
using BaseGames.Boss;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:检查 Boss 技能是否冷却就绪。
|
||||
/// 支持拖拽 BossSkillSO 或直接填写 skillId 字符串(SO 优先)。
|
||||
/// </summary>
|
||||
[TaskName("Can Use Boss Skill?")]
|
||||
[TaskCategory("BaseGames/Enemy/Boss")]
|
||||
[TaskDescription("检查指定 Boss 技能是否在当前阶段可用且冷却就绪")]
|
||||
public class BD_CanUseBossSkill : Conditional
|
||||
{
|
||||
[SerializeField] private BossSkillSO m_SkillSO;
|
||||
[SerializeField] private string m_SkillId;
|
||||
|
||||
private BossBase _boss;
|
||||
private BossSkillExecutor _executor;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
_boss = GetComponent<BossBase>();
|
||||
_executor = transform.GetComponentInChildren<BossSkillExecutor>();
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_executor == null) return TaskStatus.Failure;
|
||||
|
||||
string id = m_SkillSO != null ? m_SkillSO.skillId : m_SkillId;
|
||||
if (string.IsNullOrEmpty(id)) return TaskStatus.Failure;
|
||||
|
||||
return _executor.CanUseSkill(id) ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb7c971f5193f174189337814487bd7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,145 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:追击玩家(三阶段视线丢失模型)。
|
||||
///
|
||||
/// <list type="bullet">
|
||||
/// <item><b>Tracking</b>:持有视线,以奔跑速度追击并更新 LastKnownPlayerPosition。</item>
|
||||
/// <item><b>Searching</b>:视线丢失超过 LostSightBuffer(~0.3s)后进入。速度降低,向最后可见位置行进;若恢复视线即回到 Tracking。</item>
|
||||
/// <item><b>Lost</b>:Searching 持续超过 LoseLinkTimeout → 返回 Failure,让 BD 树切入 BD_InvestigateLastKnown。</item>
|
||||
/// </list>
|
||||
///
|
||||
/// 短暂遮挡(如绕过柱子)在 LostSightBuffer 内不会改变速度,避免追击手感割裂。
|
||||
/// </summary>
|
||||
[TaskName("Chase Player")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("三段式追击(Tracking→Searching→Lost);丢失视线后进入缓冲期")]
|
||||
public sealed class BD_ChasePlayer : Action
|
||||
{
|
||||
[Header("距离限制")]
|
||||
[Tooltip("追击距离上限(m);0 = 使用 EnemyStatsSO.MaxChaseDistance")]
|
||||
[SerializeField] [Min(0f)] private float m_MaxChaseDistance = 0f;
|
||||
|
||||
[Header("视线丢失")]
|
||||
[Tooltip("视线丢失判定超时(s);0 = 使用 EnemyStatsSO.LoseLinkTimeout")]
|
||||
[SerializeField] [Min(0f)] private float m_LoseLinkTimeout = 0f;
|
||||
|
||||
[Tooltip("视线刚丢失后的缓冲期(s):此期间保持追击速度,短暂遮挡不触发搜索模式")]
|
||||
[SerializeField] [Min(0f)] private float m_LostSightBuffer = 0.3f;
|
||||
|
||||
[Header("路径规划")]
|
||||
[Tooltip("路径重规划阈值(m):玩家移动超过此距离后才重新规划,避免每帧请求")]
|
||||
[SerializeField] [Min(0.1f)] private float m_ReplanThreshold = 1.5f;
|
||||
|
||||
[Header("搜索阶段")]
|
||||
[Tooltip("Searching 阶段速度倍率(相对于行走速度;<1 = 减速搜索)")]
|
||||
[SerializeField] [UnityEngine.Range(0.3f, 1.5f)] private float m_SearchSpeedMultiplier = 0.7f;
|
||||
|
||||
private enum ChaseSubState { Tracking, Searching }
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private float _losTimer;
|
||||
private Vector2 _lastReplanPos;
|
||||
private ChaseSubState _subState;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_enemy.SetAiPhase(AiPhase.Chase);
|
||||
_losTimer = 0f;
|
||||
_lastReplanPos = Vector2.positiveInfinity;
|
||||
_subState = ChaseSubState.Tracking;
|
||||
|
||||
float runSpeed = _enemy.Stats?.RunSpeed ?? 4f;
|
||||
_enemy.Nav?.SetSpeed(runSpeed);
|
||||
|
||||
var ac = _enemy.AnimConfig;
|
||||
if (_enemy.Animancer != null && ac?.Run != null)
|
||||
_enemy.Animancer.Play(ac.Run);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || _enemy.PlayerTransform == null)
|
||||
return TaskStatus.Failure;
|
||||
|
||||
float maxDist = m_MaxChaseDistance > 0f ? m_MaxChaseDistance : (_enemy.Stats?.MaxChaseDistance ?? 15f);
|
||||
float loseTime = m_LoseLinkTimeout > 0f ? m_LoseLinkTimeout : (_enemy.Stats?.LoseLinkTimeout ?? 2f);
|
||||
|
||||
// 超出最大追击距离 → 放弃追击
|
||||
if (_enemy.Stats != null && _enemy.Stats.SqrDistanceToPlayer > maxDist * maxDist)
|
||||
return TaskStatus.Failure;
|
||||
|
||||
Vector2 playerPos = _enemy.PlayerTransform.position;
|
||||
|
||||
// 若配置了巡逻区域,且玩家超出追击边界 → 放弃追击(优先级高于纯距离限制)
|
||||
var zone = _enemy.PatrolZone;
|
||||
if (zone != null && !zone.ContainsChase(playerPos))
|
||||
return TaskStatus.Failure;
|
||||
|
||||
if (_enemy.IsPlayerVisible())
|
||||
{
|
||||
// 视线恢复:Searching → Tracking,恢复奔跑速度
|
||||
if (_subState == ChaseSubState.Searching)
|
||||
{
|
||||
_subState = ChaseSubState.Tracking;
|
||||
_enemy.Nav?.SetSpeed(_enemy.Stats?.RunSpeed ?? 4f);
|
||||
}
|
||||
_losTimer = 0f;
|
||||
_enemy.LastKnownPlayerPosition = playerPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
_losTimer += Time.deltaTime;
|
||||
|
||||
if (_subState == ChaseSubState.Tracking)
|
||||
{
|
||||
// 缓冲期结束 → 切入 Searching:减速并向最后可见位置行进
|
||||
if (_losTimer >= m_LostSightBuffer)
|
||||
{
|
||||
_subState = ChaseSubState.Searching;
|
||||
float searchSpeed = (_enemy.Stats?.WalkSpeed ?? 2f) * m_SearchSpeedMultiplier;
|
||||
_enemy.Nav?.SetSpeed(searchSpeed);
|
||||
_enemy.MoveTo(_enemy.LastKnownPlayerPosition);
|
||||
_lastReplanPos = _enemy.LastKnownPlayerPosition;
|
||||
}
|
||||
}
|
||||
else // Searching
|
||||
{
|
||||
if (_losTimer >= loseTime)
|
||||
return TaskStatus.Failure; // 搜索超时 → 进入 BD_InvestigateLastKnown
|
||||
}
|
||||
}
|
||||
|
||||
// Tracking 阶段按阈值重规划路径
|
||||
if (_subState == ChaseSubState.Tracking)
|
||||
{
|
||||
float sqrReplan = m_ReplanThreshold * m_ReplanThreshold;
|
||||
if ((playerPos - _lastReplanPos).sqrMagnitude > sqrReplan)
|
||||
{
|
||||
_enemy.MoveTo(playerPos);
|
||||
_lastReplanPos = playerPos;
|
||||
}
|
||||
}
|
||||
|
||||
_enemy.FacePlayer();
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
float walkSpeed = _enemy?.Stats?.WalkSpeed ?? 2f;
|
||||
_enemy?.Nav?.SetSpeed(walkSpeed);
|
||||
_enemy?.StopMovement();
|
||||
_subState = ChaseSubState.Tracking; // 重置子状态,防止下次激活时以错误状态重入
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7ecfbdf1fee6a141a18c72d36fcfbf2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,35 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:Boss 切换阶段(Phase)。
|
||||
/// 调用 BossBase.EnterPhase(PhaseIndex),单帧完成,返回 Success。
|
||||
/// </summary>
|
||||
[TaskName("Enter Boss Phase")]
|
||||
[TaskCategory("BaseGames/Enemy/Boss")]
|
||||
[TaskDescription("立即切换 Boss 到目标阶段序号(单帧完成)")]
|
||||
public class BD_EnterPhase : Action
|
||||
{
|
||||
[UnityEngine.SerializeField] private int m_PhaseIndex = 1;
|
||||
|
||||
private BossBase _boss;
|
||||
|
||||
public override void OnAwake() => _boss = GetComponent<BossBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
// 阶段切换是单帧操作,在 OnStart 完成;OnUpdate 仅汇报结果
|
||||
_boss?.EnterPhase(m_PhaseIndex);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
return _boss == null ? TaskStatus.Failure : TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b532ff86847a744c801b1b6c4bae0c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,29 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:立即朝向玩家,单帧完成,返回 Success。
|
||||
/// </summary>
|
||||
[TaskName("Face Target")]
|
||||
[TaskCategory("BaseGames/Enemy/Animation")]
|
||||
[TaskDescription("立即朝向目标 Transform 或玩家,单帧返回 Success")]
|
||||
public class BD_FaceTarget : Action
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
_enemy.FacePlayer();
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ed2d3259efee514b8e17bc22ca021e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,32 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies.Abilities;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>动作:中断指定能力。</summary>
|
||||
[TaskName("Interrupt Ability")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("立即中断指定能力或全部能力")]
|
||||
public sealed class BD_InterruptAbility : Action
|
||||
{
|
||||
[SerializeField] private string m_AbilityId = "";
|
||||
[SerializeField] private InterruptReason m_Reason = InterruptReason.ExternalRequest;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
var ab = _enemy.Abilities.Get(m_AbilityId);
|
||||
if (ab == null) return TaskStatus.Failure;
|
||||
ab.Interrupt(m_Reason);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3db7ca634cc20574dba7f11ab018b23a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,162 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:多步搜查(Navigate → LookAround → RandomWalk × N)。
|
||||
///
|
||||
/// <list type="bullet">
|
||||
/// <item><b>Navigate</b>:导航至最后可见位置。</item>
|
||||
/// <item><b>LookAround</b>:到达后原地环顾(播放 Look 动画,持续 LookAroundDuration)。</item>
|
||||
/// <item><b>WalkRandom</b>:向搜查半径内的随机点移动,重复 RandomStepCount 次。</item>
|
||||
/// <item>任意阶段重新发现玩家 → 返回 Failure,BD 树重入追击。</item>
|
||||
/// <item>所有步骤完成仍未发现 → 返回 Success,BD 树归位/恢复巡逻。</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[TaskName("Investigate Last Known Pos")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("多步搜查:导航到最后已知位置 → 环顾四周 → 随机游走 N 次")]
|
||||
public sealed class BD_InvestigateLastKnown : Action
|
||||
{
|
||||
[Tooltip("到达搜查点后环顾的时长(s)")]
|
||||
[SerializeField] private float m_LookAroundDuration = 0.8f;
|
||||
|
||||
[Tooltip("随机行走步数(完成环顾后随机游荡的次数)")]
|
||||
[SerializeField] [Min(0)] private int m_RandomStepCount = 2;
|
||||
|
||||
[Tooltip("随机行走半径(m)")]
|
||||
[SerializeField] private float m_SearchRadius = 2.5f;
|
||||
|
||||
[Tooltip("到达目标点的判定半径(m)")]
|
||||
[SerializeField] private float m_ArriveRadius = 0.6f;
|
||||
|
||||
private enum InvestigateSubStep { Navigate, LookAround, WalkRandom }
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private InvestigateSubStep _step;
|
||||
private float _stepTimer;
|
||||
private int _stepsRemaining;
|
||||
private Vector2 _randomTarget;
|
||||
private bool _pathFailed;
|
||||
private bool _subscribed;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_enemy.SetAiPhase(AiPhase.Investigate);
|
||||
_step = InvestigateSubStep.Navigate;
|
||||
_stepTimer = 0f;
|
||||
_stepsRemaining = m_RandomStepCount;
|
||||
_pathFailed = false;
|
||||
|
||||
if (!_subscribed && _enemy.Nav != null)
|
||||
{
|
||||
_enemy.Nav.OnNavPathFailed += HandlePathFailed;
|
||||
_subscribed = true;
|
||||
}
|
||||
|
||||
_enemy.MoveTo(_enemy.LastKnownPlayerPosition);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
if (_enemy.IsPlayerVisible()) return TaskStatus.Failure;
|
||||
|
||||
switch (_step)
|
||||
{
|
||||
case InvestigateSubStep.Navigate: return UpdateNavigate();
|
||||
case InvestigateSubStep.LookAround: return UpdateLookAround();
|
||||
case InvestigateSubStep.WalkRandom: return UpdateWalkRandom();
|
||||
default: return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (_subscribed && _enemy?.Nav != null)
|
||||
_enemy.Nav.OnNavPathFailed -= HandlePathFailed;
|
||||
_subscribed = false;
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
|
||||
// ── 阶段逻辑 ────────────────────────────────────────────────────
|
||||
private TaskStatus UpdateNavigate()
|
||||
{
|
||||
Vector2 self = _enemy.transform.position;
|
||||
bool arrived = _pathFailed ||
|
||||
(self - _enemy.LastKnownPlayerPosition).sqrMagnitude <= m_ArriveRadius * m_ArriveRadius;
|
||||
|
||||
if (!arrived) return TaskStatus.Running;
|
||||
|
||||
_enemy.StopMovement();
|
||||
EnterLookAround();
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
private TaskStatus UpdateLookAround()
|
||||
{
|
||||
_stepTimer += Time.deltaTime;
|
||||
if (_stepTimer < m_LookAroundDuration) return TaskStatus.Running;
|
||||
|
||||
if (_stepsRemaining > 0)
|
||||
EnterRandomWalk();
|
||||
else
|
||||
return TaskStatus.Success;
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
private TaskStatus UpdateWalkRandom()
|
||||
{
|
||||
Vector2 self = _enemy.transform.position;
|
||||
bool arrived = _pathFailed ||
|
||||
(self - _randomTarget).sqrMagnitude <= m_ArriveRadius * m_ArriveRadius;
|
||||
|
||||
if (!arrived) return TaskStatus.Running;
|
||||
|
||||
_enemy.StopMovement();
|
||||
_stepsRemaining--;
|
||||
_pathFailed = false;
|
||||
|
||||
if (_stepsRemaining > 0)
|
||||
EnterRandomWalk();
|
||||
else
|
||||
return TaskStatus.Success;
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
// ── 辅助方法 ────────────────────────────────────────────────────
|
||||
private void EnterLookAround()
|
||||
{
|
||||
_step = InvestigateSubStep.LookAround;
|
||||
_stepTimer = 0f;
|
||||
_enemy.BeginLookAround();
|
||||
}
|
||||
|
||||
private void EnterRandomWalk()
|
||||
{
|
||||
_step = InvestigateSubStep.WalkRandom;
|
||||
_pathFailed = false;
|
||||
|
||||
Vector2 origin = _enemy.LastKnownPlayerPosition;
|
||||
// 横板地形中只在水平方向随机偏移,保留 origin.y;
|
||||
// PathBerserker2d 寻路负责处理跨平台的纵向路径规划。
|
||||
float dir = Random.value > 0.5f ? 1f : -1f;
|
||||
float dist = Random.Range(0.5f, m_SearchRadius);
|
||||
_randomTarget = new Vector2(origin.x + dir * dist, origin.y);
|
||||
|
||||
_enemy.MoveTo(_randomTarget);
|
||||
}
|
||||
|
||||
private void HandlePathFailed() => _pathFailed = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e43db9982a49864e95812919b0efd10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,34 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies.Abilities;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>条件:abilityId 当前是否正在运行。</summary>
|
||||
[TaskName("Is Ability Running?")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("检查指定能力当前是否正在执行中")]
|
||||
public sealed class BD_IsAbilityRunning : Conditional
|
||||
{
|
||||
[Tooltip("能力 ScriptableObject(优先级高于下方字符串 ID)")]
|
||||
[SerializeField] private EnemyAbilitySO m_AbilitySO;
|
||||
|
||||
[Tooltip("能力 ID(当 AbilitySO 未赋值时使用)")]
|
||||
[SerializeField] private string m_AbilityId = "";
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
string id = m_AbilitySO != null ? m_AbilitySO.abilityId : m_AbilityId;
|
||||
var ab = _enemy.Abilities.Get(id);
|
||||
return ab != null && ab.IsRunning ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 254e8e3d6b56229498e94e24e7e53393
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,36 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:当前 AI 行为阶段是否与目标匹配。
|
||||
///
|
||||
/// 常用于 Decorator Conditional Abort 或 Sequence 头部保护子树,
|
||||
/// 例如只有在 <see cref="AiPhase.Patrol"/> 阶段时才执行巡逻序列。
|
||||
/// </summary>
|
||||
[TaskName("Is Ai Phase?")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("检查当前 AI 行为阶段是否与目标枚举值匹配")]
|
||||
public sealed class BD_IsAiPhase : Conditional
|
||||
{
|
||||
[Tooltip("目标 AI 行为阶段")]
|
||||
[SerializeField] private AiPhase m_Phase = AiPhase.Patrol;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
return _enemy.CurrentAiPhase == m_Phase
|
||||
? TaskStatus.Success
|
||||
: TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5d65c8544c21a146a5f30140acdb5ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,27 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:敌人是否处于地面。
|
||||
/// </summary>
|
||||
[TaskName("Is Grounded?")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("检查敌人是否接地(适用于触发跳跃或落地逻辑的条件保护)")]
|
||||
public class BD_IsGrounded : Conditional
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || _enemy.Movement == null) return TaskStatus.Failure;
|
||||
return _enemy.Movement.IsGrounded ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3047372de5d51a4f98aee8505490bf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,34 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:Boss HP 是否低于阈值(用于触发阶段切换)。
|
||||
/// HPThreshold 为 0~1 归一化比例(如 0.5 = HP ≤ 50%)。
|
||||
/// </summary>
|
||||
[TaskName("Is HP Below Threshold?")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("检查当前 HP 是否低于指定百分比阈值")]
|
||||
public class BD_IsHPBelow : Conditional
|
||||
{
|
||||
[UnityEngine.Range(0f, 1f)]
|
||||
[UnityEngine.SerializeField] private float m_HPThreshold = 0.5f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || _enemy.Stats == null) return TaskStatus.Failure;
|
||||
|
||||
float maxHP = UnityEngine.Mathf.Max(1f, _enemy.Stats.MaxHP);
|
||||
float ratio = (float)_enemy.Stats.CurrentHP / maxHP;
|
||||
return ratio <= m_HPThreshold ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1b683b9405d60c4daacd09719b186b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,28 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:敌人是否靠近平台边缘。
|
||||
/// 通过 EnemyNavAgent.IsNearEdge() 检测(双射线检测脚下/前方地面)。
|
||||
/// </summary>
|
||||
[TaskName("Is Near Edge?")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("检查前方是否有悬崖边缘(基于 EnemyNavAgent Raycast 检测)")]
|
||||
public class BD_IsNearEdge : Conditional
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || _enemy.Nav == null) return TaskStatus.Failure;
|
||||
return _enemy.Nav.IsNearEdge() ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 008a71992a8cb644a94c331e06cd3955
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,35 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件:NavAgent 当前是否正在穿越连接段(跳跃/下落/爬梯/传送等)。
|
||||
/// 可选过滤具体连接类型(填 None = 任意类型均匹配)。
|
||||
/// </summary>
|
||||
[TaskName("Is On NavLink?")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("检查 NavAgent 当前是否正在穿越 NavLink(如跳跃传送门)")]
|
||||
public sealed class BD_IsOnNavLink : Conditional
|
||||
{
|
||||
[Tooltip("填 None 匹配任意类型;填具体类型则只在该类型时 Success。")]
|
||||
[SerializeField] private NavLinkType m_FilterType = NavLinkType.None;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy?.Nav == null) return TaskStatus.Failure;
|
||||
if (!_enemy.Nav.IsOnLink) return TaskStatus.Failure;
|
||||
if (m_FilterType != NavLinkType.None && _enemy.Nav.CurrentLinkType != m_FilterType)
|
||||
return TaskStatus.Failure;
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44406bb7e06320746950682adf59f59c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:判断目标坐标是否超出指定区域边界。
|
||||
///
|
||||
/// <list type="bullet">
|
||||
/// <item>未配置 PatrolZone 时返回 Failure(表示"无限制",等同于不超界)。</item>
|
||||
/// <item>超界 → Success;区域内 → Failure。</item>
|
||||
/// </list>
|
||||
///
|
||||
/// 典型用法:在 Patrol BT 子树中用 BD_IsOutsideZone 检查敌人坐标,
|
||||
/// 超出巡逻区域时触发归位序列。
|
||||
/// </summary>
|
||||
[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<EnemyBase>();
|
||||
|
||||
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
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bff87912e6defb849bea247df2801172
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,31 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:检查玩家是否在指定范围内。
|
||||
/// 成功/失败直接驱动 BT 分支选择(Selector / Sequence 节点)。
|
||||
/// </summary>
|
||||
[TaskName("Is Player In Range?")]
|
||||
[TaskCategory("BaseGames/Enemy/Perception")]
|
||||
[TaskDescription("检查玩家是否在指定距离内")]
|
||||
public class BD_IsPlayerInRange : Conditional
|
||||
{
|
||||
/// <summary>检测范围(Inspector 可配置,默认 6 米)。</summary>
|
||||
public float Range = 6f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
return _enemy.IsPlayerInRange(Range) ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d176aa20179c6b43a6798432eb073a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,28 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:玩家是否可见(LOS 检测)。
|
||||
/// 读取 EnemyBase.IsPlayerVisible(),结果来自 PhysicsPerceptionSystem(LOS / Sight 槽位)。
|
||||
/// </summary>
|
||||
[TaskName("Is Player Visible?")]
|
||||
[TaskCategory("BaseGames/Enemy/Perception")]
|
||||
[TaskDescription("检查是否有视线到达玩家(通过 EnemyBase.HasLineOfSight)")]
|
||||
public class BD_IsPlayerVisible : Conditional
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
return _enemy.IsPlayerVisible() ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f8a58f1dbebf644999205d1a2febdc9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,41 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies.Perception;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件:<see cref="IPerceptionSystem"/> 中名为 slotName 的槽位是否检测到目标。
|
||||
/// 若 m_Target 为空则使用 EnemyBase.PlayerTransform。
|
||||
/// </summary>
|
||||
[TaskName("Is Sensor Detecting?")]
|
||||
[TaskCategory("BaseGames/Enemy/Perception")]
|
||||
[TaskDescription("检查 PhysicsPerceptionSystem 中指定 Sensor 槽是否检测到目标")]
|
||||
public sealed class BD_IsSensorDetecting : Conditional
|
||||
{
|
||||
[SerializeField] private string m_SlotName = "aggro";
|
||||
[SerializeField] private bool m_AnyTarget = false;
|
||||
|
||||
private IPerceptionSystem _hub;
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
_hub = gameObject.GetComponent<IPerceptionSystem>();
|
||||
_enemy = gameObject.GetComponent<EnemyBase>();
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_hub == null) return TaskStatus.Failure;
|
||||
if (m_AnyTarget)
|
||||
return _hub.HasAnyDetection(m_SlotName) ? TaskStatus.Success : TaskStatus.Failure;
|
||||
var tgt = _enemy != null ? _enemy.PlayerTransform : null;
|
||||
if (tgt == null) return TaskStatus.Failure;
|
||||
return _hub.IsDetecting(m_SlotName, tgt.gameObject) ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a1015b63dbb3da4aa877d7e898b394a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,30 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional:敌人当前 EnemyStateType 是否与目标状态匹配。
|
||||
/// </summary>
|
||||
[TaskName("Is State Match?")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("检查当前物理/战斗状态是否与目标枚举值匹配")]
|
||||
public class BD_IsStateMatch : Conditional
|
||||
{
|
||||
[SerializeField] private EnemyStateType m_TargetState = EnemyStateType.Controlled;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
return _enemy.CurrentState == m_TargetState ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 058372e0cdf7c5b40b53838cf89b8daf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,49 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:跳跃至目标坐标(抛物线跳跃)。
|
||||
/// 调用 EnemyBase.JumpTo,待落地(IsGrounded)后返回 Success。
|
||||
/// </summary>
|
||||
[TaskName("Jump To")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("执行跳跃动作到达目标高度或 NavLink 对接点")]
|
||||
public class BD_JumpTo : Action
|
||||
{
|
||||
[SerializeField] private Vector2 m_Target;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private bool _jumped;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_jumped = false;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
if (!_jumped)
|
||||
{
|
||||
_enemy.JumpTo(m_Target);
|
||||
_jumped = true;
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
// 等待落地
|
||||
if (_enemy.Movement != null && _enemy.Movement.IsGrounded)
|
||||
return TaskStatus.Success;
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7907401e39b5fdf409449af475640396
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,94 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:战斗站位控制。
|
||||
/// 在 [m_PreferredMinDist, m_PreferredMaxDist] 范围内保持与玩家的水平距离:
|
||||
/// - 距离过近 → 后退
|
||||
/// - 距离过远 → 靠近
|
||||
/// - 在范围内 → 停止移动,持续朝向玩家
|
||||
/// 始终返回 Running,上层 BT 通过 Abort 或条件终止该 Task。
|
||||
/// </summary>
|
||||
[TaskName("Maintain Combat Distance")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("在战斗中维持与目标的理想距离范围")]
|
||||
public class BD_MaintainCombatDistance : Action
|
||||
{
|
||||
[Tooltip("期望最小距离(m);小于此值开始后退")]
|
||||
[SerializeField] private float m_PreferredMinDist = 2f;
|
||||
|
||||
[Tooltip("期望最大距离(m);大于此值开始靠近")]
|
||||
[SerializeField] private float m_PreferredMaxDist = 4f;
|
||||
|
||||
[Tooltip("后退速度(m/s),默认使用 WalkSpeed")]
|
||||
[SerializeField] private float m_BackpedaleSpeed = 0f;
|
||||
|
||||
[Tooltip("每帧重新规划路径的阈值(m);玩家移动超过此距离才重规划,降低频率")]
|
||||
[SerializeField] private float m_ReplanThreshold = 0.5f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private Vector2 _lastPlayerPos;
|
||||
private float _sqrMin;
|
||||
private float _sqrMax;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_sqrMin = m_PreferredMinDist * m_PreferredMinDist;
|
||||
_sqrMax = m_PreferredMaxDist * m_PreferredMaxDist;
|
||||
_lastPlayerPos = Vector2.positiveInfinity;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || _enemy.PlayerTransform == null)
|
||||
return TaskStatus.Failure;
|
||||
|
||||
if (_enemy.Stats == null)
|
||||
return TaskStatus.Failure;
|
||||
|
||||
_enemy.FacePlayer();
|
||||
|
||||
float sqrDist = _enemy.Stats.SqrDistanceToPlayer;
|
||||
|
||||
if (sqrDist < _sqrMin)
|
||||
{
|
||||
// 距离过近 → 后退(向远离玩家方向移动)
|
||||
_enemy.Nav?.StopNavigation();
|
||||
Vector2 toPlayer = ((Vector2)_enemy.PlayerTransform.position - (Vector2)_enemy.transform.position).normalized;
|
||||
float backDir = -Mathf.Sign(toPlayer.x);
|
||||
float speed = m_BackpedaleSpeed > 0f ? m_BackpedaleSpeed : _enemy.Stats.WalkSpeed;
|
||||
_enemy.MoveInDirectionWithSpeed(backDir, speed);
|
||||
}
|
||||
else if (sqrDist > _sqrMax)
|
||||
{
|
||||
// 距离过远 → 靠近
|
||||
Vector2 playerPos = _enemy.PlayerTransform.position;
|
||||
float moved = ((Vector2)playerPos - _lastPlayerPos).sqrMagnitude;
|
||||
if (moved > m_ReplanThreshold * m_ReplanThreshold)
|
||||
{
|
||||
_lastPlayerPos = playerPos;
|
||||
_enemy.MoveTo(playerPos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 在最优范围内 → 停止导航,原地保持朝向
|
||||
_enemy.StopMovement();
|
||||
}
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 480875a7bad333140a3c46e637eb7bc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,42 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:移动到指定世界坐标 Target。
|
||||
/// 到达目标(IsAtDestination)后返回 Success。
|
||||
/// </summary>
|
||||
[TaskName("Move To")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("导航到目标 Transform 或世界坐标点;到达返回 Success")]
|
||||
public class BD_MoveTo : Action
|
||||
{
|
||||
[SerializeField] private Vector2 m_Target;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
_enemy.MoveTo(m_Target);
|
||||
|
||||
if (_enemy.Nav != null && _enemy.Nav.IsAtDestination())
|
||||
return TaskStatus.Success;
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 460aa03baecb5b547980f7bab7cfee22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,58 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 动作:移动到目标并等待 OnGoalReached 事件(事件驱动,替代轮询版 BD_MoveTo)。
|
||||
/// OnGoalReached 触发后返回 Success;路径失败返回 Failure。
|
||||
/// </summary>
|
||||
[TaskName("Move To And Wait")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("导航到目标点,到达后原地等待指定时长,然后返回 Success")]
|
||||
public sealed class BD_MoveToAndWait : Action
|
||||
{
|
||||
[SerializeField] private Transform m_Target;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private bool _reached;
|
||||
private bool _failed;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_reached = _failed = false;
|
||||
if (_enemy?.Nav == null) { _failed = true; return; }
|
||||
_enemy.Nav.OnGoalReached += HandleReached;
|
||||
_enemy.Nav.OnNavPathFailed += HandleFailed;
|
||||
var pos = m_Target != null ? (Vector2)m_Target.position
|
||||
: _enemy.PlayerTransform != null ? (Vector2)_enemy.PlayerTransform.position
|
||||
: (Vector2)transform.position;
|
||||
_enemy.Nav.RequestMoveTo(pos);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_failed) return TaskStatus.Failure;
|
||||
if (_reached) return TaskStatus.Success;
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (_enemy?.Nav != null)
|
||||
{
|
||||
_enemy.Nav.OnGoalReached -= HandleReached;
|
||||
_enemy.Nav.OnNavPathFailed -= HandleFailed;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleReached() => _reached = true;
|
||||
private void HandleFailed() => _failed = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df51ca671ebccea47a45c1e1bca3caa3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,43 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:移向玩家。
|
||||
/// OnStart 从 EnemyBase.PlayerTransform 获取玩家引用(由 _onPlayerSpawned 事件缓存,
|
||||
/// 避免 FindWithTag 全场景扫描)。OnUpdate 每帧更新导航目标。
|
||||
/// </summary>
|
||||
[TaskName("Move To Player")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("持续向玩家方向移动,失去视线或超出追踪距离返回 Failure")]
|
||||
public class BD_MoveToPlayer : Action
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_enemy.SetAiPhase(AiPhase.Chase);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
if (_enemy.PlayerTransform == null) return TaskStatus.Failure;
|
||||
|
||||
_enemy.MoveTo(_enemy.PlayerTransform.position);
|
||||
_enemy.FacePlayer();
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67b2f5400ef71aa4fae183cf1ce1e649
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,30 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Conditional Task:检查敌人本次 BT Tick 内是否发生了弹反事件。
|
||||
///
|
||||
/// 返回 <c>Success</c> 时同时清除标志(每次弹反只触发一次响应分支)。
|
||||
/// 典型用法:在 BD 树根部优先分支放置此条件,触发时执行受击硬直 / 反制动画等子树。
|
||||
/// </summary>
|
||||
[TaskName("On Parried?")]
|
||||
[TaskCategory("BaseGames/Enemy/Utility")]
|
||||
[TaskDescription("检查上一次攻击是否被玩家格挡(用于 Boss 反制逻辑)")]
|
||||
public class BD_OnParried : Conditional
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
return _enemy.ConsumeParryEvent() ? TaskStatus.Success : TaskStatus.Failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdae429711fc46d41a7b025eed43784f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,69 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:来回踱步巡逻——持续向当前方向移动,遇墙或悬崖时自动翻转方向。
|
||||
/// 转向检测通过 <see cref="EnemyMovement.IsWallAhead"/> / <see cref="EnemyMovement.IsLedgeAhead"/>
|
||||
/// 进行;这两项是 EnemyMovement 内置的物理射线检测,不属于感知系统(PhysicsPerceptionSystem)。
|
||||
///
|
||||
/// 若需要按预设路点顺序巡逻,请使用 <see cref="BD_PatrolWaypoints"/>(支持 Transform 引用和内联坐标)。
|
||||
/// </summary>
|
||||
[TaskName("Patrol (Pace)")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("来回踱步巡逻:遇墙或悬崖自动翻转方向(通过 EnemyMovement 物理射线检测,无需感知槽)")]
|
||||
public class BD_Patrol : Action
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
private EnemyMovement _movement;
|
||||
private float _dir = 1f;
|
||||
private float _flipCooldown; // 翻转后短暂冷却,等待射线刷新到新朝向
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
_enemy = GetComponent<EnemyBase>();
|
||||
_movement = _enemy?.Movement;
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_enemy?.SetAiPhase(AiPhase.Patrol);
|
||||
// 与敌人实际朝向同步,防止任务重入时 _dir 与朝向不符(如战斗后朝向已改变)
|
||||
if (_movement != null)
|
||||
_dir = _movement.FacingDirection;
|
||||
_flipCooldown = 0f;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
// 翻转冷却期间跳过物理检测(等待射线在新朝向完成刷新)
|
||||
if (_flipCooldown > 0f)
|
||||
_flipCooldown -= Time.deltaTime;
|
||||
else if (ShouldFlip())
|
||||
{
|
||||
_dir = -_dir;
|
||||
_flipCooldown = 0.1f; // ~6 帧缓冲(60 fps),防止射线残留信号导致抖动
|
||||
}
|
||||
|
||||
_enemy.MoveInDirection(_dir);
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd() => _enemy?.StopMovement();
|
||||
|
||||
private bool ShouldFlip()
|
||||
{
|
||||
// 转身进行中时不重复检测,防止 _dir 在转身期间被残留信号反复翻转
|
||||
if (_movement == null || _movement.IsTurning) return false;
|
||||
return _movement.IsWallAhead || _movement.IsLedgeAhead;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0fd85d7c7ce18f4193bb3b70707d055
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,241 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:按预设路点顺序巡逻(支持 Transform 引用或内联 Vector2 坐标两种模式)。
|
||||
///
|
||||
/// <list type="bullet">
|
||||
/// <item><b>m_Waypoints(Transform[])</b>:拖入场景中的路点对象;适合动态路点(可在运行时移动)。</item>
|
||||
/// <item><b>m_InlineWaypoints(Vector2[])</b>:直接填写世界坐标;无需在场景中放置对象,编辑器中以 Gizmo 可视化路径。</item>
|
||||
/// <item>两者同时设置时 m_Waypoints 优先。</item>
|
||||
/// </list>
|
||||
///
|
||||
/// 到达最后一个路点后可循环(Loop)或往返(PingPong)。
|
||||
/// 与 PathBerserker2d 集成:通过 IPathAgent.RequestMoveTo 导航,支持跨平台跳跃 NavLink。
|
||||
/// </summary>
|
||||
[TaskName("Patrol (Waypoints)")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("按预设路点顺序巡逻;支持 Transform 引用或内联 Vector2 坐标,可循环或折返")]
|
||||
public sealed class BD_PatrolWaypoints : Action
|
||||
{
|
||||
[Tooltip("路点列表(世界空间 Transform);与 m_InlineWaypoints 同时设置时此项优先")]
|
||||
[SerializeField] private Transform[] m_Waypoints;
|
||||
|
||||
[Tooltip("内联路点坐标(世界空间 Vector2);m_Waypoints 为空时使用;在 Scene 视图中以绿色 Gizmo 可视化")]
|
||||
[SerializeField] private Vector2[] m_InlineWaypoints;
|
||||
|
||||
[Tooltip("到达路点的判定半径(m)")]
|
||||
[SerializeField] private float m_ArriveRadius = 0.3f;
|
||||
|
||||
[Tooltip("true = 往返; false = 循环")]
|
||||
[SerializeField] private bool m_PingPong = false;
|
||||
|
||||
[Tooltip("每个路点到达后等待时长(s)")]
|
||||
[SerializeField] private float m_WaitAtWaypoint = 0f;
|
||||
|
||||
// 首次启动重试间隔:OnStart() 的第一次 RequestCurrent() 可能因 NavAgent 尚未完成
|
||||
// UpdateMappedPosition()(脚本执行顺序问题)而静默失败。此值只需大于一帧即可。
|
||||
private const float InitialRetryDelay = 0.05f;
|
||||
|
||||
// 正常巡逻中卡住的重试间隔:必须足够长,使任何在途 PB2d 路径请求
|
||||
// (Pending → Finished → HandlePathRequest 消费)都已处理完毕,避免竞争覆盖。
|
||||
private const float StuckRetryDelay = 0.5f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private int _index = 0;
|
||||
private int _dir = 1;
|
||||
private float _waitTimer = 0f;
|
||||
private bool _waiting = false;
|
||||
private float _stuckTimer = 0f;
|
||||
private bool _pathFailed = false;
|
||||
private bool _hasMoved = false; // 首次成功开始移动后置 true
|
||||
|
||||
// ── 统一路点访问 ────────────────────────────────────────────────────
|
||||
private int WaypointCount =>
|
||||
m_Waypoints != null && m_Waypoints.Length > 0
|
||||
? m_Waypoints.Length
|
||||
: m_InlineWaypoints?.Length ?? 0;
|
||||
|
||||
private Vector2 GetWaypoint(int index)
|
||||
{
|
||||
if (m_Waypoints != null && m_Waypoints.Length > 0)
|
||||
{
|
||||
var t = m_Waypoints[index];
|
||||
return t != null ? (Vector2)t.position : (Vector2)transform.position;
|
||||
}
|
||||
return m_InlineWaypoints != null && index < m_InlineWaypoints.Length
|
||||
? m_InlineWaypoints[index]
|
||||
: (Vector2)transform.position;
|
||||
}
|
||||
|
||||
// ── BD 生命周期 ─────────────────────────────────────────────────────
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
if (WaypointCount == 0) return;
|
||||
_waiting = false;
|
||||
_waitTimer = 0f;
|
||||
_stuckTimer = 0f;
|
||||
_pathFailed = false;
|
||||
_hasMoved = false;
|
||||
_enemy?.SetAiPhase(AiPhase.Patrol);
|
||||
|
||||
if (_enemy?.Nav != null)
|
||||
{
|
||||
_enemy.Nav.OnGoalReached += HandleGoalReached;
|
||||
_enemy.Nav.OnNavPathFailed += HandlePathFailed;
|
||||
}
|
||||
|
||||
RequestCurrent();
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || WaypointCount == 0)
|
||||
return TaskStatus.Failure;
|
||||
|
||||
if (_waiting)
|
||||
{
|
||||
_waitTimer -= Time.deltaTime;
|
||||
if (_waitTimer > 0f) return TaskStatus.Running;
|
||||
_waiting = false;
|
||||
Advance();
|
||||
RequestCurrent();
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
// 兜底重试:用时间门控避免与 PB2d 的 Finished-状态路径请求产生竞争。
|
||||
// 首次启动前(_hasMoved=false)使用短延迟,处理 NavAgent 位置映射尚未就绪的情况;
|
||||
// 正常巡逻中使用长延迟,确保在途路径请求已被 HandlePathRequest 消费完毕。
|
||||
if (_enemy.Nav != null)
|
||||
{
|
||||
if (!_enemy.Nav.IsMoving)
|
||||
{
|
||||
_stuckTimer += Time.deltaTime;
|
||||
float retryDelay = _hasMoved ? StuckRetryDelay : InitialRetryDelay;
|
||||
if (_stuckTimer >= retryDelay)
|
||||
{
|
||||
_stuckTimer = 0f;
|
||||
_pathFailed = false;
|
||||
RequestCurrent();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasMoved = true;
|
||||
_stuckTimer = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (_enemy?.Nav != null)
|
||||
{
|
||||
_enemy.Nav.OnGoalReached -= HandleGoalReached;
|
||||
_enemy.Nav.OnNavPathFailed -= HandlePathFailed;
|
||||
}
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
|
||||
// ── 内部辅助 ────────────────────────────────────────────────────────
|
||||
private void HandleGoalReached()
|
||||
{
|
||||
_hasMoved = true;
|
||||
_stuckTimer = 0f;
|
||||
_pathFailed = false;
|
||||
if (m_WaitAtWaypoint > 0f)
|
||||
{
|
||||
_waiting = true;
|
||||
_waitTimer = m_WaitAtWaypoint;
|
||||
_enemy?.StopMovement();
|
||||
}
|
||||
else
|
||||
{
|
||||
Advance();
|
||||
RequestCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
// 路径失败时不在回调中立即重试——此时 NavAgent.HandlePathRequest 尚未调用
|
||||
// currentPathRequest.Reset(),直接提交新请求会被随后的 Reset() 覆盖清除。
|
||||
// 改为设置标志,交由 OnUpdate 的计时兜底在下一帧安全重试。
|
||||
private void HandlePathFailed()
|
||||
{
|
||||
_pathFailed = true;
|
||||
_stuckTimer = 0f; // 重置计时器,使兜底在 StuckRetryDelay 后触发
|
||||
}
|
||||
|
||||
private void RequestCurrent()
|
||||
{
|
||||
if (WaypointCount == 0) return;
|
||||
_enemy.MoveTo(GetWaypoint(_index));
|
||||
}
|
||||
|
||||
private void Advance()
|
||||
{
|
||||
if (WaypointCount <= 1) return;
|
||||
if (m_PingPong)
|
||||
{
|
||||
_index += _dir;
|
||||
if (_index >= WaypointCount) { _index = WaypointCount - 2; _dir = -1; }
|
||||
else if (_index < 0) { _index = 1; _dir = 1; }
|
||||
}
|
||||
else
|
||||
{
|
||||
_index = (_index + 1) % WaypointCount;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Gizmo 可视化(仅 m_InlineWaypoints 模式)────────────────────────
|
||||
#if UNITY_EDITOR
|
||||
private new void OnDrawGizmos()
|
||||
{
|
||||
if (m_InlineWaypoints == null || m_InlineWaypoints.Length < 1) return;
|
||||
// m_Waypoints 存在时不绘制,避免与场景路点重叠
|
||||
if (m_Waypoints != null && m_Waypoints.Length > 0) return;
|
||||
|
||||
Gizmos.color = new Color(0.2f, 0.85f, 0.2f, 0.8f);
|
||||
for (int i = 0; i < m_InlineWaypoints.Length; i++)
|
||||
{
|
||||
Gizmos.DrawWireSphere(m_InlineWaypoints[i], m_ArriveRadius);
|
||||
|
||||
if (i < m_InlineWaypoints.Length - 1)
|
||||
Gizmos.DrawLine(m_InlineWaypoints[i], m_InlineWaypoints[i + 1]);
|
||||
}
|
||||
|
||||
// PingPong 时也画返回线;Loop 时画首尾连接线
|
||||
if (m_InlineWaypoints.Length >= 2)
|
||||
{
|
||||
if (m_PingPong)
|
||||
{
|
||||
// 往返:虚线效果(半透明线)
|
||||
Gizmos.color = new Color(0.2f, 0.85f, 0.2f, 0.35f);
|
||||
Gizmos.DrawLine(m_InlineWaypoints[m_InlineWaypoints.Length - 1], m_InlineWaypoints[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 循环:画首尾连接
|
||||
Gizmos.color = new Color(0.2f, 0.85f, 0.2f, 0.5f);
|
||||
Gizmos.DrawLine(m_InlineWaypoints[m_InlineWaypoints.Length - 1], m_InlineWaypoints[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑器标签(路点序号)
|
||||
UnityEditor.Handles.color = new Color(0.2f, 0.85f, 0.2f, 1f);
|
||||
for (int i = 0; i < m_InlineWaypoints.Length; i++)
|
||||
UnityEditor.Handles.Label(m_InlineWaypoints[i] + Vector2.up * 0.25f, $"WP{i}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7a2cb1e940ff92499a0ebb9d3063e21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,37 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:通过 AnimationClip 名称播放 Animancer 动画,立即返回 Success。
|
||||
/// ClipName 需与 EnemyAnimationConfigSO 中字段名一致。
|
||||
/// </summary>
|
||||
[TaskName("Play Animation")]
|
||||
[TaskCategory("BaseGames/Enemy/Animation")]
|
||||
[TaskDescription("通过 Animancer 播放指定动画 Clip;支持等待动画结束后返回")]
|
||||
public class BD_PlayAnimation : Action
|
||||
{
|
||||
/// <summary>EnemyAnimationConfigSO 中的 AnimationClip 字段名(如 "Attack_Melee")。</summary>
|
||||
[SerializeField] private string m_ClipName = "Idle";
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null || _enemy.AnimConfig == null) return TaskStatus.Failure;
|
||||
|
||||
var clip = _enemy.AnimConfig.GetClipByName(m_ClipName);
|
||||
if (clip != null)
|
||||
_enemy.Animancer?.Play(clip);
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3247bf3e6a748dc408bbf0d6ac7e1680
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,103 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:归位到出生点(<see cref="EnemyBase.HomePosition"/>)。
|
||||
///
|
||||
/// <list type="bullet">
|
||||
/// <item>切换 <see cref="AiPhase.ReturnHome"/>,使用行走速度导航回初始位置。</item>
|
||||
/// <item>到达(距离 ≤ homeRadius)或路径失败时:切换 <see cref="AiPhase.Idle"/>,返回 Success。</item>
|
||||
/// <item>路径失败也返回 Success,避免 BD 树卡死;上层节点继续恢复巡逻。</item>
|
||||
/// </list>
|
||||
///
|
||||
/// 典型 BD 用法:
|
||||
/// <code>
|
||||
/// Sequence
|
||||
/// BD_InvestigateLastKnown → Success
|
||||
/// BD_ReturnToHome → Success
|
||||
/// BD_SetAiPhase(Patrol)
|
||||
/// </code>
|
||||
/// </summary>
|
||||
[TaskName("Return To Home")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("导航回出生点;到达后切换 Idle 并返回 Success")]
|
||||
public sealed class BD_ReturnToHome : Action
|
||||
{
|
||||
[Tooltip("到达判定半径(m);0 = 使用 EnemyStatsSO.HomeRadius")]
|
||||
[SerializeField] private float m_ArriveRadius = 0f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private bool _reached;
|
||||
private bool _pathFailed;
|
||||
private bool _subscribed;
|
||||
private Vector2 _returnTarget;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_enemy.SetAiPhase(AiPhase.ReturnHome);
|
||||
_reached = false;
|
||||
_pathFailed = false;
|
||||
|
||||
if (!_subscribed && _enemy.Nav != null)
|
||||
{
|
||||
_enemy.Nav.OnGoalReached += HandleReached;
|
||||
_enemy.Nav.OnNavPathFailed += HandleFailed;
|
||||
_subscribed = true;
|
||||
}
|
||||
|
||||
// 切换为行走速度
|
||||
float walkSpeed = _enemy.Stats?.WalkSpeed ?? 2f;
|
||||
_enemy.Nav?.SetSpeed(walkSpeed);
|
||||
|
||||
// 优先归位到巡逻区域中心;无区域时退回出生点
|
||||
_returnTarget = _enemy.PatrolZone != null
|
||||
? _enemy.PatrolZone.PatrolCenter
|
||||
: _enemy.HomePosition;
|
||||
_enemy.MoveTo(_returnTarget);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
if (_pathFailed) return CompleteReturn();
|
||||
if (_reached) return CompleteReturn();
|
||||
|
||||
// 兜底距离判断(事件可能因帧序问题延迟一帧)
|
||||
float radius = m_ArriveRadius > 0f ? m_ArriveRadius : (_enemy.Stats?.HomeRadius ?? 0.5f);
|
||||
float sqr = ((Vector2)_enemy.transform.position - _returnTarget).sqrMagnitude;
|
||||
if (sqr <= radius * radius)
|
||||
return CompleteReturn();
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
if (_subscribed && _enemy?.Nav != null)
|
||||
{
|
||||
_enemy.Nav.OnGoalReached -= HandleReached;
|
||||
_enemy.Nav.OnNavPathFailed -= HandleFailed;
|
||||
}
|
||||
_subscribed = false;
|
||||
}
|
||||
|
||||
private TaskStatus CompleteReturn()
|
||||
{
|
||||
_enemy.StopMovement();
|
||||
_enemy.SetAiPhase(AiPhase.Idle);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
|
||||
private void HandleReached() => _reached = true;
|
||||
private void HandleFailed() => _pathFailed = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0555fce4edd236847b580a2b436bd22f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,34 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:设置 AI 行为阶段(<see cref="AiPhase"/>)。
|
||||
/// 单帧完成,返回 Success。常用于行为树中作为阶段过渡的标记节点,
|
||||
/// 例如在 Selector 分支开头标记当前进入了哪个阶段。
|
||||
/// </summary>
|
||||
[TaskName("Set Ai Phase")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("立即切换 AI 行为阶段(AiPhase),单帧返回 Success")]
|
||||
public sealed class BD_SetAiPhase : Action
|
||||
{
|
||||
[Tooltip("目标 AI 行为阶段")]
|
||||
[SerializeField] private AiPhase m_Phase = AiPhase.Idle;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
_enemy.SetAiPhase(m_Phase);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f70a0ea7dc70bb4cbf300d19eacfba0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,29 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:设置警觉状态,并通知 EnemyBase 调整 BT Tick 频率。
|
||||
/// </summary>
|
||||
[TaskName("Set Alert Tick Rate")]
|
||||
[TaskCategory("BaseGames/Enemy/Perception")]
|
||||
[TaskDescription("切换行为树 Tick 频率:警觉时高频,巡逻时低频")]
|
||||
public class BD_SetAlert : Action
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
_enemy.SetAggroTickRate(true);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f8deae75c691904192374ccab313a2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,45 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
using BaseGames.Enemies.Abilities;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:强制切换敌人到指定 EnemyStateType,并中断所有正在执行的能力。
|
||||
/// 单帧完成,立即返回 Success。
|
||||
///
|
||||
/// 典型用法:
|
||||
/// - 进入 Stagger 状态后重置为 Idle(替代手动停止动画)
|
||||
/// - 技能打断后显式回到 Controlled 状态
|
||||
/// </summary>
|
||||
[TaskName("Set State")]
|
||||
[TaskCategory("BaseGames/Enemy/State")]
|
||||
[TaskDescription("强制切换敌人物理/战斗状态(ForceState)")]
|
||||
public class BD_SetState : Action
|
||||
{
|
||||
[Tooltip("切换到的目标状态")]
|
||||
[SerializeField] private EnemyStateType m_TargetState = EnemyStateType.Controlled;
|
||||
|
||||
[Tooltip("切换状态时同时中断所有正在执行的能力")]
|
||||
[SerializeField] private bool m_InterruptAbilities = true;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
if (m_InterruptAbilities)
|
||||
_enemy.Abilities?.InterruptAll(InterruptReason.ExternalRequest);
|
||||
|
||||
_enemy.ForceState(m_TargetState);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3406f00433d44e449c24b4340b0c49a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,42 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Pool;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:在敌人当前位置生成弹射物。
|
||||
/// ProjectileKey 为 Addressable 键,通过 GlobalObjectPool 实例化。
|
||||
/// </summary>
|
||||
[TaskName("Spawn Projectile")]
|
||||
[TaskCategory("BaseGames/Enemy/Utility")]
|
||||
[TaskDescription("在指定位置生成投射物并赋予初速度")]
|
||||
public class BD_SpawnProjectile : Action
|
||||
{
|
||||
[SerializeField] private Vector2 m_Direction = Vector2.right;
|
||||
[SerializeField] private string m_ProjectileKey = "";
|
||||
[SerializeField] private float m_Speed = 8f;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (string.IsNullOrEmpty(m_ProjectileKey)) return TaskStatus.Failure;
|
||||
|
||||
var pool = ServiceLocator.GetOrDefault<IObjectPoolService>();
|
||||
if (pool == null) return TaskStatus.Failure;
|
||||
|
||||
var go = pool.Spawn(m_ProjectileKey, transform.position, Quaternion.identity);
|
||||
if (go != null)
|
||||
{
|
||||
var rb = go.GetComponent<Rigidbody2D>();
|
||||
if (rb != null)
|
||||
rb.velocity = m_Direction.normalized * m_Speed;
|
||||
}
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85547509455668b43971ceccfd36d609
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,28 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:立即停止移动,单帧完成,返回 Success。
|
||||
/// </summary>
|
||||
[TaskName("Stop Movement")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("立即停止 NavAgent 移动,单帧返回 Success")]
|
||||
public class BD_StopMovement : Action
|
||||
{
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
_enemy.StopMovement();
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ff201baacc362345a79874bc2a56b74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Pool;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:Boss 专用召唤小兵。
|
||||
/// 通过 GlobalObjectPool 在 Boss 周围生成 MinionPrefabKey 对应的敌人。
|
||||
/// </summary>
|
||||
[TaskName("Summon Minions")]
|
||||
[TaskCategory("BaseGames/Enemy/Boss")]
|
||||
[TaskDescription("在指定位置生成小怪预制体(支持延迟和数量配置)")]
|
||||
public class BD_SummonMinions : Action
|
||||
{
|
||||
[Header("召唤配置")]
|
||||
[Tooltip("对象池 Key,对应 PoolRegistry 中注册的小怪预制体。")]
|
||||
[SerializeField] private string m_MinionPrefabKey = "";
|
||||
[Tooltip("单次召唤的小兵数量。")]
|
||||
[Min(1)]
|
||||
[SerializeField] private int m_Count = 2;
|
||||
[Tooltip("小兵生成位置距 Boss 中心的横向散开半径(m)。")]
|
||||
[Min(0.1f)]
|
||||
[SerializeField] private float m_SpawnRadius = 3f;
|
||||
|
||||
// 延迟缓存:首次调用时解析,避免每帧服务定位开销
|
||||
private IObjectPoolService _pool;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (string.IsNullOrEmpty(m_MinionPrefabKey)) return TaskStatus.Failure;
|
||||
|
||||
_pool ??= ServiceLocator.GetOrDefault<IObjectPoolService>();
|
||||
if (_pool == null) return TaskStatus.Failure;
|
||||
|
||||
for (int i = 0; i < m_Count; i++)
|
||||
{
|
||||
float angleRad = (i / (float)m_Count) * Mathf.PI * 2f;
|
||||
var offset = new Vector2(Mathf.Cos(angleRad), 0f) * m_SpawnRadius;
|
||||
var spawnPos = new Vector3(
|
||||
transform.position.x + offset.x,
|
||||
transform.position.y,
|
||||
0f);
|
||||
_pool.Spawn(m_MinionPrefabKey, spawnPos, Quaternion.identity);
|
||||
}
|
||||
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fe673f758db6ef4c81938d19b7a4fde
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,56 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies.Boss.Patterns;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:触发攻击预警(TelegraphSystem),等待 Duration 秒后返回 Success。
|
||||
/// 对应架构 07_EnemyModule §8 BD_TelegraphAttack;与 TelegraphSystem 协作。
|
||||
/// </summary>
|
||||
[TaskName("Telegraph Attack")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("播放攻击前摇动画并等待结束后返回 Success")]
|
||||
public class BD_TelegraphAttack : Action
|
||||
{
|
||||
[SerializeField] private float m_Duration = 1f;
|
||||
[SerializeField] private string m_VfxKey = "";
|
||||
|
||||
private TelegraphSystem _telegraph;
|
||||
private float _elapsed;
|
||||
private Coroutine _telegraphCoroutine;
|
||||
|
||||
public override void OnAwake() => _telegraph = GetComponent<TelegraphSystem>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_elapsed = 0f;
|
||||
_telegraphCoroutine = null;
|
||||
|
||||
if (_telegraph != null && !string.IsNullOrEmpty(m_VfxKey))
|
||||
{
|
||||
_telegraphCoroutine = _telegraph.StartCoroutine(
|
||||
_telegraph.ShowTelegraph(m_VfxKey, m_Duration, transform.position));
|
||||
}
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
_elapsed += Time.deltaTime;
|
||||
return _elapsed >= m_Duration ? TaskStatus.Success : TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
// BD 任务被 Abort 时停止仍在播放的预警协程,避免孤立 VFX
|
||||
if (_telegraphCoroutine != null)
|
||||
{
|
||||
_telegraph?.StopCoroutine(_telegraphCoroutine);
|
||||
_telegraphCoroutine = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbc61c8ed12b2bb4b9c50b6aa1046576
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,26 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:瞬移(传送)到目标坐标,Boss 专用。
|
||||
/// 单帧直接修改 transform.position,不使用导航。
|
||||
/// </summary>
|
||||
[TaskName("Teleport To")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("瞬移到目标位置(配合粒子/闪烁能力)")]
|
||||
public class BD_TeleportTo : Action
|
||||
{
|
||||
[SerializeField] private Vector2 m_Target;
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
transform.position = new Vector3(m_Target.x, m_Target.y, transform.position.z);
|
||||
return TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9d4cc838f773cd44ad029c86f722906
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,58 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies.Abilities;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用:触发能力。OnStart 调用 ability.Execute(),OnUpdate 等待结束。
|
||||
/// 失败条件:能力不存在、能力 CanUse=false 或 Execute 返回 false。
|
||||
/// </summary>
|
||||
[TaskName("Use Ability")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("触发指定能力(拖拽 EnemyAbilitySO 或填写 ID),等待执行结束")]
|
||||
public sealed class BD_UseAbility : Action
|
||||
{
|
||||
[Tooltip("可直接拖拽 EnemyAbilitySO 资产(推荐),或填写裸字符串 ID 作为兜底")]
|
||||
[SerializeField] private EnemyAbilitySO m_AbilitySO;
|
||||
[SerializeField] private string m_AbilityId = "";
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private EnemyAbilityBase _ability;
|
||||
private bool _startedSuccessfully;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
_enemy = gameObject.GetComponent<EnemyBase>();
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_startedSuccessfully = false;
|
||||
if (_enemy == null) return;
|
||||
|
||||
// SO 拖拽优先;裸字符串兜底
|
||||
string id = m_AbilitySO != null ? m_AbilitySO.abilityId : m_AbilityId;
|
||||
if (string.IsNullOrEmpty(id)) return;
|
||||
|
||||
_ability = _enemy.Abilities.Get(id);
|
||||
if (_ability == null) return;
|
||||
_startedSuccessfully = _ability.Execute();
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (!_startedSuccessfully || _ability == null) return TaskStatus.Failure;
|
||||
return _ability.IsRunning ? TaskStatus.Running : TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
_ability = null;
|
||||
_startedSuccessfully = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4865a86627f84a54292736e6dc2b9e15
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,53 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Boss;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 触发 Boss 技能。OnStart 调用 BossBase.UseBossSkill(skillId),OnUpdate 等待技能结束。
|
||||
/// 失败条件:非 Boss 敌人、技能 ID 无效、BossSkillExecutor 未就绪或技能执行中。
|
||||
/// </summary>
|
||||
[TaskName("Use Boss Skill")]
|
||||
[TaskCategory("BaseGames/Enemy/Boss")]
|
||||
[TaskDescription("通过技能 ID 执行 Boss 指定技能")]
|
||||
public sealed class BD_UseBossSkill : Action
|
||||
{
|
||||
[SerializeField] private string m_SkillId = "";
|
||||
[Tooltip("可选:直接拖拽 BossSkillSO 资产以替代裸字符串(优先于 m_SkillId)")]
|
||||
[SerializeField] private BossSkillSO m_SkillSO;
|
||||
|
||||
private BossBase _boss;
|
||||
private bool _startedSuccessfully;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
_boss = gameObject.GetComponent<BossBase>();
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_startedSuccessfully = false;
|
||||
if (_boss == null) return;
|
||||
|
||||
string id = m_SkillSO != null ? m_SkillSO.skillId : m_SkillId;
|
||||
if (string.IsNullOrEmpty(id)) return;
|
||||
|
||||
_startedSuccessfully = _boss.UseBossSkill(id);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (!_startedSuccessfully || _boss == null) return TaskStatus.Failure;
|
||||
return _boss.IsBossSkillExecuting ? TaskStatus.Running : TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnEnd()
|
||||
{
|
||||
_startedSuccessfully = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f86542f8dede80438ab28ec682758b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,54 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:在当前阶段可用且冷却就绪的技能中,按 weight 加权随机选择一个技能并执行。
|
||||
///
|
||||
/// 返回 Running:技能正在执行。
|
||||
/// 返回 Success:技能执行完成。
|
||||
/// 返回 Failure:无可用技能,或执行器忙。
|
||||
///
|
||||
/// 用法:在 Boss BT 的 Combat 阶段,替代 BD_UseBossSkill(固定 ID)实现随机化技能组合。
|
||||
/// 每个 BossSkillSO 设置 weight 字段控制出现概率:越大越常见。
|
||||
/// </summary>
|
||||
[TaskName("Use Boss Skill (Weighted)")]
|
||||
[TaskCategory("BaseGames/Enemy/Boss")]
|
||||
[TaskDescription("加权随机选择并执行可用技能;对上一次使用的技能施加权重惩罚")]
|
||||
public class BD_UseBossSkillWeighted : Action
|
||||
{
|
||||
[Tooltip("等待技能执行完成后才返回 Success。关闭后执行开始即返回 Success,BT 继续运行其他节点。")]
|
||||
[SerializeField] private bool m_WaitForCompletion = true;
|
||||
|
||||
private BossBase _boss;
|
||||
private bool _started;
|
||||
|
||||
public override void OnAwake() => _boss = GetComponent<BossBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_started = false;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_boss == null) return TaskStatus.Failure;
|
||||
|
||||
if (!_started)
|
||||
{
|
||||
bool ok = _boss.UseBossSkillWeighted();
|
||||
if (!ok) return TaskStatus.Failure;
|
||||
_started = true;
|
||||
|
||||
if (!m_WaitForCompletion) return TaskStatus.Success;
|
||||
}
|
||||
|
||||
// 等待技能执行完成
|
||||
return _boss.IsBossSkillExecuting ? TaskStatus.Running : TaskStatus.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cf18a1d81f80c646947ea0475c31108
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,33 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:等待固定 Duration 秒后返回 Success。
|
||||
/// 适用于攻击前摇、冷却间隔等固定等待。
|
||||
/// </summary>
|
||||
[TaskName("Wait")]
|
||||
[TaskCategory("BaseGames/Enemy/Utility")]
|
||||
[TaskDescription("等待固定 Duration 秒后返回 Success")]
|
||||
public class BD_Wait : Action
|
||||
{
|
||||
[UnityEngine.SerializeField] private float m_Duration = 1f;
|
||||
|
||||
private float _elapsed;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_elapsed = 0f;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
_elapsed += Time.deltaTime;
|
||||
return _elapsed >= m_Duration ? TaskStatus.Success : TaskStatus.Running;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a145269c2d2c3094994ff16e72ba4d68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,48 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:等待当前 Animancer 动画播放完毕再返回 Success。
|
||||
/// 通过 Animancer CurrentState.NormalizedTime >= 1 轮询;
|
||||
/// 若动画为循环动画(NormalizedTime 每帧 wrap 到 0),超时后强制返回 Success,防止永久挂死。
|
||||
/// </summary>
|
||||
[TaskName("Wait For Animation")]
|
||||
[TaskCategory("BaseGames/Enemy/Animation")]
|
||||
[TaskDescription("等待 Animancer 当前动画播放完毕后返回 Success。循环动画请设置超时时间。")]
|
||||
public class BD_WaitForAnimation : Action
|
||||
{
|
||||
[Tooltip("安全超时(秒)。若动画是循环型,超时后自动返回 Success。0 = 不启用超时(仅适合非循环动画)。")]
|
||||
[SerializeField, Min(0f)] private float m_Timeout = 5f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private float _deadline;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_deadline = m_Timeout > 0f ? Time.time + m_Timeout : float.MaxValue;
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
|
||||
// 超时保护:防止循环动画导致永久阻塞
|
||||
if (Time.time >= _deadline) return TaskStatus.Success;
|
||||
|
||||
var state = _enemy.Animancer?.States?.Current;
|
||||
if (state == null) return TaskStatus.Success; // 无动画直接继续
|
||||
if (state.NormalizedTime >= 1f) return TaskStatus.Success;
|
||||
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 437d55b7c77973b4c8a80b688ab153d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,36 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:在 [Min, Max] 范围内随机等待后返回 Success。
|
||||
/// 适用于巡逻间隔、随机攻击延迟等自然行为。
|
||||
/// </summary>
|
||||
[TaskName("Wait (Random)")]
|
||||
[TaskCategory("BaseGames/Enemy/Utility")]
|
||||
[TaskDescription("在 Min~Max 范围内随机等待后返回 Success")]
|
||||
public class BD_WaitRandom : Action
|
||||
{
|
||||
[UnityEngine.SerializeField] private float m_Min = 0.5f;
|
||||
[UnityEngine.SerializeField] private float m_Max = 2.0f;
|
||||
|
||||
private float _elapsed;
|
||||
private float _target;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_elapsed = 0f;
|
||||
_target = Random.Range(m_Min, m_Max);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
_elapsed += Time.deltaTime;
|
||||
return _elapsed >= _target ? TaskStatus.Success : TaskStatus.Running;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15e39022725082a44a41a79a7a655814
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,68 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
using BaseGames.Enemies.Abilities;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// BD Action:等待指定能力执行结束后返回 Success。
|
||||
/// 适用于需要同步等待某个由外部触发的能力(而非本节点触发)的场景。
|
||||
///
|
||||
/// 返回 Running:能力正在执行。
|
||||
/// 返回 Success:能力执行完毕(IsRunning = false)。
|
||||
/// 返回 Failure:能力不存在,或超时保护触发。
|
||||
///
|
||||
/// 典型用法:Sequence [ BD_UseAbility(A) → BD_WaitUntilAbilityEnd(B) ] 等待 B 被 A 内部链式触发后结束。
|
||||
/// </summary>
|
||||
[TaskName("Wait Until Ability End")]
|
||||
[TaskCategory("BaseGames/Enemy/Combat")]
|
||||
[TaskDescription("等待指定能力执行完成后返回 Success")]
|
||||
public sealed class BD_WaitUntilAbilityEnd : Action
|
||||
{
|
||||
[Tooltip("可直接拖拽 EnemyAbilitySO 资产(推荐),或填写裸字符串 ID 作为兜底")]
|
||||
[SerializeField] private EnemyAbilitySO m_AbilitySO;
|
||||
[SerializeField] private string m_AbilityId = "";
|
||||
|
||||
[Tooltip("超时保护(秒);0 = 永不超时")]
|
||||
[SerializeField, Min(0f)] private float m_Timeout = 5f;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
private EnemyAbilityBase _ability;
|
||||
private float _deadline;
|
||||
|
||||
public override void OnAwake() => _enemy = GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_ability = null;
|
||||
_deadline = m_Timeout > 0f ? Time.time + m_Timeout : float.MaxValue;
|
||||
|
||||
if (_enemy == null) return;
|
||||
string id = m_AbilitySO != null ? m_AbilitySO.abilityId : m_AbilityId;
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
_ability = _enemy.Abilities?.Get(id);
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_ability == null) return TaskStatus.Failure;
|
||||
|
||||
if (Time.time >= _deadline)
|
||||
{
|
||||
Debug.LogWarning($"[BD_WaitUntilAbilityEnd] 能力 '{_ability.Config?.abilityId}' 超时,强制中断", gameObject);
|
||||
// 强制中断仍在运行的能力,防止 HitBox/动画协程泄漏
|
||||
if (_ability.IsRunning)
|
||||
_ability.Interrupt(InterruptReason.ExternalRequest);
|
||||
return TaskStatus.Failure;
|
||||
}
|
||||
|
||||
return _ability.IsRunning ? TaskStatus.Running : TaskStatus.Success;
|
||||
}
|
||||
|
||||
public override void OnEnd() => _ability = null;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9311a809097042f4b8b5de9681d51d0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,48 +0,0 @@
|
||||
#if GRAPH_DESIGNER
|
||||
using UnityEngine;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
||||
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
|
||||
using BaseGames.Enemies;
|
||||
|
||||
namespace BaseGames.Enemies.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 动作:随机游走(调用 NavAgent.SetRandomDestination)。
|
||||
/// 到达目的地后立即选下一个随机点,持续 Running。
|
||||
/// 常用于巡逻 fallback 或无路点的小怪。
|
||||
/// </summary>
|
||||
[TaskName("Walk Random")]
|
||||
[TaskCategory("BaseGames/Enemy/Movement")]
|
||||
[TaskDescription("随机游走:持续选取随机目的地导航(常用于待机巡逻兜底)")]
|
||||
public sealed class BD_WalkRandom : Action
|
||||
{
|
||||
[Tooltip("尝试选取随机点的次数")]
|
||||
[SerializeField] private int m_RetryCount = 5;
|
||||
|
||||
private EnemyBase _enemy;
|
||||
|
||||
public override void OnAwake() => _enemy = gameObject.GetComponent<EnemyBase>();
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_enemy.SetAiPhase(AiPhase.Patrol);
|
||||
TryWalk();
|
||||
}
|
||||
|
||||
public override TaskStatus OnUpdate()
|
||||
{
|
||||
if (_enemy == null) return TaskStatus.Failure;
|
||||
if (_enemy.Nav?.IsAtDestination() ?? true) TryWalk();
|
||||
return TaskStatus.Running;
|
||||
}
|
||||
|
||||
public override void OnEnd() => _enemy?.StopMovement();
|
||||
|
||||
private void TryWalk()
|
||||
{
|
||||
for (int i = 0; i < m_RetryCount; i++)
|
||||
if (_enemy.Nav?.WalkToRandom() ?? false) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user