AI 决策层(E001CaoZhiAi + PerceptionStateMachine)彻底移除所有 actuation: 不再有 Mover.Stop/FacePlayer/UseChaseSpeed/WalkRandom、也不再 SetPhase。 每个 AI 状态只声明触发哪个能力 id,行为(移动/朝向/停/速度/动画/伤害/ 阶段声明)全部下沉到对应能力里。 - 新增 IdleAbility/PatrolAbility/AlertAbility:待机静止、巡逻游走、 警觉朝向玩家,各自 SetAiPhase 驱动阶段动画。 - ContactChaseAbility 追击进入时自设 RunSpeed + Chase 阶段(原在 AI)。 - PerceptionStateMachine 改为 AddAbilityState:进入/每帧 EnsureAbility (被打断/受击后自动重触发)、离开 InterruptAbilities;转换规则不变。 - IEnemyActor/EnemyBrainContext 移除已无用的 SetPhase,保留 HasAlertState。 - 新增 SO:ABL_E001_Idle(e001_idle)、ABL_E001_Patrol(e001_patrol)。 - 脚手架 PlaceE001 与 ENM_CaoZhi 预制体同步为四能力结构;TestRoomA 实例替换为规范预制体实例。 PlayMode 验证:Chase→ContactChaseAbility、脱离感知→Move_Patrol→ PatrolAbility,阶段由能力设置,无报错。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using System.Collections;
|
|
using Animancer;
|
|
using UnityEngine;
|
|
|
|
namespace BaseGames.Enemies.Abilities
|
|
{
|
|
/// <summary>
|
|
/// 循环追击 + 体接触伤害能力(纯执行器)。
|
|
/// 每帧 MoveTo 追向玩家、开接触伤害;**何时停止由 AI 决策层负责**——AI 在"脱离视野"时
|
|
/// 中断本能力(AI decides when to stop, ability implements the chase)。
|
|
/// 可复用于任何需要"追击+接触伤害循环"的敌人。
|
|
/// </summary>
|
|
public class ContactChaseAbility : EnemyAbilityBase
|
|
{
|
|
[Header("动画")]
|
|
[SerializeField] private ClipTransition _loopClip;
|
|
[SerializeField] private ClipTransition _endClip;
|
|
|
|
[Header("接触伤害")]
|
|
[SerializeField] private BodyContactDamage _contactDamage;
|
|
|
|
protected override IEnumerator ExecuteCoroutine()
|
|
{
|
|
Phase = AbilityRunState.Active;
|
|
|
|
// 追击行为的速度/阶段声明归本能力(AI 只触发能力,不做这些执行)
|
|
if (_enemy.Nav != null && _enemy.Stats != null)
|
|
_enemy.Nav.SetSpeed(_enemy.Stats.RunSpeed);
|
|
_enemy.SetAiPhase(AiPhase.Chase);
|
|
|
|
if (_loopClip.Clip != null)
|
|
_animancer.Play(_loopClip);
|
|
|
|
if (_contactDamage != null)
|
|
_contactDamage.enabled = true;
|
|
|
|
// 追击直到玩家消失或被 AI 中断(退出追击的决策归 AI,见 EnemyBrainContext.InterruptAbilities)。
|
|
// 小怪走 nav 寻路(EnemyBase.MoveTo → 导航),寻路正确性依赖脚手架把碰撞体底部对齐 y=0。
|
|
while (_enemy.PlayerTransform != null)
|
|
{
|
|
_enemy.MoveTo(_enemy.PlayerTransform.position);
|
|
yield return null;
|
|
}
|
|
|
|
CleanupChase();
|
|
|
|
if (_endClip.Clip != null)
|
|
{
|
|
_animancer.Play(_endClip);
|
|
yield return EnemyAbilityWaits.Get(_endClip.Clip.length);
|
|
}
|
|
}
|
|
|
|
protected override void OnInterrupted(InterruptReason reason) => CleanupChase();
|
|
|
|
private void CleanupChase()
|
|
{
|
|
if (_contactDamage != null)
|
|
_contactDamage.enabled = false;
|
|
_enemy.StopMovement();
|
|
}
|
|
}
|
|
}
|