-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectTransformExtensions.cs
More file actions
65 lines (63 loc) · 2.45 KB
/
RectTransformExtensions.cs
File metadata and controls
65 lines (63 loc) · 2.45 KB
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
using UnityEngine;
namespace ExtraSlots
{
public static class RectTransformExtensions
{
public enum ElementAnchor
{
TopLeft,
Top,
TopRight,
Right,
BottomRight,
Bottom,
BottomLeft,
Left,
Middle
}
public static void SetAnchor(this RectTransform rectTransform, ElementAnchor anchor)
{
switch (anchor)
{
case ElementAnchor.TopLeft:
rectTransform.anchorMin = new Vector2(0f, 1f);
rectTransform.anchorMax = new Vector2(0f, 1f);
break;
case ElementAnchor.Top:
rectTransform.anchorMin = new Vector2(0.5f, 1f);
rectTransform.anchorMax = new Vector2(0.5f, 1f);
break;
case ElementAnchor.TopRight:
rectTransform.anchorMin = new Vector2(1f, 1f);
rectTransform.anchorMax = new Vector2(1f, 1f);
break;
case ElementAnchor.Right:
rectTransform.anchorMin = new Vector2(1f, 0.5f);
rectTransform.anchorMax = new Vector2(1f, 0.5f);
break;
case ElementAnchor.BottomRight:
rectTransform.anchorMin = new Vector2(1f, 0f);
rectTransform.anchorMax = new Vector2(1f, 0f);
break;
case ElementAnchor.Bottom:
rectTransform.anchorMin = new Vector2(0.5f, 0f);
rectTransform.anchorMax = new Vector2(0.5f, 0f);
break;
case ElementAnchor.BottomLeft:
rectTransform.anchorMin = new Vector2(0f, 0f);
rectTransform.anchorMax = new Vector2(0f, 0f);
break;
case ElementAnchor.Left:
rectTransform.anchorMin = new Vector2(0f, 0.5f);
rectTransform.anchorMax = new Vector2(0f, 0.5f);
break;
case ElementAnchor.Middle:
rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
break;
default:
throw new System.ArgumentOutOfRangeException(nameof(anchor), anchor, null);
}
}
}
}