33 lines
1020 B
C#
33 lines
1020 B
C#
using UnityEngine;
|
|
|
|
namespace BrewMonster.Scripts.Extensions
|
|
{
|
|
public static class RectExtension
|
|
{
|
|
public static bool IsEmpty(this Rect rect)
|
|
{
|
|
return rect.width == 0 && rect.height == 0;
|
|
}
|
|
|
|
public static Rect Intersect(this Rect rc1, Rect rc2)
|
|
{
|
|
if ((rc1.width == 0 && rc1.height == 0) || (rc2.width == 0 && rc2.height == 0))
|
|
return Rect.zero;
|
|
|
|
if (rc1.xMin >= rc2.xMax || rc2.xMin >= rc1.xMax ||
|
|
rc1.xMin >= rc2.yMax || rc2.yMin >= rc1.yMax)
|
|
return Rect.zero;
|
|
|
|
return new Rect(Mathf.Max(rc1.x, rc2.x), Mathf.Max(rc1.y, rc2.y), Mathf.Min(rc1.width, rc2.width), Mathf.Min(rc1.height, rc2.height));
|
|
}
|
|
|
|
public static Rect Offset(this Rect rect, float x, float y)
|
|
{
|
|
rect.xMin += x;
|
|
rect.yMin += y;
|
|
rect.xMax += x;
|
|
rect.yMax += y;
|
|
return rect;
|
|
}
|
|
}
|
|
} |