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