- Implemented HurtBoxOwnerGuard to ensure that multiple HurtBoxes on the same character do not register damage multiple times during a single HitBox activation. - Added custom editor for HitBox to facilitate the creation of shape colliders with HitBoxColliderProxy. - Introduced PhysicsPerceptionSystem for enemy perception, supporting multiple detection modes including RangeCircle, BatchLOS, FanCast, and BoxCast. - Created EnemyPatrolZone to define patrol and chase areas for enemies, allowing for shared zones among multiple enemies. - Added BD_IsOutsideZone conditional task for Behavior Designer to check if an enemy or player is outside a defined patrol zone.
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Linq;
|
|
using Animancer;
|
|
using UnityEngine;
|
|
|
|
namespace BaseGames.Enemies.Abilities
|
|
{
|
|
/// <summary>
|
|
/// 面向玩家能力:朝向玩家后播放转身/翻转动画并等待完成。
|
|
/// CanUse 重写:仅在无其他技能运行且玩家在背后时可用。
|
|
/// 可复用于任何需要"检测背后玩家并翻转"的敌人。
|
|
/// </summary>
|
|
public class FacePlayerAbility : EnemyAbilityBase
|
|
{
|
|
[SerializeField] private ClipTransition _faceClip;
|
|
|
|
public override bool CanUse =>
|
|
base.CanUse
|
|
&& !_enemy.Abilities.All.Any(a => a != this && a.IsRunning)
|
|
&& IsPlayerBehind();
|
|
|
|
private bool IsPlayerBehind()
|
|
{
|
|
if (_enemy.PlayerTransform == null) return false;
|
|
float dx = _enemy.PlayerTransform.position.x - _enemy.transform.position.x;
|
|
int facing = _enemy.Movement?.FacingDirection ?? 1;
|
|
return (facing > 0 && dx < 0) || (facing < 0 && dx > 0);
|
|
}
|
|
|
|
protected override IEnumerator ExecuteCoroutine()
|
|
{
|
|
Phase = AbilityRunState.Active;
|
|
|
|
_enemy.FacePlayer();
|
|
|
|
if (_faceClip.Clip == null) yield break;
|
|
|
|
_animancer.Play(_faceClip);
|
|
yield return EnemyAbilityWaits.Get(_faceClip.Clip.length);
|
|
}
|
|
}
|
|
}
|