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