Files
aibis-dream/Assets/Scripts/MiniGame/HuoShan/Language/ExpressionParticleGeometry.cs
T
2026-08-02 13:43:06 +08:00

46 lines
1.2 KiB
C#

using UnityEngine;
namespace AibisDream.MiniGame.Language
{
public static class ExpressionParticleGeometry
{
public static bool TryGetSeparation(
Bounds first,
Bounds second,
float padding,
out Vector2 direction,
out float overlap)
{
float overlapX =
Mathf.Min(first.max.x, second.max.x) -
Mathf.Max(first.min.x, second.min.x) +
padding;
float overlapY =
Mathf.Min(first.max.y, second.max.y) -
Mathf.Max(first.min.y, second.min.y) +
padding;
if (overlapX <= 0f || overlapY <= 0f)
{
direction = Vector2.zero;
overlap = 0f;
return false;
}
Vector2 centerDelta = first.center - second.center;
if (overlapX <= overlapY)
{
direction = new Vector2(centerDelta.x >= 0f ? 1f : -1f, 0f);
overlap = overlapX;
}
else
{
direction = new Vector2(0f, centerDelta.y >= 0f ? 1f : -1f);
overlap = overlapY;
}
return true;
}
}
}