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