Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
Util Class Reference

Static Public Member Functions

static int Distance (int pX1, int pY1, int pX2, int pY2)
 
static T CopyComponent< T > (T original, GameObject destination)
 
static T Instantiate< T > (T t, Component parent=null)
 
static Transform Instantiate (string path, Component parent=null)
 
static T Instantiate< T > (string path, Component parent=null)
 
static void DestroyChildren (Transform trans)
 
static void RebuildLayoutInParents (Component c, Component root)
 
static void SetRectToFitScreen (RectTransform rect)
 
static void ClampToScreen (RectTransform rect, int margin=0)
 
static float GetAngle (Vector3 self, Vector3 target)
 
static float GetAngle (float x, float y)
 
static VectorDir GetVectorDir (Vector3 normal)
 
static Vector2 ConvertAxis (Vector2 v)
 
static Vector2 WorldToUIPos (Vector3 worldPoint, RectTransform container)
 
static T RandomEnum< T > ()
 
static List< T > EnumToList< T > ()
 
static void ShowExplorer (string itemPath, bool selectFirstFile=false)
 
static void Run (string itemPath)
 
static T[,] ResizeArray< T > (T[,] original, int x, int y, Func< int, int, T > func)
 

Static Public Attributes

static Color[] alphaMap
 
static Canvas canvas
 

Static Private Member Functions

static Util ()
 

Detailed Description

Definition at line 9 of file Util.cs.

Constructor & Destructor Documentation

◆ Util()

static Util.Util ( )
inlinestaticprivate

Definition at line 15 of file Util.cs.

16 {
17 alphaMap = new Color[256];
18 for (int i = 0; i < 256; i++)
19 {
20 alphaMap[i] = new Color(1f, 1f, 1f, 1f * (float)i / 255f);
21 }
22 }
static Color[] alphaMap
Definition: Util.cs:11

References Color.

Member Function Documentation

◆ ClampToScreen()

static void Util.ClampToScreen ( RectTransform  rect,
int  margin = 0 
)
inlinestatic

Definition at line 110 of file Util.cs.

111 {
112 RectTransform rectTransform = BaseCore.Instance.canvas.Rect();
113 Vector3 localPosition = rect.localPosition;
114 Vector3 vector = rectTransform.rect.min - rect.rect.min;
115 Vector3 vector2 = rectTransform.rect.max - rect.rect.max;
116 localPosition.x = Mathf.Clamp(localPosition.x, vector.x + (float)margin, vector2.x - (float)margin);
117 localPosition.y = Mathf.Clamp(localPosition.y, vector.y + (float)margin, vector2.y - (float)margin);
118 rect.localPosition = localPosition;
119 }
Canvas canvas
Definition: BaseCore.cs:34
static BaseCore Instance
Definition: BaseCore.cs:11

References BaseCore.canvas, and BaseCore.Instance.

◆ ConvertAxis()

static Vector2 Util.ConvertAxis ( Vector2  v)
inlinestatic

Definition at line 157 of file Util.cs.

158 {
159 float x = v.x;
160 float y = v.y;
161 if (y == 1f)
162 {
163 if (x == 0f)
164 {
165 return new Vector2(-1f, 1f);
166 }
167 if (x == 1f)
168 {
169 return new Vector2(0f, 1f);
170 }
171 if (x == -1f)
172 {
173 return new Vector2(-1f, 0f);
174 }
175 }
176 if (y == 0f)
177 {
178 if (x == 0f)
179 {
180 return Vector2.zero;
181 }
182 if (x == 1f)
183 {
184 return new Vector2(1f, 1f);
185 }
186 if (x == -1f)
187 {
188 return new Vector2(-1f, -1f);
189 }
190 }
191 if (y == -1f)
192 {
193 if (x == 0f)
194 {
195 return new Vector2(1f, -1f);
196 }
197 if (x == 1f)
198 {
199 return new Vector2(1f, 0f);
200 }
201 if (x == -1f)
202 {
203 return new Vector2(0f, -1f);
204 }
205 }
206 return Vector3.zero;
207 }

◆ CopyComponent< T >()

static T Util.CopyComponent< T > ( original,
GameObject  destination 
)
inlinestatic
Type Constraints
T :Component 

Definition at line 29 of file Util.cs.

29 : Component
30 {
31 Type type = original.GetType();
32 T val = destination.GetComponent(type) as T;
33 if (!val)
34 {
35 val = destination.AddComponent(type) as T;
36 }
37 FieldInfo[] fields = type.GetFields();
38 foreach (FieldInfo fieldInfo in fields)
39 {
40 if (!fieldInfo.IsStatic)
41 {
42 fieldInfo.SetValue(val, fieldInfo.GetValue(original));
43 }
44 }
45 PropertyInfo[] properties = type.GetProperties();
46 foreach (PropertyInfo propertyInfo in properties)
47 {
48 if (propertyInfo.CanWrite && propertyInfo.CanWrite && !(propertyInfo.Name == "name") && !(propertyInfo.Name == "usedByComposite") && !(propertyInfo.Name == "density"))
49 {
50 propertyInfo.SetValue(val, propertyInfo.GetValue(original, null), null);
51 }
52 }
53 return val;
54 }

◆ DestroyChildren()

static void Util.DestroyChildren ( Transform  trans)
inlinestatic

Definition at line 82 of file Util.cs.

83 {
84 for (int num = trans.childCount - 1; num >= 0; num--)
85 {
86 UnityEngine.Object.Destroy(trans.GetChild(num).gameObject);
87 }
88 }

◆ Distance()

static int Util.Distance ( int  pX1,
int  pY1,
int  pX2,
int  pY2 
)
inlinestatic

Definition at line 24 of file Util.cs.

25 {
26 return (int)Math.Sqrt((pX1 - pX2) * (pX1 - pX2) + (pY1 - pY2) * (pY1 - pY2));
27 }

◆ EnumToList< T >()

static List< T > Util.EnumToList< T > ( )
inlinestatic
Type Constraints
T :Enum 

Definition at line 223 of file Util.cs.

223 : Enum
224 {
225 return Enum.GetValues(typeof(T)).Cast<T>().ToList();
226 }

◆ GetAngle() [1/2]

static float Util.GetAngle ( float  x,
float  y 
)
inlinestatic

Definition at line 127 of file Util.cs.

128 {
129 return Mathf.Atan2(0f - y, x) * 57.29578f + 90f;
130 }

◆ GetAngle() [2/2]

static float Util.GetAngle ( Vector3  self,
Vector3  target 
)
inlinestatic

Definition at line 121 of file Util.cs.

122 {
123 Vector3 vector = target - self;
124 return Mathf.Atan2(vector.y * -1f, vector.x) * 57.29578f + 90f;
125 }

◆ GetVectorDir()

static VectorDir Util.GetVectorDir ( Vector3  normal)
inlinestatic

Definition at line 132 of file Util.cs.

133 {
134 if (Math.Abs(normal.y - 1f) < 0.1f)
135 {
136 return VectorDir.down;
137 }
138 if (Math.Abs(normal.x - 1f) < 0.1f)
139 {
140 return VectorDir.left;
141 }
142 if (Math.Abs(normal.x - -1f) < 0.1f)
143 {
144 return VectorDir.right;
145 }
146 if (Math.Abs(normal.z - 1f) < 0.1f)
147 {
148 return VectorDir.back;
149 }
150 if (Math.Abs(normal.z - -1f) < 0.1f)
151 {
152 return VectorDir.forward;
153 }
154 return VectorDir.up;
155 }
VectorDir
Definition: VectorDir.cs:2

◆ Instantiate()

static Transform Util.Instantiate ( string  path,
Component  parent = null 
)
inlinestatic

Definition at line 67 of file Util.cs.

68 {
69 return Instantiate<Transform>(path, parent);
70 }

Referenced by Instantiate< T >().

◆ Instantiate< T >() [1/2]

static T Util.Instantiate< T > ( string  path,
Component  parent = null 
)
inlinestatic
Type Constraints
T :Component 

Definition at line 72 of file Util.cs.

72 : Component
73 {
74 T val = Resources.Load<T>(path);
75 if (val == null)
76 {
77 return null;
78 }
79 return Instantiate(val, parent);
80 }
static Transform Instantiate(string path, Component parent=null)
Definition: Util.cs:67

References Instantiate().

◆ Instantiate< T >() [2/2]

static T Util.Instantiate< T > ( t,
Component  parent = null 
)
inlinestatic
Type Constraints
T :Component 

Definition at line 56 of file Util.cs.

56 : Component
57 {
58 T val = UnityEngine.Object.Instantiate(t);
59 val.transform.SetParent(parent ? parent.transform : null, worldPositionStays: false);
60 if (!val.gameObject.activeSelf)
61 {
62 val.gameObject.SetActive(value: true);
63 }
64 return val;
65 }

◆ RandomEnum< T >()

static T Util.RandomEnum< T > ( )
inlinestatic

Definition at line 217 of file Util.cs.

218 {
219 Array values = Enum.GetValues(typeof(T));
220 return (T)values.GetValue(new System.Random().Next(values.Length));
221 }

◆ RebuildLayoutInParents()

static void Util.RebuildLayoutInParents ( Component  c,
Component  root 
)
inlinestatic

Definition at line 90 of file Util.cs.

91 {
92 Transform transform = c.transform;
93 transform.RebuildLayout();
94 Transform parent = transform.parent;
95 if ((bool)parent && !(parent == root.transform))
96 {
97 RebuildLayoutInParents(parent, root);
98 }
99 }
static void RebuildLayoutInParents(Component c, Component root)
Definition: Util.cs:90

References RebuildLayoutInParents().

Referenced by RebuildLayoutInParents().

◆ ResizeArray< T >()

static T[,] Util.ResizeArray< T > ( original[,],
int  x,
int  y,
Func< int, int, T >  func 
)
inlinestatic

Definition at line 247 of file Util.cs.

248 {
249 T[,] array = new T[x, y];
250 int num = Math.Min(x, original.GetLength(0));
251 int num2 = Math.Min(y, original.GetLength(1));
252 for (int i = 0; i < x; i++)
253 {
254 for (int j = 0; j < y; j++)
255 {
256 if (i >= num || j >= num2)
257 {
258 array[i, j] = func(i, j);
259 }
260 else
261 {
262 array[i, j] = original[i, j];
263 }
264 }
265 }
266 return array;
267 }

◆ Run()

static void Util.Run ( string  itemPath)
inlinestatic

Definition at line 242 of file Util.cs.

243 {
244 Process.Start(itemPath);
245 }

◆ SetRectToFitScreen()

static void Util.SetRectToFitScreen ( RectTransform  rect)
inlinestatic

Definition at line 101 of file Util.cs.

102 {
103 rect.anchorMin = Vector2.zero;
104 rect.anchorMax = Vector2.one;
105 rect.localPosition = Vector3.zero;
106 rect.anchoredPosition = Vector2.zero;
107 rect.sizeDelta = Vector2.zero;
108 }

◆ ShowExplorer()

static void Util.ShowExplorer ( string  itemPath,
bool  selectFirstFile = false 
)
inlinestatic

Definition at line 228 of file Util.cs.

229 {
230 if (selectFirstFile)
231 {
232 FileInfo[] files = new DirectoryInfo(itemPath).GetFiles();
233 if (files.Length != 0)
234 {
235 itemPath = itemPath + "/" + files[0].Name;
236 }
237 }
238 itemPath = itemPath.Replace("/", "\\");
239 Process.Start("explorer.exe", "/select," + itemPath);
240 }

◆ WorldToUIPos()

static Vector2 Util.WorldToUIPos ( Vector3  worldPoint,
RectTransform  container 
)
inlinestatic

Definition at line 209 of file Util.cs.

210 {
211 Vector2 localPoint = Vector2.zero;
212 Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, worldPoint);
213 RectTransformUtility.ScreenPointToLocalPointInRectangle(container, screenPoint, canvas.worldCamera, out localPoint);
214 return localPoint;
215 }
static Canvas canvas
Definition: Util.cs:13

Member Data Documentation

◆ alphaMap

Color [] Util.alphaMap
static

Definition at line 11 of file Util.cs.

◆ canvas

Canvas Util.canvas
static

Definition at line 13 of file Util.cs.


The documentation for this class was generated from the following file: