多轮审查和修复
This commit is contained in:
55
Assets/Scripts/World/DirectionalDestructible.cs
Normal file
55
Assets/Scripts/World/DirectionalDestructible.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using BaseGames.Combat;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.World
|
||||
{
|
||||
/// <summary>
|
||||
/// 单向可破坏物。在 DestructibleTile 基础上增加攻击方向校验。
|
||||
/// 使用 AttackSide.Any 等效于普通 DestructibleTile。
|
||||
/// </summary>
|
||||
public class DirectionalDestructible : DestructibleTile
|
||||
{
|
||||
public enum AttackSide { Left, Right, Top, Bottom, Any }
|
||||
|
||||
[SerializeField] private AttackSide _validAttackSide = AttackSide.Any;
|
||||
|
||||
protected override bool CheckDestroyCondition(DamageInfo info)
|
||||
{
|
||||
if (_validAttackSide == AttackSide.Any)
|
||||
return base.CheckDestroyCondition(info);
|
||||
|
||||
var dir = (info.SourcePosition - (Vector2)transform.position).normalized;
|
||||
|
||||
bool valid = _validAttackSide switch
|
||||
{
|
||||
AttackSide.Left => dir.x < -0.5f,
|
||||
AttackSide.Right => dir.x > 0.5f,
|
||||
AttackSide.Top => dir.y > 0.5f,
|
||||
AttackSide.Bottom => dir.y < -0.5f,
|
||||
_ => true
|
||||
};
|
||||
|
||||
return valid && base.CheckDestroyCondition(info);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Vector2 arrow = _validAttackSide switch
|
||||
{
|
||||
AttackSide.Left => Vector2.left,
|
||||
AttackSide.Right => Vector2.right,
|
||||
AttackSide.Top => Vector2.up,
|
||||
AttackSide.Bottom => Vector2.down,
|
||||
_ => Vector2.zero
|
||||
};
|
||||
|
||||
if (arrow == Vector2.zero) return;
|
||||
|
||||
Gizmos.color = new Color(1f, 0.5f, 0f, 0.9f);
|
||||
var origin = (Vector2)transform.position;
|
||||
Gizmos.DrawLine(origin, origin + arrow * 0.8f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user