Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ClassExtension.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Reflection;
7using System.Text;
8using Pluralize.NET;
9using UnityEngine;
10using UnityEngine.Events;
11using UnityEngine.UI;
12
13public static class ClassExtension
14{
15 private static Vector3 vector3;
16
17 public static IPluralize pluralizer = new Pluralizer();
18
19 public static string lang(this string s)
20 {
21 return Lang.Get(s);
22 }
23
24 public static string langPlural(this string s, int i)
25 {
26 string text = Lang.Get(s);
27 return Lang.Parse((i <= 1 || !Lang.setting.pluralize) ? text : pluralizer.Pluralize(text), i.ToString() ?? "");
28 }
29
30 public static string lang(this string s, string ref1, string ref2 = null, string ref3 = null, string ref4 = null, string ref5 = null)
31 {
32 return Lang.Parse(s, ref1, ref2, ref3, ref4, ref5);
33 }
34
35 public static string langGame(this string s)
36 {
37 return Lang.Game.Get(s);
38 }
39
40 public static string langGame(this string s, string ref1, string ref2 = null, string ref3 = null, string ref4 = null)
41 {
42 return Lang.Game.Parse(s, ref1, ref2, ref3, ref4);
43 }
44
45 public static string Parentheses(this string str)
46 {
47 return "(" + str + ")";
48 }
49
50 public static string Bracket(this string str, int type = 0)
51 {
52 return type switch
53 {
54 -1 => str,
55 1 => "「" + str + "」",
56 2 => "『" + str + "』",
57 3 => "《" + str + "》",
58 4 => "(" + str + ")",
59 _ => "_bracketLeft".lang() + str + "_bracketRight".lang(),
60 };
61 }
62
63 public static byte[] ToBytes(this BitArray bits)
64 {
65 byte[] array = new byte[(bits.Length - 1) / 8 + 1];
66 bits.CopyTo(array, 0);
67 return array;
68 }
69
70 public static bool GetBit(this byte pByte, int bitNo)
71 {
72 return (pByte & (1 << bitNo)) != 0;
73 }
74
75 public static byte SetBit(this byte pByte, int bitNo, bool value)
76 {
77 if (!value)
78 {
79 return Convert.ToByte(pByte & ~(1 << bitNo));
80 }
81 return Convert.ToByte(pByte | (1 << bitNo));
82 }
83
84 public static int ToInt3(this float a)
85 {
86 return (int)(a * 1000f);
87 }
88
89 public static float FromInt3(this int a)
90 {
91 return (float)a / 1000f;
92 }
93
94 public static int ToInt2(this float a)
95 {
96 return (int)(a * 100f);
97 }
98
99 public static float FromInt2(this int a)
100 {
101 return (float)a / 100f;
102 }
103
104 public static int Minimum(this int i)
105 {
106 if (i != 0)
107 {
108 if (i <= 0)
109 {
110 return -1;
111 }
112 return 1;
113 }
114 return 0;
115 }
116
117 public static bool IsNull(this object o)
118 {
119 return o == null;
120 }
121
122 public static bool IsOn(this int data, int digit)
123 {
124 BitArray32 bitArray = default(BitArray32);
125 bitArray.SetInt(data);
126 return bitArray[digit];
127 }
128
129 public static T ToEnum<T>(this int value)
130 {
131 return (T)Enum.ToObject(typeof(T), value);
132 }
133
134 public static T ToEnum<T>(this long value)
135 {
136 return (T)Enum.ToObject(typeof(T), value);
137 }
138
139 public static T ToEnum<T>(this string value, bool ignoreCase = true)
140 {
141 return (T)Enum.Parse(typeof(T), value, ignoreCase);
142 }
143
144 public static Type ToType(this string value)
145 {
146 return Type.GetType("Elona." + value + ", Assembly-CSharp");
147 }
148
149 public static T NextEnum<T>(this T src) where T : struct
150 {
151 return ((T[])Enum.GetValues(src.GetType())).NextItem(src);
152 }
153
154 public static T PrevEnum<T>(this T src) where T : struct
155 {
156 return ((T[])Enum.GetValues(src.GetType())).PrevItem(src);
157 }
158
159 public static bool Within(this int v, int v2, int range)
160 {
161 if (v - v2 >= range)
162 {
163 return v - v2 < -range;
164 }
165 return true;
166 }
167
168 public static bool Within(this byte v, byte v2, byte range)
169 {
170 if (v - v2 >= range)
171 {
172 return v - v2 < -range;
173 }
174 return true;
175 }
176
177 public static int Clamp(this int v, int min, int max, bool loop = false)
178 {
179 if (v < min)
180 {
181 v = ((!loop) ? min : max);
182 }
183 else if (v > max)
184 {
185 v = ((!loop) ? max : min);
186 }
187 return v;
188 }
189
190 public static int ClampMin(this int v, int min)
191 {
192 if (v >= min)
193 {
194 return v;
195 }
196 return min;
197 }
198
199 public static int ClampMax(this int v, int max)
200 {
201 if (v <= max)
202 {
203 return v;
204 }
205 return max;
206 }
207
208 public static T ToField<T>(this string s, object o)
209 {
210 return (T)o.GetType().GetField(s).GetValue(o);
211 }
212
213 public static bool HasField<T>(this object o, string name)
214 {
215 FieldInfo field = o.GetType().GetField(name);
216 if (field != null)
217 {
218 return typeof(T).IsAssignableFrom(field.FieldType);
219 }
220 return false;
221 }
222
223 public static T GetField<T>(this object o, string name)
224 {
225 return (T)o.GetType().GetField(name).GetValue(o);
226 }
227
228 public static void SetField<T>(this object o, string name, T value)
229 {
230 o.GetType().GetField(name).SetValue(o, value);
231 }
232
233 public static T GetProperty<T>(this object o, string name)
234 {
235 return (T)o.GetType().GetProperty(name).GetValue(o);
236 }
237
238 public static void SetProperty<T>(this object o, string name, T value)
239 {
240 o.GetType().GetProperty(name).SetValue(o, value);
241 }
242
243 public static void Sort<T>(this IList<T> list, Comparison<T> comparison)
244 {
245 if (list is List<T>)
246 {
247 ((List<T>)list).Sort(comparison);
248 return;
249 }
250 List<T> list2 = new List<T>(list);
251 list2.Sort(comparison);
252 for (int i = 0; i < list.Count; i++)
253 {
254 list[i] = list2[i];
255 }
256 }
257
258 public static TValue TryGet<TValue>(this IList<TValue> array, int index, int defIndex = -1)
259 {
260 if (array.Count != 0)
261 {
262 if (index >= array.Count)
263 {
264 if (defIndex != -1)
265 {
266 if (array.Count <= defIndex)
267 {
268 return array[Mathf.Max(0, array.Count - 1)];
269 }
270 return array[defIndex];
271 }
272 return array[Mathf.Max(0, array.Count - 1)];
273 }
274 return array[Math.Max(0, index)];
275 }
276 return default(TValue);
277 }
278
279 public static TValue TryGet<TValue>(this IList<TValue> array, int index, bool returnNull)
280 {
281 if (index >= array.Count)
282 {
283 return default(TValue);
284 }
285 return array[index];
286 }
287
288 public static bool IsEmpty(this Array array)
289 {
290 if (array != null)
291 {
292 return array.Length == 0;
293 }
294 return true;
295 }
296
297 public static int IndexOf(this IList<Component> list, GameObject go)
298 {
299 if (!go)
300 {
301 return -1;
302 }
303 for (int i = 0; i < list.Count; i++)
304 {
305 if (list[i].gameObject == go)
306 {
307 return i;
308 }
309 }
310 return -1;
311 }
312
313 public static TValue Move<TValue>(this IList<TValue> list, TValue target, int a)
314 {
315 int num = list.IndexOf(target);
316 int num2 = num + a;
317 if (num2 < 0)
318 {
319 num2 = list.Count - 1;
320 }
321 if (num2 >= list.Count)
322 {
323 num2 = 0;
324 }
325 list.Remove(target);
326 list.Insert(num2, target);
327 return list[num];
328 }
329
330 public static IList<TValue> Copy<TValue>(this IList<TValue> list)
331 {
332 return list.ToList();
333 }
334
335 public static void Each<TValue>(this IList<TValue> list, Action<TValue> action)
336 {
337 for (int num = list.Count - 1; num >= 0; num--)
338 {
339 action(list[num]);
340 }
341 }
342
343 public static IList<TValue> Shuffle<TValue>(this IList<TValue> list)
344 {
345 int num = list.Count;
346 while (num > 1)
347 {
348 int index = Rand._random.Next(num);
349 num--;
350 TValue value = list[num];
351 list[num] = list[index];
352 list[index] = value;
353 }
354 return list;
355 }
356
357 public static TValue TryGetValue<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key, TValue fallback = default(TValue))
358 {
359 TValue value = default(TValue);
360 if (key != null && source.TryGetValue(key, out value))
361 {
362 return value;
363 }
364 return fallback;
365 }
366
367 public static TValue TryGetValue<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key, TKey key_fallback)
368 {
369 TValue value = default(TValue);
370 if (key != null && source.TryGetValue(key, out value))
371 {
372 return value;
373 }
374 return source[key_fallback];
375 }
376
377 public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, Func<TValue> func = null)
378 {
379 TValue val = dict.TryGetValue(key);
380 if (val == null)
381 {
382 val = ((func != null) ? func() : Activator.CreateInstance<TValue>());
383 dict.Add(key, val);
384 }
385 return val;
386 }
387
388 public static TKey[] CopyKeys<TKey, TValue>(this IDictionary<TKey, TValue> dict)
389 {
390 TKey[] array = new TKey[dict.Keys.Count];
391 dict.Keys.CopyTo(array, 0);
392 return array;
393 }
394
395 public static TValue[] CopyValues<TKey, TValue>(this IDictionary<TKey, TValue> dict)
396 {
397 TValue[] array = new TValue[dict.Keys.Count];
398 dict.Values.CopyTo(array, 0);
399 return array;
400 }
401
402 public static T RandomItem<T>(this IEnumerable<T> ie)
403 {
404 int num = ie.Count();
405 if (num == 0)
406 {
407 return default(T);
408 }
409 return ie.ElementAt(Rand.rnd(num));
410 }
411
412 public static TValue RandomItem<TKey, TValue>(this IDictionary<TKey, TValue> source)
413 {
414 if (source.Count != 0)
415 {
416 return source.ElementAt(Rand.rnd(source.Count)).Value;
417 }
418 return default(TValue);
419 }
420
421 public static TValue RandomItem<TValue>(this IList<TValue> source)
422 {
423 if (source.Count != 0)
424 {
425 return source[Rand.rnd(source.Count)];
426 }
427 return default(TValue);
428 }
429
430 public static TValue RandomItem<TValue>(this IList<TValue> source, TValue exclude)
431 {
432 return source.RandomItem(source.IndexOf(exclude));
433 }
434
435 public static TValue RandomItem<TValue>(this IList<TValue> source, int exclude)
436 {
437 if (source.Count > 1)
438 {
439 int num;
440 do
441 {
442 num = Rand.rnd(source.Count);
443 }
444 while (num == exclude);
445 return source[num];
446 }
447 if (source.Count == 1)
448 {
449 return source[0];
450 }
451 return default(TValue);
452 }
453
454 public static TValue RandomItem<TValue>(this IList<TValue> source, Func<TValue, bool> funcValid, TValue defaultValue = default(TValue))
455 {
456 for (int i = 0; i < 100; i++)
457 {
458 TValue val = source[Rand.rnd(source.Count)];
459 if (funcValid(val))
460 {
461 return val;
462 }
463 }
464 return defaultValue;
465 }
466
467 public static TValue RandomItemWeighted<TValue>(this IList<TValue> source, Func<TValue, float> getWeight)
468 {
469 if (source.Count == 0)
470 {
471 return default(TValue);
472 }
473 if (source.Count == 1)
474 {
475 return source[0];
476 }
477 float num = 0f;
478 foreach (TValue item in source)
479 {
480 num += getWeight(item);
481 }
482 float num2 = Rand.Range(0f, num);
483 num = 0f;
484 foreach (TValue item2 in source)
485 {
486 num += getWeight(item2);
487 if (num2 < num)
488 {
489 return item2;
490 }
491 }
492 return source.First();
493 }
494
495 public static TValue Remainder<TValue>(this IList<TValue> source, int divider)
496 {
497 if (source.Count != 0)
498 {
499 return source[divider % source.Count];
500 }
501 return default(TValue);
502 }
503
504 public static TValue FirstItem<TKey, TValue>(this IDictionary<TKey, TValue> source)
505 {
506 if (source == null)
507 {
508 return default(TValue);
509 }
510 return source[source.First().Key];
511 }
512
513 public static TValue LastItem<TValue>(this IList<TValue> source)
514 {
515 if (source.Count != 0)
516 {
517 return source[source.Count - 1];
518 }
519 return default(TValue);
520 }
521
522 public static TValue NextItem<TValue>(this IList<TValue> source, ref int index)
523 {
524 index++;
525 if (index >= source.Count)
526 {
527 index = 0;
528 }
529 if (source.Count != 0)
530 {
531 return source[index];
532 }
533 return default(TValue);
534 }
535
536 public static int NextIndex<TValue>(this IList<TValue> source, TValue val)
537 {
538 if (val == null)
539 {
540 return 0;
541 }
542 int num = source.IndexOf(val) + 1;
543 if (num >= source.Count)
544 {
545 num = 0;
546 }
547 return num;
548 }
549
550 public static TValue NextItem<TValue>(this IList<TValue> source, TValue val)
551 {
552 int num = source.IndexOf(val) + 1;
553 if (num >= source.Count)
554 {
555 num = 0;
556 }
557 if (source.Count != 0)
558 {
559 return source[num];
560 }
561 return default(TValue);
562 }
563
564 public static TValue PrevItem<TValue>(this IList<TValue> source, TValue val)
565 {
566 int num = source.IndexOf(val) - 1;
567 if (num < 0)
568 {
569 num = source.Count - 1;
570 }
571 if (source.Count != 0)
572 {
573 return source[num];
574 }
575 return default(TValue);
576 }
577
578 public static TValue Clamp<TValue>(this IList<TValue> source, int i)
579 {
580 if (i < 0)
581 {
582 i = 0;
583 }
584 else if (i >= source.Count)
585 {
586 i = source.Count - 1;
587 }
588 return source[i];
589 }
590
591 public static List<T> GetList<T>(this IDictionary source)
592 {
593 List<T> list = new List<T>();
594 foreach (object value in source.Values)
595 {
596 if (value is T)
597 {
598 list.Add((T)value);
599 }
600 }
601 return list;
602 }
603
604 public static void ToDictionary<T>(this IList<UPair<T>> list, ref Dictionary<string, T> dic)
605 {
606 dic = new Dictionary<string, T>();
607 for (int i = 0; i < list.Count; i++)
608 {
609 dic.Add(list[i].name, list[i].value);
610 }
611 }
612
613 public static T FindMax<T>(this List<T> list, Func<T, int> func)
614 {
615 int num = int.MinValue;
616 T result = default(T);
617 foreach (T item in list)
618 {
619 int num2 = func(item);
620 if (num2 > num)
621 {
622 num = num2;
623 result = item;
624 }
625 }
626 return result;
627 }
628
629 public static void Set<T1, T2>(this Dictionary<T1, T2> dic, Dictionary<T1, T2> from)
630 {
631 dic.Clear();
632 foreach (KeyValuePair<T1, T2> item in from)
633 {
634 dic[item.Key] = item.Value;
635 }
636 }
637
638 public static int Calc(this string str, int power = 0, int ele = 0, int p2 = 0)
639 {
640 return Cal.Calcuate(str.Replace("p2", p2.ToString() ?? "").Replace("p", power.ToString() ?? "").Replace("e", ele.ToString() ?? ""));
641 }
642
643 public static int ToInt<T>(this string str)
644 {
645 return str.ToInt(typeof(T));
646 }
647
648 public static int ToInt(this string str, Type type)
649 {
650 FieldInfo field = type.GetField(str, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
651 if (field == null)
652 {
653 Debug.LogError("Field is null:" + str + "/" + type);
654 return -1;
655 }
656 return (int)field.GetValue(null);
657 }
658
659 public static int ToInt(this string str)
660 {
661 if (int.TryParse(str, out var result))
662 {
663 return result;
664 }
665 return 0;
666 }
667
668 public static float ToFloat(this string str)
669 {
670 float result = 0f;
671 try
672 {
673 if (!float.TryParse(str, out result))
674 {
675 Debug.Log("exception: ToFlat1" + str);
676 result = 1f;
677 }
678 }
679 catch
680 {
681 Debug.Log("exception: ToFlat2" + str);
682 result = 1f;
683 }
684 return result;
685 }
686
687 public static string StripLastPun(this string str)
688 {
689 if (str != null)
690 {
691 return str.TrimEnd(Lang.words.period);
692 }
693 return str;
694 }
695
696 public static string StripPun(this string str, bool stripComma, bool insertSpaceForComma = false)
697 {
698 StringBuilder stringBuilder = new StringBuilder();
699 foreach (char c in str)
700 {
701 if (c == Lang.words.comma)
702 {
703 if (stripComma)
704 {
705 if (insertSpaceForComma)
706 {
707 stringBuilder.Append('\u3000');
708 }
709 }
710 else
711 {
712 stringBuilder.Append(c);
713 }
714 }
715 else if (c != Lang.words.period)
716 {
717 stringBuilder.Append(c);
718 }
719 }
720 return stringBuilder.ToString();
721 }
722
723 public static string Repeat(this string str, int count)
724 {
725 StringBuilder stringBuilder = new StringBuilder();
726 for (int i = 0; i < Mathf.Abs(count); i++)
727 {
728 stringBuilder.Append(str);
729 }
730 return stringBuilder.ToString();
731 }
732
733 public static string StripBrackets(this string str)
734 {
735 return str.Replace("\"", "").Replace("「", "").Replace("」", "")
736 .Replace("“", "")
737 .Replace("\"", "");
738 }
739
740 public static string TryAddExtension(this string s, string ext)
741 {
742 if (!s.Contains("." + ext))
743 {
744 return s + "." + ext;
745 }
746 return s;
747 }
748
749 public static bool IsEmpty(this string str)
750 {
751 if (str != null)
752 {
753 return str == "";
754 }
755 return true;
756 }
757
758 public static string IsEmpty(this string str, string defaultStr)
759 {
760 if (str != null && !(str == ""))
761 {
762 return str;
763 }
764 return defaultStr;
765 }
766
767 public static string TrimNewLines(this string text)
768 {
769 while (text.EndsWith(Environment.NewLine))
770 {
771 text = text.Substring(0, text.Length - Environment.NewLine.Length);
772 }
773 return text;
774 }
775
776 public static int[] SplitToInts(this string str, char separator)
777 {
778 string[] array = str.Split(separator);
779 int[] array2 = new int[array.Length];
780 for (int i = 0; i < array.Length; i++)
781 {
782 array2[i] = int.Parse(array[i]);
783 }
784 return array2;
785 }
786
787 public static string[] SplitNewline(this string str)
788 {
789 return str.Split(Environment.NewLine.ToCharArray());
790 }
791
792 public static bool Contains(this string[] strs, string id)
793 {
794 if (strs == null || strs.Length == 0)
795 {
796 return false;
797 }
798 for (int i = 0; i < strs.Length; i++)
799 {
800 if (strs[i] == id)
801 {
802 return true;
803 }
804 }
805 return false;
806 }
807
808 public static string Evalute(this string[] array, float val)
809 {
810 return array[(int)Mathf.Clamp((float)(array.Length - 1) * val, 0f, array.Length - 1)];
811 }
812
813 public static string ToShortNumber(this int a)
814 {
815 string text;
816 if (a < 1000000)
817 {
818 if (a >= 1000)
819 {
820 return a / 1000 + "K";
821 }
822 text = a.ToString();
823 if (text == null)
824 {
825 return "";
826 }
827 }
828 else
829 {
830 text = a / 1000000 + "M";
831 }
832 return text;
833 }
834
835 public static string ToFormat(this int a)
836 {
837 return $"{a:#,0}";
838 }
839
840 public static string ToFormat(this long a)
841 {
842 return $"{a:#,0}";
843 }
844
845 public static string ToText(this int a, bool skipIfZero = true)
846 {
847 object obj;
848 if (!(a == 0 && skipIfZero))
849 {
850 if (a >= 0)
851 {
852 return "+" + a;
853 }
854 obj = a.ToString();
855 if (obj == null)
856 {
857 return "";
858 }
859 }
860 else
861 {
862 obj = "";
863 }
864 return (string)obj;
865 }
866
867 public static string TagColor(this string s, Color c, string txt)
868 {
869 return s + "<color=" + c.ToHex() + ">" + txt + "</color>";
870 }
871
872 public static string TagColor(this string s, Color c)
873 {
874 return "<color=" + c.ToHex() + ">" + s + "</color>";
875 }
876
877 public static string TagSize(this string s, string txt, int size)
878 {
879 return s + "<size=" + size + ">" + txt + "</size>";
880 }
881
882 public static string TagSize(this string s, int size)
883 {
884 return "<size=" + size + ">" + s + "</size>";
885 }
886
887 public static string GetFullFileNameWithoutExtension(this FileInfo fileInfo)
888 {
889 return fileInfo.Directory.FullName + "/" + Path.GetFileNameWithoutExtension(fileInfo.Name);
890 }
891
892 public static string GetFullFileNameWithoutExtension(this string path)
893 {
894 return new FileInfo(path).GetFullFileNameWithoutExtension();
895 }
896
897 public static string AddArticle(this string s)
898 {
899 if (!Lang.setting.addArticle || s.Length < 1)
900 {
901 return s;
902 }
903 char c = s[0];
904 s = ((c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') ? "an " : "a ") + s;
905 return s;
906 }
907
908 public static string AddArticle(this string s, int num, ArticleStyle style = ArticleStyle.Default, string replace = null)
909 {
910 if (!Lang.setting.addArticle || s.Length < 1)
911 {
912 return s;
913 }
914 char c = s[0];
915 string text = ((num >= 2) ? (num.ToFormat() + " ") : ((c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') ? "an " : "a "));
916 if (num >= 2 && Lang.setting.pluralize)
917 {
918 s = ((replace.IsEmpty() || !s.Contains(replace) || s.Contains("limestone stone")) ? pluralizer.Pluralize(s) : s.Replace(replace, pluralizer.Pluralize(replace)));
919 }
920 return style switch
921 {
922 ArticleStyle.The => "_the".lang().ToTitleCase() + " " + ((num > 1) ? (num + " ") : "") + s,
923 ArticleStyle.None => ((num > 1) ? (num.ToFormat() + " ") : "") + s.ToTitleCase(),
924 _ => text + s,
925 };
926 }
927
928 public static string ToTitleCase(this string s, bool wholeText = false)
929 {
931 {
932 return s;
933 }
934 char[] array = s.ToCharArray();
935 bool flag = true;
936 for (int i = 0; i < array.Length; i++)
937 {
938 if (flag)
939 {
940 array[i] = char.ToUpper(array[i]);
941 flag = false;
942 }
943 if (!wholeText)
944 {
945 break;
946 }
947 if (array[i] == ' ')
948 {
949 flag = true;
950 }
951 }
952 return new string(array);
953 }
954
955 public static void LoopTail<T>(this List<T> list, bool vertical = false) where T : Selectable
956 {
957 if (list.Count > 1)
958 {
959 Navigation navigation = list[0].navigation;
960 Navigation navigation2 = list[list.Count - 1].navigation;
961 if (vertical)
962 {
963 navigation.selectOnUp = list[list.Count - 1];
964 navigation2.selectOnDown = list[0];
965 }
966 else
967 {
968 navigation.selectOnLeft = list[list.Count - 1];
969 navigation2.selectOnRight = list[0];
970 }
971 list[0].navigation = navigation;
972 list[list.Count - 1].navigation = navigation2;
973 }
974 }
975
976 public static void SetNavigation(this Component a, Component b, bool vertical = false)
977 {
978 if (!a || !b)
979 {
980 return;
981 }
982 Selectable component = a.GetComponent<Selectable>();
983 Selectable component2 = b.GetComponent<Selectable>();
984 if ((bool)component && (bool)component2)
985 {
986 Navigation navigation = component.navigation;
987 Navigation navigation2 = component2.navigation;
988 if (vertical)
989 {
990 navigation.selectOnUp = component2;
991 navigation2.selectOnDown = component;
992 }
993 else
994 {
995 navigation.selectOnLeft = component2;
996 navigation2.selectOnRight = component;
997 }
998 component.navigation = navigation;
999 component2.navigation = navigation2;
1000 }
1001 }
1002
1003 public static void LoopSelectable(this List<Selectable> sels, bool vertical = true, bool horizonal = true, bool asGroup = true)
1004 {
1005 for (int i = 0; i < sels.Count; i++)
1006 {
1007 Selectable selectable = sels[i];
1008 Selectable selectable2 = sels[0];
1009 Navigation navigation = selectable.navigation;
1010 if (horizonal)
1011 {
1012 navigation.selectOnRight = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1013 }
1014 if (asGroup)
1015 {
1016 for (int j = i + 1; j < sels.Count; j++)
1017 {
1018 if (sels[j].transform.position.y < selectable.transform.position.y)
1019 {
1020 selectable2 = sels[j];
1021 break;
1022 }
1023 }
1024 }
1025 else
1026 {
1027 selectable2 = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1028 }
1029 if (vertical)
1030 {
1031 navigation.selectOnDown = selectable2;
1032 }
1033 selectable.navigation = navigation;
1034 }
1035 for (int num = sels.Count - 1; num >= 0; num--)
1036 {
1037 Selectable selectable3 = sels[num];
1038 Selectable selectable4 = sels[sels.Count - 1];
1039 Navigation navigation2 = selectable3.navigation;
1040 if (horizonal)
1041 {
1042 navigation2.selectOnLeft = ((num > 0) ? sels[num - 1] : selectable4);
1043 }
1044 if (asGroup)
1045 {
1046 int num2 = sels.Count - 1;
1047 for (int num3 = num - 1; num3 >= 0; num3--)
1048 {
1049 if (sels[num3].transform.position.y > selectable3.transform.position.y)
1050 {
1051 num2 = num3;
1052 break;
1053 }
1054 }
1055 int num4 = num2;
1056 while (num4 >= 0 && !(sels[num4].transform.position.y > sels[num2].transform.position.y))
1057 {
1058 selectable4 = sels[num4];
1059 num4--;
1060 }
1061 }
1062 else
1063 {
1064 selectable4 = ((num > 0) ? sels[num - 1] : selectable4);
1065 }
1066 if (vertical)
1067 {
1068 navigation2.selectOnUp = ((selectable4 == selectable3) ? sels[sels.Count - 1] : selectable4);
1069 }
1070 navigation2.mode = Navigation.Mode.Explicit;
1071 selectable3.navigation = navigation2;
1072 }
1073 }
1074
1075 public static void LoopSelectable(this Transform l, bool vertical = true, bool horizonal = true, bool asGroup = true)
1076 {
1077 List<Selectable> list = l.GetComponentsInChildren<Selectable>().ToList();
1078 for (int num = list.Count - 1; num >= 0; num--)
1079 {
1080 if (!list[num].interactable || list[num].navigation.mode == Navigation.Mode.None)
1081 {
1082 list.RemoveAt(num);
1083 }
1084 }
1085 list.LoopSelectable(vertical, horizonal, asGroup);
1086 }
1087
1088 public static Color ToColor(this string s)
1089 {
1090 Color color = Color.white;
1091 ColorUtility.TryParseHtmlString("#" + s, out color);
1092 return color;
1093 }
1094
1095 public static void SetAlpha(this Image c, float a)
1096 {
1097 c.color = new Color(c.color.r, c.color.g, c.color.b, a);
1098 }
1099
1100 public static void SetAlpha(this RawImage c, float a)
1101 {
1102 c.color = new Color(c.color.r, c.color.g, c.color.b, a);
1103 }
1104
1105 public static Color SetAlpha(this Color c, float a)
1106 {
1107 c.a = a;
1108 return c;
1109 }
1110
1111 public static Color Multiply(this Color c, float mtp, float add)
1112 {
1113 return new Color(c.r * mtp + add, c.g * mtp + add, c.b * mtp + add, c.a);
1114 }
1115
1116 public static string Tag(this Color c)
1117 {
1118 return "<color=" + $"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}" + ">";
1119 }
1120
1121 public static string ToHex(this Color c)
1122 {
1123 return $"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}";
1124 }
1125
1126 public static void SetOnClick(this Button b, Action action)
1127 {
1128 b.onClick.RemoveAllListeners();
1129 b.onClick.AddListener(delegate
1130 {
1131 action();
1132 });
1133 }
1134
1135 public static void SetListener(this Button.ButtonClickedEvent e, Action action)
1136 {
1137 e.RemoveAllListeners();
1138 e.AddListener(delegate
1139 {
1140 action();
1141 });
1142 }
1143
1144 public static void SetAlpha(this Text text, float aloha = 1f)
1145 {
1146 text.color = new Color(text.color.r, text.color.g, text.color.b, aloha);
1147 }
1148
1149 public static void SetSlider(this Slider slider, float value, Func<float, string> action, bool notify)
1150 {
1151 slider.SetSlider(value, action, -1, -1, notify);
1152 }
1153
1154 public static void SetSlider(this Slider slider, float value, Func<float, string> action, int min = -1, int max = -1, bool notify = true)
1155 {
1156 slider.onValueChanged.RemoveAllListeners();
1157 slider.onValueChanged.AddListener(delegate(float a)
1158 {
1159 slider.GetComponentInChildren<Text>(includeInactive: true).text = action(a);
1160 });
1161 if (min != -1)
1162 {
1163 slider.minValue = min;
1164 slider.maxValue = max;
1165 }
1166 if (notify)
1167 {
1168 slider.value = value;
1169 }
1170 else
1171 {
1172 slider.SetValueWithoutNotify(value);
1173 }
1174 slider.GetComponentInChildren<Text>(includeInactive: true).text = action(value);
1175 }
1176
1177 public static T GetOrCreate<T>(this Component t) where T : Component
1178 {
1179 T val = t.gameObject.GetComponent<T>();
1180 if (!val)
1181 {
1182 val = t.gameObject.AddComponent<T>();
1183 }
1184 return val;
1185 }
1186
1187 public static RectTransform Rect(this Component c)
1188 {
1189 return c.transform as RectTransform;
1190 }
1191
1192 public static void CopyRect(this RectTransform r, RectTransform t)
1193 {
1194 r.pivot = t.pivot;
1195 r.sizeDelta = t.sizeDelta;
1196 r.anchorMin = t.anchorMin;
1197 r.anchorMax = t.anchorMax;
1198 r.anchoredPosition = t.anchoredPosition;
1199 }
1200
1201 public static void ToggleActive(this Component c)
1202 {
1203 c.SetActive(!c.gameObject.activeSelf);
1204 }
1205
1206 public static void SetActive(this Component c, bool enable)
1207 {
1208 if (c.gameObject.activeSelf != enable)
1209 {
1210 c.gameObject.SetActive(enable);
1211 }
1212 }
1213
1214 public static void SetActive(this Component c, bool enable, Action<bool> onChangeState)
1215 {
1216 if (c.gameObject.activeSelf != enable)
1217 {
1218 c.gameObject.SetActive(enable);
1219 onChangeState(enable);
1220 }
1221 }
1222
1223 public static Selectable GetSelectable(this GameObject go)
1224 {
1225 return go.GetComponentInChildren<Selectable>();
1226 }
1227
1228 public static void SetLayerRecursively(this GameObject obj, int layer)
1229 {
1230 obj.layer = layer;
1231 foreach (Transform item in obj.transform)
1232 {
1233 item.gameObject.SetLayerRecursively(layer);
1234 }
1235 }
1236
1237 public static bool IsInteractable(this GameObject obj)
1238 {
1239 Selectable selectable = (obj ? obj.GetComponent<Selectable>() : null);
1240 if ((bool)selectable)
1241 {
1242 return selectable.interactable;
1243 }
1244 return false;
1245 }
1246
1247 public static bool IsChildOf(this GameObject c, GameObject root)
1248 {
1249 if (c.transform == root.transform)
1250 {
1251 return true;
1252 }
1253 if ((bool)c.transform.parent)
1254 {
1255 return c.transform.parent.gameObject.IsChildOf(root);
1256 }
1257 return false;
1258 }
1259
1260 public static bool IsPrefab(this Component c)
1261 {
1262 return c.gameObject.scene.name == null;
1263 }
1264
1265 public static T CreateMold<T>(this Component c, string name = null) where T : Component
1266 {
1267 T result = null;
1268 for (int i = 0; i < c.transform.childCount; i++)
1269 {
1270 T component = c.transform.GetChild(i).GetComponent<T>();
1271 if ((bool)component && (name.IsEmpty() || name == component.name))
1272 {
1273 component.gameObject.SetActive(value: false);
1274 result = component;
1275 break;
1276 }
1277 }
1278 c.DestroyChildren();
1279 return result;
1280 }
1281
1282 public static Transform Find(this Component c, string name = null)
1283 {
1284 return c.Find<Transform>(name);
1285 }
1286
1287 public static T Find<T>(this Component c, string name = null, bool recursive = false) where T : Component
1288 {
1289 if (recursive)
1290 {
1291 T[] componentsInChildren = c.transform.GetComponentsInChildren<T>();
1292 foreach (T val in componentsInChildren)
1293 {
1294 if (name == null || name == val.name)
1295 {
1296 return val;
1297 }
1298 }
1299 return null;
1300 }
1301 for (int j = 0; j < c.transform.childCount; j++)
1302 {
1303 T component = c.transform.GetChild(j).GetComponent<T>();
1304 if ((bool)component && (name == null || name == component.name))
1305 {
1306 return component;
1307 }
1308 }
1309 return null;
1310 }
1311
1312 public static GameObject FindTagInParents(this Component c, string tag, bool includeInactive = true)
1313 {
1314 Transform transform = c.transform;
1315 for (int i = 0; i < transform.childCount; i++)
1316 {
1317 Transform child = transform.GetChild(i);
1318 if ((includeInactive || child.gameObject.activeSelf) && child.tag == tag)
1319 {
1320 return child.gameObject;
1321 }
1322 }
1323 if ((bool)transform.parent)
1324 {
1325 return transform.parent.FindTagInParents(tag, includeInactive);
1326 }
1327 return null;
1328 }
1329
1330 public static T GetComponentInChildrenExcludSelf<T>(this Transform c) where T : Component
1331 {
1332 for (int i = 0; i < c.childCount; i++)
1333 {
1334 T component = c.GetChild(i).GetComponent<T>();
1335 if ((bool)component)
1336 {
1337 return component;
1338 }
1339 }
1340 return null;
1341 }
1342
1343 public static List<T> GetComponentsInDirectChildren<T>(this Transform comp, bool includeInactive = true) where T : Component
1344 {
1345 List<T> list = new List<T>();
1346 Transform transform = comp.transform;
1347 for (int i = 0; i < transform.childCount; i++)
1348 {
1349 T component = transform.GetChild(i).GetComponent<T>();
1350 if ((bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1351 {
1352 list.Add(component);
1353 }
1354 }
1355 return list;
1356 }
1357
1358 public static List<T> GetComponentsInDirectChildren<T>(this Component comp, bool includeInactive = true) where T : Component
1359 {
1360 List<T> list = new List<T>();
1361 Transform transform = comp.transform;
1362 for (int i = 0; i < transform.childCount; i++)
1363 {
1364 T component = transform.GetChild(i).GetComponent<T>();
1365 if ((bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1366 {
1367 list.Add(component);
1368 }
1369 }
1370 return list;
1371 }
1372
1373 public static T GetComponentInDirectChildren<T>(this Component comp) where T : Component
1374 {
1375 Transform transform = comp.transform;
1376 for (int i = 0; i < transform.childCount; i++)
1377 {
1378 T component = transform.GetChild(i).GetComponent<T>();
1379 if ((bool)component)
1380 {
1381 return component;
1382 }
1383 }
1384 return null;
1385 }
1386
1387 public static void DestroyChildren(this Component component, bool destroyInactive = false, bool ignoreDestroy = true)
1388 {
1389 if (!component || !component.transform)
1390 {
1391 Debug.LogWarning("DestroyChlidren:" + component);
1392 return;
1393 }
1394 for (int num = component.transform.childCount - 1; num >= 0; num--)
1395 {
1396 GameObject gameObject = component.transform.GetChild(num).gameObject;
1397 if ((!ignoreDestroy || !(gameObject.tag == "IgnoreDestroy")) && (destroyInactive || gameObject.activeSelf))
1398 {
1399 UnityEngine.Object.DestroyImmediate(gameObject);
1400 }
1401 }
1402 }
1403
1404 public static bool IsMouseOver(this RectTransform r, Camera cam)
1405 {
1406 return RectTransformUtility.RectangleContainsScreenPoint(r, Input.mousePosition, cam);
1407 }
1408
1409 public static void RebuildLayout(this Component c, bool recursive = false)
1410 {
1411 if (recursive)
1412 {
1413 foreach (Transform item in c.transform)
1414 {
1415 if (item is RectTransform)
1416 {
1417 item.RebuildLayout(recursive: true);
1418 }
1419 }
1420 }
1421 LayoutRebuilder.ForceRebuildLayoutImmediate(c.transform as RectTransform);
1422 }
1423
1424 public static void RebuildLayoutTo<T>(this Component c) where T : Component
1425 {
1426 c.RebuildLayout();
1427 if ((bool)c.transform.parent && !c.transform.parent.GetComponent<T>())
1428 {
1429 c.transform.parent.RebuildLayoutTo<T>();
1430 }
1431 }
1432
1433 public static void RebuildLayoutTo(this Component c, Component target)
1434 {
1435 c.RebuildLayout();
1436 if (!(c == target) && (bool)c.transform.parent)
1437 {
1438 c.transform.parent.RebuildLayoutTo(target);
1439 }
1440 }
1441
1442 public static void SetRect(this RectTransform r, float x, float y, float w, float h, float pivotX, float pivotY, float minX, float minY, float maxX, float maxY)
1443 {
1444 r.SetPivot(pivotX, pivotY);
1445 r.SetAnchor(minX, minY, maxX, maxY);
1446 if (w != -1f)
1447 {
1448 r.sizeDelta = new Vector2(w, h);
1449 }
1450 r.anchoredPosition = new Vector2((x == -1f) ? r.anchoredPosition.x : x, (y == -1f) ? r.anchoredPosition.y : y);
1451 }
1452
1453 public static void SetPivot(this RectTransform r, float x, float y)
1454 {
1455 r.pivot = new Vector2(x, y);
1456 }
1457
1458 public static void SetAnchor(this RectTransform r, float minX, float minY, float maxX, float maxY)
1459 {
1460 r.anchorMin = new Vector2(minX, minY);
1461 r.anchorMax = new Vector2(maxX, maxY);
1462 }
1463
1464 public static void _SetAnchor(this RectTransform _rect, RectPosition anchor)
1465 {
1466 switch (anchor)
1467 {
1468 case RectPosition.TopCenter:
1469 _rect.SetAnchor(0.5f, 1f, 0.5f, 1f);
1470 break;
1471 case RectPosition.BottomCenter:
1472 _rect.SetAnchor(0.5f, 0f, 0.5f, 0f);
1473 break;
1474 case RectPosition.TopLEFT:
1475 _rect.SetAnchor(0f, 1f, 0f, 1f);
1476 break;
1477 case RectPosition.TopRIGHT:
1478 _rect.SetAnchor(1f, 1f, 1f, 1f);
1479 break;
1480 case RectPosition.BottomLEFT:
1481 _rect.SetAnchor(0f, 0f, 0f, 0f);
1482 break;
1483 case RectPosition.BottomRIGHT:
1484 _rect.SetAnchor(1f, 0f, 1f, 0f);
1485 break;
1486 case RectPosition.Left:
1487 _rect.SetAnchor(0f, 0.5f, 0f, 0.5f);
1488 break;
1489 case RectPosition.Right:
1490 _rect.SetAnchor(1f, 0.5f, 1f, 0.5f);
1491 break;
1492 default:
1493 _rect.SetAnchor(0.5f, 0.5f, 0.5f, 0.5f);
1494 break;
1495 }
1496 }
1497
1498 public static void SetAnchor(this RectTransform _rect, RectPosition anchor = RectPosition.Auto)
1499 {
1500 Vector3 position = _rect.position;
1501 _rect._SetAnchor((anchor == RectPosition.Auto) ? _rect.GetAnchor() : anchor);
1502 _rect.position = position;
1503 }
1504
1505 public static RectPosition GetAnchor(this RectTransform _rect)
1506 {
1507 Vector3 position = _rect.position;
1508 int width = Screen.width;
1509 int height = Screen.height;
1510 bool flag = position.y > (float)height * 0.5f;
1511 if (position.x > (float)width * 0.3f && position.x < (float)width * 0.7f)
1512 {
1513 if (position.y > (float)height * 0.3f && position.y < (float)height * 0.7f)
1514 {
1515 return RectPosition.Center;
1516 }
1517 if (!flag)
1518 {
1519 return RectPosition.BottomCenter;
1520 }
1521 return RectPosition.TopCenter;
1522 }
1523 if (position.x < (float)width * 0.5f)
1524 {
1525 if (!flag)
1526 {
1527 return RectPosition.BottomLEFT;
1528 }
1529 return RectPosition.TopLEFT;
1530 }
1531 if (!flag)
1532 {
1533 return RectPosition.BottomRIGHT;
1534 }
1535 return RectPosition.TopRIGHT;
1536 }
1537
1538 public static Transform GetLastChild(this Transform trans)
1539 {
1540 return trans.GetChild(trans.childCount - 1);
1541 }
1542
1543 public static Vector2 ToVector2(this Vector3 self)
1544 {
1545 return new Vector2(self.x, self.z);
1546 }
1547
1548 public static void SetScale(this SpriteRenderer renderer, float size)
1549 {
1550 float x = renderer.bounds.size.x;
1551 float y = renderer.bounds.size.y;
1552 float x2 = size / x;
1553 float y2 = size / y;
1554 renderer.transform.localScale = new Vector3(x2, y2, 1f);
1555 }
1556
1557 private static float GetForwardDiffPoint(Vector2 forward)
1558 {
1559 if (object.Equals(forward, Vector2.up))
1560 {
1561 return 90f;
1562 }
1563 object.Equals(forward, Vector2.right);
1564 return 0f;
1565 }
1566
1567 public static void LookAt2D(this Transform self, Transform target, Vector2 forward)
1568 {
1569 self.LookAt2D(target.position, forward);
1570 }
1571
1572 public static void LookAt2D(this Transform self, Vector3 target, Vector2 forward)
1573 {
1574 float forwardDiffPoint = GetForwardDiffPoint(forward);
1575 Vector3 vector = target - self.position;
1576 float num = Mathf.Atan2(vector.y, vector.x) * 57.29578f;
1577 self.rotation = Quaternion.AngleAxis(num - forwardDiffPoint, Vector3.forward);
1578 }
1579
1580 public static float Distance(this Transform t, Vector2 pos)
1581 {
1582 return Vector3.Distance(t.position, pos);
1583 }
1584
1585 public static Vector3 Plus(this Vector3 v, Vector2 v2)
1586 {
1587 v.x += v2.x;
1588 v.y += v2.y;
1589 return v;
1590 }
1591
1592 public static Vector3 SetZ(this Vector3 v, float a)
1593 {
1594 v.z = a;
1595 return v;
1596 }
1597
1598 public static Vector3 SetY(this Vector3 v, float a)
1599 {
1600 v.y = a;
1601 return v;
1602 }
1603
1604 public static Vector3 PlusX(this Vector3 v, float a)
1605 {
1606 v.x += a;
1607 return v;
1608 }
1609
1610 public static Vector3 PlusY(this Vector3 v, float a)
1611 {
1612 v.y += a;
1613 return v;
1614 }
1615
1616 public static Vector3 PlusZ(this Vector3 v, float a)
1617 {
1618 v.z += a;
1619 return v;
1620 }
1621
1622 public static void SetPosition(this Transform transform, float x, float y, float z)
1623 {
1624 vector3.Set(x, y, z);
1625 transform.position = vector3;
1626 }
1627
1628 public static void SetPositionX(this Transform transform, float x)
1629 {
1630 vector3.Set(x, transform.position.y, transform.position.z);
1631 transform.position = vector3;
1632 }
1633
1634 public static void SetPositionY(this Transform transform, float y)
1635 {
1636 vector3.Set(transform.position.x, y, transform.position.z);
1637 transform.position = vector3;
1638 }
1639
1640 public static void SetPositionZ(this Transform transform, float z)
1641 {
1642 vector3.Set(transform.position.x, transform.position.y, z);
1643 transform.position = vector3;
1644 }
1645
1646 public static void AddPosition(this Transform transform, float x, float y, float z)
1647 {
1648 vector3.Set(transform.position.x + x, transform.position.y + y, transform.position.z + z);
1649 transform.position = vector3;
1650 }
1651
1652 public static void AddPositionX(this Transform transform, float x)
1653 {
1654 vector3.Set(transform.position.x + x, transform.position.y, transform.position.z);
1655 transform.position = vector3;
1656 }
1657
1658 public static void AddPositionY(this Transform transform, float y)
1659 {
1660 vector3.Set(transform.position.x, transform.position.y + y, transform.position.z);
1661 transform.position = vector3;
1662 }
1663
1664 public static void AddPositionZ(this Transform transform, float z)
1665 {
1666 vector3.Set(transform.position.x, transform.position.y, transform.position.z + z);
1667 transform.position = vector3;
1668 }
1669
1670 public static void SetLocalPosition(this Transform transform, float x, float y, float z)
1671 {
1672 vector3.Set(x, y, z);
1673 transform.localPosition = vector3;
1674 }
1675
1676 public static void SetLocalPositionX(this Transform transform, float x)
1677 {
1678 vector3.Set(x, transform.localPosition.y, transform.localPosition.z);
1679 transform.localPosition = vector3;
1680 }
1681
1682 public static void SetLocalPositionY(this Transform transform, float y)
1683 {
1684 vector3.Set(transform.localPosition.x, y, transform.localPosition.z);
1685 transform.localPosition = vector3;
1686 }
1687
1688 public static void SetLocalPositionZ(this Transform transform, float z)
1689 {
1690 vector3.Set(transform.localPosition.x, transform.localPosition.y, z);
1691 transform.localPosition = vector3;
1692 }
1693
1694 public static void AddLocalPosition(this Transform transform, float x, float y, float z)
1695 {
1696 vector3.Set(transform.localPosition.x + x, transform.localPosition.y + y, transform.localPosition.z + z);
1697 transform.localPosition = vector3;
1698 }
1699
1700 public static void AddLocalPositionX(this Transform transform, float x)
1701 {
1702 vector3.Set(transform.localPosition.x + x, transform.localPosition.y, transform.localPosition.z);
1703 transform.localPosition = vector3;
1704 }
1705
1706 public static void AddLocalPositionY(this Transform transform, float y)
1707 {
1708 vector3.Set(transform.localPosition.x, transform.localPosition.y + y, transform.localPosition.z);
1709 transform.localPosition = vector3;
1710 }
1711
1712 public static void AddLocalPositionZ(this Transform transform, float z)
1713 {
1714 vector3.Set(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + z);
1715 transform.localPosition = vector3;
1716 }
1717
1718 public static void SetLocalScale(this Transform transform, float x, float y, float z)
1719 {
1720 vector3.Set(x, y, z);
1721 transform.localScale = vector3;
1722 }
1723
1724 public static void SetLocalScaleX(this Transform transform, float x)
1725 {
1726 vector3.Set(x, transform.localScale.y, transform.localScale.z);
1727 transform.localScale = vector3;
1728 }
1729
1730 public static void SetLocalScaleY(this Transform transform, float y)
1731 {
1732 vector3.Set(transform.localScale.x, y, transform.localScale.z);
1733 transform.localScale = vector3;
1734 }
1735
1736 public static void SetLocalScaleZ(this Transform transform, float z)
1737 {
1738 vector3.Set(transform.localScale.x, transform.localScale.y, z);
1739 transform.localScale = vector3;
1740 }
1741
1742 public static void AddLocalScale(this Transform transform, float x, float y, float z)
1743 {
1744 vector3.Set(transform.localScale.x + x, transform.localScale.y + y, transform.localScale.z + z);
1745 transform.localScale = vector3;
1746 }
1747
1748 public static void AddLocalScaleX(this Transform transform, float x)
1749 {
1750 vector3.Set(transform.localScale.x + x, transform.localScale.y, transform.localScale.z);
1751 transform.localScale = vector3;
1752 }
1753
1754 public static void AddLocalScaleY(this Transform transform, float y)
1755 {
1756 vector3.Set(transform.localScale.x, transform.localScale.y + y, transform.localScale.z);
1757 transform.localScale = vector3;
1758 }
1759
1760 public static void AddLocalScaleZ(this Transform transform, float z)
1761 {
1762 vector3.Set(transform.localScale.x, transform.localScale.y, transform.localScale.z + z);
1763 transform.localScale = vector3;
1764 }
1765
1766 public static void SetEulerAngles(this Transform transform, float x, float y, float z)
1767 {
1768 vector3.Set(x, y, z);
1769 transform.eulerAngles = vector3;
1770 }
1771
1772 public static void SetEulerAnglesX(this Transform transform, float x)
1773 {
1774 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1775 transform.eulerAngles = vector3;
1776 }
1777
1778 public static void SetEulerAnglesY(this Transform transform, float y)
1779 {
1780 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1781 transform.eulerAngles = vector3;
1782 }
1783
1784 public static void SetEulerAnglesZ(this Transform transform, float z)
1785 {
1786 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1787 transform.eulerAngles = vector3;
1788 }
1789
1790 public static void AddEulerAngles(this Transform transform, float x, float y, float z)
1791 {
1792 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y + y, transform.eulerAngles.z + z);
1793 transform.eulerAngles = vector3;
1794 }
1795
1796 public static void AddEulerAnglesX(this Transform transform, float x)
1797 {
1798 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y, transform.eulerAngles.z);
1799 transform.eulerAngles = vector3;
1800 }
1801
1802 public static void AddEulerAnglesY(this Transform transform, float y)
1803 {
1804 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y + y, transform.eulerAngles.z);
1805 transform.eulerAngles = vector3;
1806 }
1807
1808 public static void AddEulerAnglesZ(this Transform transform, float z)
1809 {
1810 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z + z);
1811 transform.eulerAngles = vector3;
1812 }
1813
1814 public static void SetLocalEulerAngles(this Transform transform, float x, float y, float z)
1815 {
1816 vector3.Set(x, y, z);
1817 transform.localEulerAngles = vector3;
1818 }
1819
1820 public static void SetLocalEulerAnglesX(this Transform transform, float x)
1821 {
1822 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1823 transform.localEulerAngles = vector3;
1824 }
1825
1826 public static void SetLocalEulerAnglesY(this Transform transform, float y)
1827 {
1828 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1829 transform.localEulerAngles = vector3;
1830 }
1831
1832 public static void SetLocalEulerAnglesZ(this Transform transform, float z)
1833 {
1834 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1835 transform.localEulerAngles = vector3;
1836 }
1837
1838 public static void AddLocalEulerAngles(this Transform transform, float x, float y, float z)
1839 {
1840 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y + y, transform.localEulerAngles.z + z);
1841 transform.localEulerAngles = vector3;
1842 }
1843
1844 public static void AddLocalEulerAnglesX(this Transform transform, float x)
1845 {
1846 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1847 transform.localEulerAngles = vector3;
1848 }
1849
1850 public static void AddLocalEulerAnglesY(this Transform transform, float y)
1851 {
1852 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y + y, transform.localEulerAngles.z);
1853 transform.localEulerAngles = vector3;
1854 }
1855
1856 public static void AddLocalEulerAnglesZ(this Transform transform, float z)
1857 {
1858 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z + z);
1859 transform.localEulerAngles = vector3;
1860 }
1861
1862 public static void ToggleKeyword(this Material m, string id, bool enable)
1863 {
1864 if (enable)
1865 {
1866 m.EnableKeyword(id);
1867 }
1868 else
1869 {
1870 m.DisableKeyword(id);
1871 }
1872 }
1873
1874 public static void ForeachReverse<T>(this IList<T> items, Action<T> action)
1875 {
1876 for (int num = items.Count - 1; num >= 0; num--)
1877 {
1878 action(items[num]);
1879 }
1880 }
1881
1882 public static void ForeachReverse<T>(this IList<T> items, Func<T, bool> action)
1883 {
1884 int num = items.Count - 1;
1885 while (num >= 0 && !action(items[num]))
1886 {
1887 num--;
1888 }
1889 }
1890
1891 public static float ClampAngle(this float angle)
1892 {
1893 if (angle < 0f)
1894 {
1895 return 360f - (0f - angle) % 360f;
1896 }
1897 return angle % 360f;
1898 }
1899
1900 public static Vector3 Random(this Vector3 v)
1901 {
1902 return new Vector3(Rand.Range(0f - v.x, v.x), Rand.Range(0f - v.y, v.y), Rand.Range(0f - v.z, v.z));
1903 }
1904
1905 public static T Instantiate<T>(this T s) where T : ScriptableObject
1906 {
1907 string name = s.name;
1908 T val = UnityEngine.Object.Instantiate(s);
1909 val.name = name;
1910 return val;
1911 }
1912
1913 public static int GetRuntimeEventCount(this UnityEventBase unityEvent)
1914 {
1915 Type typeFromHandle = typeof(UnityEventBase);
1916 Assembly assembly = Assembly.GetAssembly(typeFromHandle);
1917 Type type = assembly.GetType("UnityEngine.Events.InvokableCallList");
1918 Type type2 = assembly.GetType("UnityEngine.Events.BaseInvokableCall");
1919 Type type3 = typeof(List<>).MakeGenericType(type2);
1920 FieldInfo field = typeFromHandle.GetField("m_Calls", BindingFlags.Instance | BindingFlags.NonPublic);
1921 FieldInfo field2 = type.GetField("m_RuntimeCalls", BindingFlags.Instance | BindingFlags.NonPublic);
1922 object value = field.GetValue(unityEvent);
1923 object value2 = field2.GetValue(value);
1924 return (int)type3.GetProperty("Count").GetValue(value2, null);
1925 }
1926}
ArticleStyle
Definition: ArticleStyle.cs:2
RectPosition
Definition: RectPosition.cs:2
static string TryAddExtension(this string s, string ext)
static string StripLastPun(this string str)
static byte SetBit(this byte pByte, int bitNo, bool value)
static T GetComponentInChildrenExcludSelf< T >(this Transform c)
static int[] SplitToInts(this string str, char separator)
static void SetEulerAnglesZ(this Transform transform, float z)
static T CreateMold< T >(this Component c, string name=null)
static void SetAnchor(this RectTransform r, float minX, float minY, float maxX, float maxY)
static T GetField< T >(this object o, string name)
static void SetPosition(this Transform transform, float x, float y, float z)
static string TagColor(this string s, Color c, string txt)
static void SetEulerAnglesX(this Transform transform, float x)
static int NextIndex< TValue >(this IList< TValue > source, TValue val)
static int ClampMax(this int v, int max)
static void Each< TValue >(this IList< TValue > list, Action< TValue > action)
static void AddLocalPosition(this Transform transform, float x, float y, float z)
static T PrevEnum< T >(this T src)
static string langGame(this string s, string ref1, string ref2=null, string ref3=null, string ref4=null)
static Vector3 vector3
static TKey[] CopyKeys< TKey, TValue >(this IDictionary< TKey, TValue > dict)
static void AddLocalEulerAnglesY(this Transform transform, float y)
static IList< TValue > Shuffle< TValue >(this IList< TValue > list)
static string Parentheses(this string str)
static void AddLocalScale(this Transform transform, float x, float y, float z)
static string ToTitleCase(this string s, bool wholeText=false)
static T Find< T >(this Component c, string name=null, bool recursive=false)
static TValue Clamp< TValue >(this IList< TValue > source, int i)
static TValue TryGetValue< TKey, TValue >(this IDictionary< TKey, TValue > source, TKey key, TValue fallback=default(TValue))
static void SetLocalEulerAngles(this Transform transform, float x, float y, float z)
static string ToFormat(this int a)
static void LoopSelectable(this List< Selectable > sels, bool vertical=true, bool horizonal=true, bool asGroup=true)
static string langPlural(this string s, int i)
static void SetScale(this SpriteRenderer renderer, float size)
static int ToInt(this string str, Type type)
static float GetForwardDiffPoint(Vector2 forward)
static T ToEnum< T >(this int value)
static bool IsChildOf(this GameObject c, GameObject root)
static int Calc(this string str, int power=0, int ele=0, int p2=0)
static void AddLocalScaleY(this Transform transform, float y)
static void SetSlider(this Slider slider, float value, Func< float, string > action, int min=-1, int max=-1, bool notify=true)
static string StripPun(this string str, bool stripComma, bool insertSpaceForComma=false)
static int IndexOf(this IList< Component > list, GameObject go)
static Vector3 SetY(this Vector3 v, float a)
static void AddPositionX(this Transform transform, float x)
static void LoopTail< T >(this List< T > list, bool vertical=false)
static T GetOrCreate< T >(this Component t)
static bool IsOn(this int data, int digit)
static IList< TValue > Copy< TValue >(this IList< TValue > list)
static float FromInt2(this int a)
static Selectable GetSelectable(this GameObject go)
static string AddArticle(this string s, int num, ArticleStyle style=ArticleStyle.Default, string replace=null)
static void SetLocalPositionZ(this Transform transform, float z)
static void SetLocalEulerAnglesZ(this Transform transform, float z)
static void RebuildLayoutTo(this Component c, Component target)
static bool IsEmpty(this string str)
static bool IsPrefab(this Component c)
static void SetActive(this Component c, bool enable)
static void ToDictionary< T >(this IList< UPair< T > > list, ref Dictionary< string, T > dic)
static void AddEulerAnglesZ(this Transform transform, float z)
static void SetProperty< T >(this object o, string name, T value)
static bool Within(this byte v, byte v2, byte range)
static void SetAlpha(this Text text, float aloha=1f)
static void ToggleActive(this Component c)
static bool Contains(this string[] strs, string id)
static int GetRuntimeEventCount(this UnityEventBase unityEvent)
static void SetLayerRecursively(this GameObject obj, int layer)
static void SetActive(this Component c, bool enable, Action< bool > onChangeState)
static void SetLocalEulerAnglesY(this Transform transform, float y)
static bool Within(this int v, int v2, int range)
static Vector2 ToVector2(this Vector3 self)
static void LoopSelectable(this Transform l, bool vertical=true, bool horizonal=true, bool asGroup=true)
static Color ToColor(this string s)
static void AddLocalEulerAnglesX(this Transform transform, float x)
static void SetLocalPosition(this Transform transform, float x, float y, float z)
static void AddPositionY(this Transform transform, float y)
static RectPosition GetAnchor(this RectTransform _rect)
static bool GetBit(this byte pByte, int bitNo)
static void ToggleKeyword(this Material m, string id, bool enable)
static string Tag(this Color c)
static T NextEnum< T >(this T src)
static void SetPositionX(this Transform transform, float x)
static void SetLocalScaleX(this Transform transform, float x)
static TValue GetOrCreate< TKey, TValue >(this IDictionary< TKey, TValue > dict, TKey key, Func< TValue > func=null)
static Vector3 PlusY(this Vector3 v, float a)
static bool IsEmpty(this Array array)
static T GetProperty< T >(this object o, string name)
static void SetLocalPositionX(this Transform transform, float x)
static void SetLocalEulerAnglesX(this Transform transform, float x)
static float Distance(this Transform t, Vector2 pos)
static void AddLocalScaleX(this Transform transform, float x)
static float FromInt3(this int a)
static void AddEulerAngles(this Transform transform, float x, float y, float z)
static string TagSize(this string s, int size)
static void AddLocalScaleZ(this Transform transform, float z)
static void SetAlpha(this RawImage c, float a)
static void AddEulerAnglesX(this Transform transform, float x)
static Transform Find(this Component c, string name=null)
static void DestroyChildren(this Component component, bool destroyInactive=false, bool ignoreDestroy=true)
static bool IsInteractable(this GameObject obj)
static void Sort< T >(this IList< T > list, Comparison< T > comparison)
static int ToInt3(this float a)
static TValue RandomItem< TKey, TValue >(this IDictionary< TKey, TValue > source)
static string StripBrackets(this string str)
static string ToHex(this Color c)
static TValue RandomItemWeighted< TValue >(this IList< TValue > source, Func< TValue, float > getWeight)
static string lang(this string s)
static float ToFloat(this string str)
static Vector3 SetZ(this Vector3 v, float a)
static void AddLocalEulerAnglesZ(this Transform transform, float z)
static bool IsNull(this object o)
static void SetAlpha(this Image c, float a)
static void SetAnchor(this RectTransform _rect, RectPosition anchor=RectPosition.Auto)
static bool IsMouseOver(this RectTransform r, Camera cam)
static Vector3 PlusX(this Vector3 v, float a)
static List< T > GetComponentsInDirectChildren< T >(this Transform comp, bool includeInactive=true)
static void SetSlider(this Slider slider, float value, Func< float, string > action, bool notify)
static string langGame(this string s)
static void SetNavigation(this Component a, Component b, bool vertical=false)
static TValue RandomItem< TValue >(this IList< TValue > source)
static void AddLocalEulerAngles(this Transform transform, float x, float y, float z)
static int ClampMin(this int v, int min)
static TValue FirstItem< TKey, TValue >(this IDictionary< TKey, TValue > source)
static void SetPivot(this RectTransform r, float x, float y)
static TValue NextItem< TValue >(this IList< TValue > source, ref int index)
static T FindMax< T >(this List< T > list, Func< T, int > func)
static void SetField< T >(this object o, string name, T value)
static TValue TryGet< TValue >(this IList< TValue > array, int index, int defIndex=-1)
static TValue Move< TValue >(this IList< TValue > list, TValue target, int a)
static T GetComponentInDirectChildren< T >(this Component comp)
static void SetRect(this RectTransform r, float x, float y, float w, float h, float pivotX, float pivotY, float minX, float minY, float maxX, float maxY)
static Type ToType(this string value)
static void ForeachReverse< T >(this IList< T > items, Action< T > action)
static TValue PrevItem< TValue >(this IList< TValue > source, TValue val)
static void RebuildLayout(this Component c, bool recursive=false)
static Vector3 Plus(this Vector3 v, Vector2 v2)
static GameObject FindTagInParents(this Component c, string tag, bool includeInactive=true)
static string GetFullFileNameWithoutExtension(this string path)
static int ToInt< T >(this string str)
static string ToShortNumber(this int a)
static void SetEulerAnglesY(this Transform transform, float y)
static IPluralize pluralizer
static void AddLocalPositionX(this Transform transform, float x)
static string IsEmpty(this string str, string defaultStr)
static void Set< T1, T2 >(this Dictionary< T1, T2 > dic, Dictionary< T1, T2 > from)
static T RandomItem< T >(this IEnumerable< T > ie)
static T Instantiate< T >(this T s)
static string TagSize(this string s, string txt, int size)
static string Repeat(this string str, int count)
static Transform GetLastChild(this Transform trans)
static int ToInt(this string str)
static void SetPositionY(this Transform transform, float y)
static string ToFormat(this long a)
static string ToText(this int a, bool skipIfZero=true)
static void _SetAnchor(this RectTransform _rect, RectPosition anchor)
static Vector3 Random(this Vector3 v)
static string GetFullFileNameWithoutExtension(this FileInfo fileInfo)
static void SetListener(this Button.ButtonClickedEvent e, Action action)
static void RebuildLayoutTo< T >(this Component c)
static void SetOnClick(this Button b, Action action)
static string Bracket(this string str, int type=0)
static void AddPosition(this Transform transform, float x, float y, float z)
static RectTransform Rect(this Component c)
static void AddLocalPositionZ(this Transform transform, float z)
static string Evalute(this string[] array, float val)
static string lang(this string s, string ref1, string ref2=null, string ref3=null, string ref4=null, string ref5=null)
static int Minimum(this int i)
static void LookAt2D(this Transform self, Transform target, Vector2 forward)
static void SetLocalScaleZ(this Transform transform, float z)
static void SetEulerAngles(this Transform transform, float x, float y, float z)
static float ClampAngle(this float angle)
static int Clamp(this int v, int min, int max, bool loop=false)
static string TrimNewLines(this string text)
static string TagColor(this string s, Color c)
static string[] SplitNewline(this string str)
static void CopyRect(this RectTransform r, RectTransform t)
static Color Multiply(this Color c, float mtp, float add)
static TValue[] CopyValues< TKey, TValue >(this IDictionary< TKey, TValue > dict)
static void SetLocalPositionY(this Transform transform, float y)
static Vector3 PlusZ(this Vector3 v, float a)
static void SetPositionZ(this Transform transform, float z)
static Color SetAlpha(this Color c, float a)
static void SetLocalScaleY(this Transform transform, float y)
static TValue LastItem< TValue >(this IList< TValue > source)
static byte[] ToBytes(this BitArray bits)
static T ToField< T >(this string s, object o)
static void SetLocalScale(this Transform transform, float x, float y, float z)
static string AddArticle(this string s)
static TValue Remainder< TValue >(this IList< TValue > source, int divider)
static int ToInt2(this float a)
static List< T > GetList< T >(this IDictionary source)
static void AddLocalPositionY(this Transform transform, float y)
static void AddPositionZ(this Transform transform, float z)
static bool HasField< T >(this object o, string name)
static void AddEulerAnglesY(this Transform transform, float y)
static void LookAt2D(this Transform self, Vector3 target, Vector2 forward)
bool pluralize
Definition: LangSetting.cs:32
bool addArticle
Definition: LangSetting.cs:30
bool capitalize
Definition: LangSetting.cs:34
char period
Definition: Lang.cs:19
char comma
Definition: Lang.cs:17
Definition: Lang.cs:6
static Words words
Definition: Lang.cs:26
static LangSetting setting
Definition: Lang.cs:54
static string Get(string id)
Definition: Lang.cs:91
static LangGame Game
Definition: Lang.cs:48
static string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null, string val5=null)
Definition: Lang.cs:147
Definition: Rand.cs:4
static Random _random
Definition: Rand.cs:7
static int Range(int min, int max)
Definition: Rand.cs:42
static int rnd(int max)
Definition: Rand.cs:52
string Get(string id)
Definition: SourceLang.cs:12
string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null)
Definition: SourceLang.cs:43
Definition: UPair.cs:5
void SetInt(int i)
Definition: BitArray32.cs:89