54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using UnityEngine;
|
||
using PathBerserker2d;
|
||
using BaseGames.Enemies;
|
||
|
||
namespace BaseGames.Enemies.Navigation
|
||
{
|
||
/// <summary>
|
||
/// PathBerserker2d 导航代理包装器(架构 07_EnemyModule §5)。
|
||
/// 实现 IPathAgent 接口,使 EnemyBase 和 BD Task 无需直接依赖 PB2d 类型。
|
||
/// PB2d API:UpdatePath(Vector2)、Stop()、TransformBasedMovement.movementSpeed、IsFollowingAPath。
|
||
/// </summary>
|
||
[RequireComponent(typeof(NavAgent))]
|
||
[RequireComponent(typeof(TransformBasedMovement))]
|
||
public class EnemyNavAgent : MonoBehaviour, IPathAgent
|
||
{
|
||
private NavAgent _navAgent;
|
||
private TransformBasedMovement _movement;
|
||
|
||
/// <summary>正在沿路径移动时为 true。</summary>
|
||
public bool IsMoving => _navAgent != null && _navAgent.IsFollowingAPath;
|
||
|
||
public event System.Action OnNavPathFailed;
|
||
|
||
private void Awake()
|
||
{
|
||
_navAgent = GetComponent<NavAgent>();
|
||
_movement = GetComponent<TransformBasedMovement>();
|
||
}
|
||
|
||
public void RequestMoveTo(Vector2 target)
|
||
{
|
||
_navAgent?.UpdatePath(target);
|
||
}
|
||
|
||
public void StopNavigation()
|
||
{
|
||
_navAgent?.Stop();
|
||
}
|
||
|
||
public bool IsAtDestination()
|
||
{
|
||
if (_navAgent == null) return true;
|
||
// 已停止 OR 在目标线段上且不再跟随路径
|
||
return _navAgent.IsIdle;
|
||
}
|
||
|
||
public void SetSpeed(float speed)
|
||
{
|
||
if (_movement != null) _movement.movementSpeed = speed;
|
||
}
|
||
}
|
||
}
|
||
|