refactor(ai): Chase 走 Locomotion.Approach;删除 Idle/Patrol/Alert 协程能力与 SO
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
%YAML 1.1
|
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
|
||||||
--- !u!114 &11400000
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 0}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 9050afa76362dff469c64fbb48c9ff8d, type: 3}
|
|
||||||
m_Name: ABL_E001_Alert
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
abilityId: e001_alert
|
|
||||||
attackSequence: []
|
|
||||||
cooldown: 0
|
|
||||||
telegraphVfxKey:
|
|
||||||
telegraphDuration: 0
|
|
||||||
interruptOnHurt: 1
|
|
||||||
interruptOnStagger: 1
|
|
||||||
preferredMinRange: 0
|
|
||||||
preferredMaxRange: 5
|
|
||||||
requiresLineOfSight: 1
|
|
||||||
requiresGrounded: 1
|
|
||||||
exclusionGroup:
|
|
||||||
priority: 0
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 157dc45e6b444c64ea1a80a5886a8b92
|
|
||||||
NativeFormatImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
mainObjectFileID: 11400000
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
%YAML 1.1
|
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
|
||||||
--- !u!114 &11400000
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 0}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 9050afa76362dff469c64fbb48c9ff8d, type: 3}
|
|
||||||
m_Name: ABL_E001_Idle
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
abilityId: e001_idle
|
|
||||||
attackSequence: []
|
|
||||||
cooldown: 0
|
|
||||||
telegraphVfxKey:
|
|
||||||
telegraphDuration: 0
|
|
||||||
interruptOnHurt: 1
|
|
||||||
interruptOnStagger: 1
|
|
||||||
preferredMinRange: 0
|
|
||||||
preferredMaxRange: 5
|
|
||||||
requiresLineOfSight: 0
|
|
||||||
requiresGrounded: 1
|
|
||||||
exclusionGroup:
|
|
||||||
priority: 0
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 39972ac36f68c5a40a696350ee5b45ef
|
|
||||||
NativeFormatImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
mainObjectFileID: 11400000
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
%YAML 1.1
|
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
|
||||||
--- !u!114 &11400000
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 0}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 9050afa76362dff469c64fbb48c9ff8d, type: 3}
|
|
||||||
m_Name: ABL_E001_Patrol
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
abilityId: e001_patrol
|
|
||||||
attackSequence: []
|
|
||||||
cooldown: 0
|
|
||||||
telegraphVfxKey:
|
|
||||||
telegraphDuration: 0
|
|
||||||
interruptOnHurt: 1
|
|
||||||
interruptOnStagger: 1
|
|
||||||
preferredMinRange: 0
|
|
||||||
preferredMaxRange: 5
|
|
||||||
requiresLineOfSight: 0
|
|
||||||
requiresGrounded: 1
|
|
||||||
exclusionGroup:
|
|
||||||
priority: 0
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: ea84fa0bad3eb9c44841fbe355923cbd
|
|
||||||
NativeFormatImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
mainObjectFileID: 11400000
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -488,14 +488,8 @@ namespace BaseGames.Editor
|
|||||||
BodyContactDamage bodyContact = GetOrAddComponent<BodyContactDamage>(contactT.gameObject);
|
BodyContactDamage bodyContact = GetOrAddComponent<BodyContactDamage>(contactT.gameObject);
|
||||||
bodyContact.enabled = false; // 伪装/待机期不伤人;由 e001_chase 能力在追击期开启
|
bodyContact.enabled = false; // 伪装/待机期不伤人;由 e001_chase 能力在追击期开启
|
||||||
|
|
||||||
// Model A:每个 AI 状态 = 一个行为能力(AI 只决策触发哪个 id,行为在能力里实现)
|
// Model A:AI 只决策触发哪个能力(Idle/Patrol/Alert 已改为纯移动意图,由 EnemyLocomotion 执行,无需挂能力组件)
|
||||||
Transform abilitiesT = GetOrCreateChild(go.transform, "Abilities");
|
Transform abilitiesT = GetOrCreateChild(go.transform, "Abilities");
|
||||||
Transform idleT = GetOrCreateChild(abilitiesT, "IdleAbility_Idle");
|
|
||||||
IdleAbility idleAbility = GetOrAddComponent<IdleAbility>(idleT.gameObject);
|
|
||||||
Transform patrolT = GetOrCreateChild(abilitiesT, "PatrolAbility_Patrol");
|
|
||||||
PatrolAbility patrolAbility = GetOrAddComponent<PatrolAbility>(patrolT.gameObject);
|
|
||||||
Transform alertT = GetOrCreateChild(abilitiesT, "AlertAbility_Alert");
|
|
||||||
AlertAbility alertAbility = GetOrAddComponent<AlertAbility>(alertT.gameObject);
|
|
||||||
Transform chaseT = GetOrCreateChild(abilitiesT, "ContactChaseAbility_Chase");
|
Transform chaseT = GetOrCreateChild(abilitiesT, "ContactChaseAbility_Chase");
|
||||||
ContactChaseAbility chaseAbility = GetOrAddComponent<ContactChaseAbility>(chaseT.gameObject);
|
ContactChaseAbility chaseAbility = GetOrAddComponent<ContactChaseAbility>(chaseT.gameObject);
|
||||||
|
|
||||||
@@ -523,9 +517,6 @@ namespace BaseGames.Editor
|
|||||||
new[] { "Platform", "OneWayPlatform", "MovingOneWayPlatform", "MidHeightOneWayPlatform" },
|
new[] { "Platform", "OneWayPlatform", "MovingOneWayPlatform", "MidHeightOneWayPlatform" },
|
||||||
report);
|
report);
|
||||||
|
|
||||||
AssignAsset(idleAbility, "_config", report, false, "ABL_E001_Idle");
|
|
||||||
AssignAsset(patrolAbility, "_config", report, false, "ABL_E001_Patrol");
|
|
||||||
AssignAsset(alertAbility, "_config", report, false, "ABL_E001_Alert");
|
|
||||||
AssignAsset(chaseAbility, "_config", report, false, "ABL_E001_Chase");
|
AssignAsset(chaseAbility, "_config", report, false, "ABL_E001_Chase");
|
||||||
AssignReference(chaseAbility, "_contactDamage", bodyContact, report);
|
AssignReference(chaseAbility, "_contactDamage", bodyContact, report);
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using Animancer;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace BaseGames.Enemies.Abilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 警觉行为能力:停下 + 朝向玩家 + Alert 阶段(播警觉动画/feedback)。持续朝向玩家直到被打断。
|
|
||||||
/// "警觉态朝向角色"等行为归本能力,AI 只在进入警觉状态时触发。
|
|
||||||
/// </summary>
|
|
||||||
public class AlertAbility : EnemyAbilityBase
|
|
||||||
{
|
|
||||||
[Header("警觉动画(可选,留空则用 AnimConfig.Alert 阶段动画)")]
|
|
||||||
[SerializeField] private ClipTransition _alertClip;
|
|
||||||
|
|
||||||
protected override IEnumerator ExecuteCoroutine()
|
|
||||||
{
|
|
||||||
Phase = AbilityRunState.Active;
|
|
||||||
_enemy.SetAiPhase(AiPhase.Alert); // 阶段动画 + 广播(供群体警戒等)
|
|
||||||
if (_alertClip.Clip != null)
|
|
||||||
_animancer.Play(_alertClip);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
_enemy.StopMovement(); // 保持静止
|
|
||||||
if (_enemy.PlayerTransform != null)
|
|
||||||
_enemy.FaceTarget(_enemy.PlayerTransform.position); // 朝向玩家
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c51a5a3300c5d2549b3f8826d8c54fa8
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -36,11 +36,9 @@ namespace BaseGames.Enemies.Abilities
|
|||||||
|
|
||||||
// 追击直到玩家消失或被 AI 中断(退出追击的决策归 AI,见 EnemyBrainContext.InterruptAbilities)。
|
// 追击直到玩家消失或被 AI 中断(退出追击的决策归 AI,见 EnemyBrainContext.InterruptAbilities)。
|
||||||
// 小怪走 nav 寻路(EnemyBase.MoveTo → 导航),寻路正确性依赖脚手架把碰撞体底部对齐 y=0。
|
// 小怪走 nav 寻路(EnemyBase.MoveTo → 导航),寻路正确性依赖脚手架把碰撞体底部对齐 y=0。
|
||||||
|
_enemy.Locomotion?.Approach(_enemy.PlayerTransform);
|
||||||
while (_enemy.PlayerTransform != null)
|
while (_enemy.PlayerTransform != null)
|
||||||
{
|
|
||||||
_enemy.MoveTo(_enemy.PlayerTransform.position);
|
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
|
||||||
|
|
||||||
CleanupChase();
|
CleanupChase();
|
||||||
|
|
||||||
@@ -57,7 +55,7 @@ namespace BaseGames.Enemies.Abilities
|
|||||||
{
|
{
|
||||||
if (_contactDamage != null)
|
if (_contactDamage != null)
|
||||||
_contactDamage.enabled = false;
|
_contactDamage.enabled = false;
|
||||||
_enemy.StopMovement();
|
_enemy.Locomotion?.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace BaseGames.Enemies.Abilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 待机行为能力:停下 + 声明 Idle 阶段(播 Idle/伪装动画)。保持到被 AI 切换状态时打断。
|
|
||||||
/// 由 AI 决策层在进入待机状态时触发(AI 只决策,行为在此实现)。
|
|
||||||
/// </summary>
|
|
||||||
public class IdleAbility : EnemyAbilityBase
|
|
||||||
{
|
|
||||||
protected override IEnumerator ExecuteCoroutine()
|
|
||||||
{
|
|
||||||
Phase = AbilityRunState.Active;
|
|
||||||
_enemy.StopMovement();
|
|
||||||
_enemy.SetAiPhase(AiPhase.Idle);
|
|
||||||
while (true) // 保持待机(占用运行态)直到被打断
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 599faa708ea4a0f4b96ca9a3691523d7
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace BaseGames.Enemies.Abilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 巡逻行为能力:巡逻速度 + Patrol 阶段(播 Walk 动画) + 经导航随机游走。保持到被打断。
|
|
||||||
/// 移动执行归本能力,AI 只在进入巡逻状态时触发。
|
|
||||||
/// </summary>
|
|
||||||
public class PatrolAbility : EnemyAbilityBase
|
|
||||||
{
|
|
||||||
protected override IEnumerator ExecuteCoroutine()
|
|
||||||
{
|
|
||||||
Phase = AbilityRunState.Active;
|
|
||||||
_enemy.SetAiPhase(AiPhase.Patrol);
|
|
||||||
var nav = _enemy.Nav;
|
|
||||||
if (nav != null && _enemy.Stats != null)
|
|
||||||
nav.SetSpeed(_enemy.Stats.WalkSpeed);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (nav != null && !nav.IsMoving)
|
|
||||||
nav.WalkToRandom(); // 到达后再选一个随机可达点,持续游走
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnInterrupted(InterruptReason reason)
|
|
||||||
{
|
|
||||||
_enemy.Nav?.StopNavigation(); // 退出巡逻时清除残留游走目标
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 36ef5fe655e471c448e7c1300355888b
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Reference in New Issue
Block a user