Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
DynamicScrollViewExtention.cs
Go to the documentation of this file.
1using UnityEngine;
2
3namespace Mosframe;
4
5public static class DynamicScrollViewExtention
6{
7 public static void setLayer(this GameObject self, int layer, bool includeChildren = true)
8 {
9 self.layer = layer;
10 if (includeChildren)
11 {
12 Transform[] componentsInChildren = self.transform.GetComponentsInChildren<Transform>(includeInactive: true);
13 for (int i = 0; i < componentsInChildren.Length; i++)
14 {
15 componentsInChildren[i].gameObject.layer = layer;
16 }
17 }
18 }
19
20 public static RectTransform setFullSize(this RectTransform self)
21 {
22 self.sizeDelta = new Vector2(0f, 0f);
23 self.anchorMin = new Vector2(0f, 0f);
24 self.anchorMax = new Vector2(1f, 1f);
25 self.pivot = new Vector2(0.5f, 0.5f);
26 return self;
27 }
28
29 public static Vector2 getSize(this RectTransform self)
30 {
31 return self.rect.size;
32 }
33
34 public static void setSize(this RectTransform self, Vector2 newSize)
35 {
36 Vector2 pivot = self.pivot;
37 Vector2 vector = newSize - self.rect.size;
38 self.offsetMin -= new Vector2(vector.x * pivot.x, vector.y * pivot.y);
39 self.offsetMax += new Vector2(vector.x * (1f - pivot.x), vector.y * (1f - pivot.y));
40 }
41
42 public static RectTransform setSizeFromLeft(this RectTransform self, float rate)
43 {
44 self.setFullSize();
45 float width = self.rect.width;
46 self.anchorMin = new Vector2(0f, 0f);
47 self.anchorMax = new Vector2(0f, 1f);
48 self.pivot = new Vector2(0f, 1f);
49 self.sizeDelta = new Vector2(width * rate, 0f);
50 return self;
51 }
52
53 public static RectTransform setSizeFromRight(this RectTransform self, float rate)
54 {
55 self.setFullSize();
56 float width = self.rect.width;
57 self.anchorMin = new Vector2(1f, 0f);
58 self.anchorMax = new Vector2(1f, 1f);
59 self.pivot = new Vector2(1f, 1f);
60 self.sizeDelta = new Vector2(width * rate, 0f);
61 return self;
62 }
63
64 public static RectTransform setSizeFromTop(this RectTransform self, float rate)
65 {
66 self.setFullSize();
67 float height = self.rect.height;
68 self.anchorMin = new Vector2(0f, 1f);
69 self.anchorMax = new Vector2(1f, 1f);
70 self.pivot = new Vector2(0f, 1f);
71 self.sizeDelta = new Vector2(0f, height * rate);
72 return self;
73 }
74
75 public static RectTransform setSizeFromBottom(this RectTransform self, float rate)
76 {
77 self.setFullSize();
78 float height = self.rect.height;
79 self.anchorMin = new Vector2(0f, 0f);
80 self.anchorMax = new Vector2(1f, 0f);
81 self.pivot = new Vector2(0f, 0f);
82 self.sizeDelta = new Vector2(0f, height * rate);
83 return self;
84 }
85
86 public static void setOffset(this RectTransform self, float left, float top, float right, float bottom)
87 {
88 self.offsetMin = new Vector2(left, top);
89 self.offsetMax = new Vector2(right, bottom);
90 }
91
92 public static bool inScreenRect(this RectTransform self, Vector2 screenPos)
93 {
94 Canvas componentInParent = self.GetComponentInParent<Canvas>();
95 switch (componentInParent.renderMode)
96 {
97 case RenderMode.ScreenSpaceCamera:
98 {
99 Camera worldCamera = componentInParent.worldCamera;
100 if (worldCamera != null)
101 {
102 return RectTransformUtility.RectangleContainsScreenPoint(self, screenPos, worldCamera);
103 }
104 break;
105 }
106 case RenderMode.ScreenSpaceOverlay:
107 return RectTransformUtility.RectangleContainsScreenPoint(self, screenPos);
108 case RenderMode.WorldSpace:
109 return RectTransformUtility.RectangleContainsScreenPoint(self, screenPos);
110 }
111 return false;
112 }
113
114 public static bool inScreenRect(this RectTransform self, RectTransform rectTransform)
115 {
116 Rect screenRect = self.getScreenRect();
117 Rect screenRect2 = rectTransform.getScreenRect();
118 return screenRect.Overlaps(screenRect2);
119 }
120
121 public static Rect getScreenRect(this RectTransform self)
122 {
123 Rect result = default(Rect);
124 Camera worldCamera = self.GetComponentInParent<Canvas>().worldCamera;
125 if (worldCamera != null)
126 {
127 Vector3[] array = new Vector3[4];
128 self.GetWorldCorners(array);
129 result.min = worldCamera.WorldToScreenPoint(array[0]);
130 result.max = worldCamera.WorldToScreenPoint(array[2]);
131 }
132 return result;
133 }
134}
static bool inScreenRect(this RectTransform self, RectTransform rectTransform)
static Vector2 getSize(this RectTransform self)
static Rect getScreenRect(this RectTransform self)
static RectTransform setSizeFromRight(this RectTransform self, float rate)
static RectTransform setSizeFromTop(this RectTransform self, float rate)
static RectTransform setSizeFromLeft(this RectTransform self, float rate)
static void setOffset(this RectTransform self, float left, float top, float right, float bottom)
static void setSize(this RectTransform self, Vector2 newSize)
static RectTransform setSizeFromBottom(this RectTransform self, float rate)
static void setLayer(this GameObject self, int layer, bool includeChildren=true)
static RectTransform setFullSize(this RectTransform self)
static bool inScreenRect(this RectTransform self, Vector2 screenPos)