-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathRectExtensions.cs
113 lines (95 loc) · 2.65 KB
/
RectExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using UnityEngine;
namespace Multiplayer.Client
{
public static class RectExtensions
{
public static Rect Under(this Rect rect, float height)
{
return new Rect(rect.xMin, rect.yMax, rect.width, height);
}
public static Rect Down(this Rect rect, float y)
{
rect.y += y;
return rect;
}
public static Rect Up(this Rect rect, float y)
{
rect.y -= y;
return rect;
}
public static Rect Right(this Rect rect, float x)
{
rect.x += x;
return rect;
}
public static Rect Left(this Rect rect, float x)
{
rect.x -= x;
return rect;
}
public static Rect Width(this Rect rect, float width)
{
rect.width = width;
return rect;
}
public static Rect Height(this Rect rect, float height)
{
rect.height = height;
return rect;
}
public static Rect CenterOn(this Rect rect, Rect on)
{
rect.x = on.x + (on.width - rect.width) / 2f;
rect.y = on.y + (on.height - rect.height) / 2f;
return rect;
}
public static Rect CenterOn(this Rect rect, Vector2 on)
{
rect.x = on.x - rect.width / 2f;
rect.y = on.y - rect.height / 2f;
return rect;
}
public static Vector2 BottomLeftCorner(this Rect rect)
{
return new Vector2(rect.xMin, rect.yMax);
}
public static Vector2 TopRightCorner(this Rect rect)
{
return new Vector2(rect.xMax, rect.yMin);
}
public static Rect ExpandedBy(this Vector2 center, float expand)
{
return new Rect(center.x - expand, center.y - expand, 2 * expand, 2 * expand);
}
public static Rect MinX(this Rect rect, float x)
{
rect.xMin = x;
return rect;
}
public static Rect MinY(this Rect rect, float y)
{
rect.yMin = y;
return rect;
}
public static Rect MaxX(this Rect rect, float x)
{
rect.xMax = x;
return rect;
}
public static Rect MaxY(this Rect rect, float y)
{
rect.yMax = y;
return rect;
}
public static Rect AtX(this Rect rect, float x)
{
rect.x = x;
return rect;
}
public static Rect AtY(this Rect rect, float y)
{
rect.y = y;
return rect;
}
}
}