- Enhanced Physics2D layer collision report with new interactions between Player and Enemy layers. - Refactored BD_InvestigateLastKnown to streamline animation handling and improve readability. - Simplified BD_MaintainCombatDistance by consolidating movement stop logic. - Updated BD_MoveToPlayer to set AI phase on start. - Improved BD_Patrol logic with better handling of stuck states and path failures. - Enhanced BD_PatrolWaypoints to manage stuck conditions and retry logic more effectively. - Refined BD_ReturnToHome to remove unnecessary animation calls. - Updated BD_WalkRandom to ensure AI phase is set correctly on start. - Improved EnemyAbilityBase to delegate target facing to the movement system. - Enhanced EnemyBase with new movement methods for better control. - Refactored EnemyMovement to introduce a new input system for handling movement and facing. - Added EnemyMoveInput struct to encapsulate movement intentions. - Updated Physics2DSettings to reflect new layer collision matrix. - Introduced RTK CLI instructions for optimized command usage.
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
#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
|