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