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