2using System.Collections;
3using System.Collections.Generic;
6using System.Reflection;
8using System.Text.RegularExpressions;
10using Unity.Collections.LowLevel.Unsafe;
12using UnityEngine.Events;
19 public static readonly
bool IsInt = typeof(T).IsEnum && Enum.GetUnderlyingType(typeof(T)) == typeof(
int);
21 public static readonly
bool IsLong = typeof(T).IsEnum && Enum.GetUnderlyingType(typeof(T)) == typeof(
long);
26 public static readonly Dictionary<string, T>
cached;
28 public static readonly Dictionary<string, T>
fuzzy;
32 cached =
new Dictionary<string, T>();
33 fuzzy =
new Dictionary<string, T>(StringComparer.OrdinalIgnoreCase);
34 string[] names = Enum.GetNames(typeof(T));
35 foreach (
string text
in names)
37 T value = (T)Enum.Parse(typeof(T), text);
39 fuzzy.TryAdd(text, value);
48 public static string lang(
this string s)
59 public static string lang(
this string s,
string ref1,
string ref2 =
null,
string ref3 =
null,
string ref4 =
null,
string ref5 =
null)
61 return Lang.
Parse(s, ref1, ref2, ref3, ref4, ref5);
74 public static string langGame(
this string s,
string ref1,
string ref2 =
null,
string ref3 =
null,
string ref4 =
null)
81 return "(" + str +
")";
84 public static string Bracket(
this string str,
int type = 0)
97 return list[0] + str + list[1];
100 return "_bracketLeft".lang() + str +
"_bracketRight".lang();
104 public static byte[]
ToBytes(
this BitArray bits)
106 byte[] array =
new byte[(bits.Length - 1) / 8 + 1];
107 bits.CopyTo(array, 0);
111 public static bool GetBit(
this byte pByte,
int bitNo)
113 return (pByte & (1 << bitNo)) != 0;
116 public static byte SetBit(
this byte pByte,
int bitNo,
bool value)
120 return Convert.ToByte(pByte & ~(1 << bitNo));
122 return Convert.ToByte(pByte | (1 << bitNo));
127 return (
int)(a * 1000f);
132 return (
float)a / 1000f;
137 return (
int)(a * 100f);
142 return (
float)a / 100f;
163 public static bool IsOn(
this int data,
int digit)
167 return bitArray[digit];
174 return (T)Enum.ToObject(typeof(T), value);
176 return UnsafeUtility.As<int, T>(ref value);
183 return (T)Enum.ToObject(typeof(T), value);
185 return UnsafeUtility.As<long, T>(ref value);
188 public static T
ToEnum<T>(
this string value,
bool ignoreCase =
true)
190 if (
EnumNames<T>.cached.TryGetValue(value, out var value2))
194 if (ignoreCase &&
EnumNames<T>.fuzzy.TryGetValue(value, out value2))
198 return (T)Enum.Parse(typeof(T), value, ignoreCase);
201 public static Type
ToType(
this string value)
203 return Type.GetType(
"Elona." + value +
", Assembly-CSharp");
208 return ((T[])Enum.GetValues(src.GetType())).NextItem(src);
213 return ((T[])Enum.GetValues(src.GetType())).PrevItem(src);
216 public static bool Within(
this int v,
int v2,
int range)
220 return v - v2 < -range;
225 public static bool Within(
this byte v,
byte v2,
byte range)
229 return v - v2 < -range;
234 public static int Clamp(
this int v,
int min,
int max,
bool loop =
false)
238 v = ((!loop) ? min : max);
242 v = ((!loop) ? max : min);
267 return (T)o.GetType().GetField(s).GetValue(o);
272 FieldInfo field = o.GetType().GetField(name);
275 return typeof(T).IsAssignableFrom(field.FieldType);
282 return (T)o.GetType().GetField(name).GetValue(o);
285 public static void SetField<T>(
this object o,
string name, T value)
287 o.GetType().GetField(name).SetValue(o, value);
292 return (T)o.GetType().GetProperty(name).GetValue(o);
297 o.GetType().GetProperty(name).SetValue(o, value);
300 public static void Sort<T>(
this IList<T> list, Comparison<T> comparison)
304 ((List<T>)list).Sort(comparison);
307 List<T> list2 =
new List<T>(list);
308 list2.Sort(comparison);
309 for (
int i = 0; i < list.Count; i++)
315 public static void Sort<T>(
this IList<T> list, Func<T, int> keySelector)
317 List<T> list2 = list.OrderBy(keySelector).ToList();
319 foreach (T
item in list2)
325 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
int defIndex = -1)
327 if (array.Count != 0)
329 if (index >= array.Count)
333 if (array.Count <= defIndex)
335 return array[Mathf.Max(0, array.Count - 1)];
337 return array[defIndex];
339 return array[Mathf.Max(0, array.Count - 1)];
341 return array[Math.Max(0, index)];
343 return default(TValue);
346 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
bool returnNull)
348 if (index >= array.Count)
350 return default(TValue);
359 return array.Length == 0;
364 public static int IndexOf(
this IList<Component> list, GameObject go)
370 for (
int i = 0; i < list.Count; i++)
372 if (list[i].gameObject == go)
380 public static TValue
Move<TValue>(
this IList<TValue> list, TValue target,
int a)
382 int num = list.IndexOf(target);
386 num2 = list.Count - 1;
388 if (num2 >= list.Count)
393 list.Insert(num2, target);
399 return list.ToList();
402 public static void Each<TValue>(
this IList<TValue> list, Action<TValue> action)
404 for (
int num = list.Count - 1; num >= 0; num--)
412 int num = list.Count;
417 TValue value = list[num];
418 list[num] = list[index];
426 TValue value =
default(TValue);
427 if (key !=
null && source.TryGetValue(key, out value))
436 TValue value =
default(TValue);
437 if (key !=
null && source.TryGetValue(key, out value))
441 return source[key_fallback];
446 TValue val = dict.TryGetValue(key);
449 val = ((func !=
null) ? func() : Activator.CreateInstance<TValue>());
457 TKey[] array =
new TKey[dict.Keys.Count];
458 dict.Keys.CopyTo(array, 0);
464 TValue[] array =
new TValue[dict.Keys.Count];
465 dict.Values.CopyTo(array, 0);
471 int num = ie.Count();
476 return ie.ElementAt(
Rand.
rnd(num));
481 if (source.Count != 0)
483 return source.ElementAt(
Rand.
rnd(source.Count)).Value;
485 return default(TValue);
490 if (source.Count != 0)
492 return source[
Rand.
rnd(source.Count)];
494 return default(TValue);
499 return source.RandomItem(source.IndexOf(exclude));
504 if (source.Count > 1)
511 while (num == exclude);
514 if (source.Count == 1)
518 return default(TValue);
521 public static TValue
RandomItem<TValue>(
this IList<TValue> source, Func<TValue, bool> funcValid, TValue defaultValue =
default(TValue))
523 for (
int i = 0; i < 100; i++)
525 TValue val = source[
Rand.
rnd(source.Count)];
536 if (source.Count == 0)
538 return default(TValue);
540 if (source.Count == 1)
545 foreach (TValue
item in source)
547 num += getWeight(
item);
551 foreach (TValue item2
in source)
553 num += getWeight(item2);
559 return source.First();
564 if (source.Count != 0)
566 return source[divider % source.Count];
568 return default(TValue);
575 return default(TValue);
577 return source[source.First().Key];
582 if (source.Count != 0)
584 return source[source.Count - 1];
586 return default(TValue);
592 if (index >= source.Count)
596 if (source.Count != 0)
598 return source[index];
600 return default(TValue);
609 int num = source.IndexOf(val) + 1;
610 if (num >= source.Count)
619 int num = source.IndexOf(val) + 1;
620 if (num >= source.Count)
624 if (source.Count != 0)
628 return default(TValue);
633 int num = source.IndexOf(val) - 1;
636 num = source.Count - 1;
638 if (source.Count != 0)
642 return default(TValue);
651 else if (i >= source.Count)
653 i = source.Count - 1;
660 List<T> list =
new List<T>();
661 foreach (
object value
in source.Values)
673 dic =
new Dictionary<string, T>();
674 for (
int i = 0; i < list.Count; i++)
676 dic.Add(list[i].name, list[i].value);
680 public static T
FindMax<T>(
this List<T> list, Func<T, int> func)
682 int num =
int.MinValue;
683 T result =
default(T);
684 foreach (T
item in list)
686 int num2 = func(
item);
696 public static void Set<T1, T2>(
this Dictionary<T1, T2> dic, Dictionary<T1, T2> from)
699 foreach (KeyValuePair<T1, T2>
item in from)
707 if (
string.IsNullOrEmpty(text))
709 return new string[0];
711 return text.Split(
new string[3] {
"\r\n",
"\n",
"\r" }, StringSplitOptions.None);
716 if (
string.IsNullOrEmpty(text))
720 return text.Replace(
"\r",
"").Replace(
"\n",
"");
725 if (
string.IsNullOrEmpty(text))
729 return Regex.Replace(text,
"<.*?>",
"");
732 public static int Calc(
this string str,
int power = 0,
int ele = 0,
int p2 = 0)
734 return Cal.Calcuate(str.Replace(
"p2", p2.ToString() ??
"").Replace(
"p", power.ToString() ??
"").Replace(
"e", ele.ToString() ??
"")
740 return str.ToInt(typeof(T));
743 public static int ToInt(
this string str, Type type)
745 FieldInfo field = type.GetField(str, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
748 Debug.LogError(
"Field is null:" + str +
"/" + type);
751 return (
int)field.GetValue(
null);
754 public static int ToInt(
this string str)
756 if (
int.TryParse(str, out var result))
763 public static long ToLong(
this string str)
765 if (
long.TryParse(str, out var result))
777 if (!
float.TryParse(str, out result))
779 Debug.Log(
"exception: ToFlat1" + str);
785 Debug.Log(
"exception: ToFlat2" + str);
800 public static string StripPun(
this string str,
bool stripComma,
bool insertSpaceForComma =
false)
802 StringBuilder stringBuilder =
new StringBuilder();
803 foreach (
char c
in str)
809 if (insertSpaceForComma)
811 stringBuilder.Append(
'\u3000');
816 stringBuilder.Append(c);
821 stringBuilder.Append(c);
824 return stringBuilder.ToString();
827 public static string Repeat(
this string str,
int count)
829 StringBuilder stringBuilder =
new StringBuilder();
830 for (
int i = 0; i < Mathf.Abs(count); i++)
832 stringBuilder.Append(str);
834 return stringBuilder.ToString();
839 HashSet<char> brackets =
new HashSet<char> {
'"',
'「',
'」',
'“',
'”' };
840 return string.Concat(str.Where((
char c) => !brackets.Contains(c)));
845 if (!s.Contains(
"." + ext))
847 return s +
"." + ext;
861 public static string IsEmpty(
this string str,
string defaultStr)
863 if (str !=
null && !(str ==
""))
872 while (text.EndsWith(Environment.NewLine))
874 text = text.Substring(0, text.Length - Environment.NewLine.Length);
881 string[] array = str.Split(separator);
882 int[] array2 =
new int[array.Length];
883 for (
int i = 0; i < array.Length; i++)
885 array2[i] =
int.Parse(array[i]);
892 return str.Split(Environment.NewLine.ToCharArray());
895 public static bool Contains(
this string[] strs,
string id)
897 if (strs ==
null || strs.Length == 0)
901 for (
int i = 0; i < strs.Length; i++)
911 public static string Evalute(
this string[] array,
float val)
913 return array[(int)Mathf.Clamp((
float)(array.Length - 1) * val, 0f, array.Length - 1)];
925 return a / 1000 +
"K";
935 text = a / 1000000 +
"M";
944 return a / 1000 +
"K";
946 text2 = a.ToString();
954 text2 = a / 1000000 +
"M";
969 public static string ToText(
this int a,
bool skipIfZero =
true)
972 if (!(a == 0 && skipIfZero))
993 return s +
"<color=" + c.ToHex() +
">" + txt +
"</color>";
998 return "<color=" + c.ToHex() +
">" + s +
"</color>";
1001 public static string TagSize(
this string s,
string txt,
int size)
1003 return s +
"<size=" + size +
">" + txt +
"</size>";
1006 public static string TagSize(
this string s,
int size)
1008 return "<size=" + size +
">" + s +
"</size>";
1011 public static bool HasTag(
this string s,
string id,
char splitter =
'/')
1013 return s.Split(splitter).Contains(
id);
1016 public static string SetTag(
this string s,
string id,
bool enable,
char splitter =
'/')
1018 s = ((!enable) ? s.RemoveTag(
id, splitter) : s.AddTag(
id, splitter));
1022 public static string AddTag(
this string s,
string id,
char splitter =
'/')
1024 if (!s.HasTag(
id, splitter))
1026 s = s + (s.IsEmpty() ?
"" : ((object)splitter))?.ToString() + id;
1031 public static string RemoveTag(
this string s,
string id,
char splitter =
'/')
1033 string[] array = s.Split(splitter);
1035 string[] array2 = array;
1036 foreach (
string text
in array2)
1040 s.AddTag(text, splitter);
1048 return fileInfo.Directory.FullName +
"/" + Path.GetFileNameWithoutExtension(fileInfo.Name);
1053 return new FileInfo(path).GetFullFileNameWithoutExtension();
1058 if (s ==
"talisman")
1067 if (a.ToLower() ==
"unicorn")
1080 char c = s.ToLower()[0];
1081 s = (
GetSpecialArticle(s) ?? ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a ")) + s;
1092 string text = ((num >= 2) ? (num.ToFormat() +
" ") : (
GetSpecialArticle(s) ?? ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a ")));
1095 s = ((replace.IsEmpty() || !s.Contains(replace) || s.Contains(
"limestone stone")) ?
Pluralize(s) : s.Replace(replace,
Pluralize(replace)));
1099 ArticleStyle.The =>
"_the".lang().ToTitleCase() +
" " + ((num > 1) ? (num +
" ") :
"") + s,
1100 ArticleStyle.None => ((num > 1) ? (num.ToFormat() +
" ") :
"") + s.ToTitleCase(),
1105 public static string ToTitleCase(
this string s,
bool wholeText =
false)
1111 char[] array = s.ToCharArray();
1113 for (
int i = 0; i < array.Length; i++)
1117 array[i] =
char.ToUpper(array[i]);
1124 if (array[i] ==
' ')
1129 return new string(array);
1132 public static void LoopTail<T>(
this List<T> list,
bool vertical =
false) where T : Selectable
1136 Navigation navigation = list[0].navigation;
1137 Navigation navigation2 = list[list.Count - 1].navigation;
1140 navigation.selectOnUp = list[list.Count - 1];
1141 navigation2.selectOnDown = list[0];
1145 navigation.selectOnLeft = list[list.Count - 1];
1146 navigation2.selectOnRight = list[0];
1148 list[0].navigation = navigation;
1149 list[list.Count - 1].navigation = navigation2;
1153 public static void SetNavigation(
this Component a, Component b,
bool vertical =
false)
1159 Selectable component = a.GetComponent<Selectable>();
1160 Selectable component2 = b.GetComponent<Selectable>();
1161 if ((
bool)component && (bool)component2)
1163 Navigation navigation = component.navigation;
1164 Navigation navigation2 = component2.navigation;
1167 navigation.selectOnUp = component2;
1168 navigation2.selectOnDown = component;
1172 navigation.selectOnLeft = component2;
1173 navigation2.selectOnRight = component;
1175 component.navigation = navigation;
1176 component2.navigation = navigation2;
1180 public static void LoopSelectable(
this List<Selectable> sels,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1182 for (
int i = 0; i < sels.Count; i++)
1184 Selectable selectable = sels[i];
1185 Selectable selectable2 = sels[0];
1186 Navigation navigation = selectable.navigation;
1189 navigation.selectOnRight = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1193 for (
int j = i + 1; j < sels.Count; j++)
1195 if (sels[j].transform.position.y < selectable.transform.position.y)
1197 selectable2 = sels[j];
1204 selectable2 = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1208 navigation.selectOnDown = selectable2;
1210 selectable.navigation = navigation;
1212 for (
int num = sels.Count - 1; num >= 0; num--)
1214 Selectable selectable3 = sels[num];
1215 Selectable selectable4 = sels[sels.Count - 1];
1216 Navigation navigation2 = selectable3.navigation;
1219 navigation2.selectOnLeft = ((num > 0) ? sels[num - 1] : selectable4);
1223 int num2 = sels.Count - 1;
1224 for (
int num3 = num - 1; num3 >= 0; num3--)
1226 if (sels[num3].transform.position.y > selectable3.transform.position.y)
1233 while (num4 >= 0 && !(sels[num4].transform.position.y > sels[num2].transform.position.y))
1235 selectable4 = sels[num4];
1241 selectable4 = ((num > 0) ? sels[num - 1] : selectable4);
1245 navigation2.selectOnUp = ((selectable4 == selectable3) ? sels[sels.Count - 1] : selectable4);
1247 navigation2.mode = Navigation.Mode.Explicit;
1248 selectable3.navigation = navigation2;
1252 public static void LoopSelectable(
this Transform l,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1254 List<Selectable> list = l.GetComponentsInChildren<Selectable>().ToList();
1255 for (
int num = list.Count - 1; num >= 0; num--)
1257 if (!list[num].interactable || list[num].navigation.mode == Navigation.Mode.None)
1262 list.LoopSelectable(vertical, horizonal, asGroup);
1268 ColorUtility.TryParseHtmlString(
"#" + s, out color);
1274 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1279 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1290 return new Color(c.r * mtp + add, c.g * mtp + add, c.b * mtp + add, c.a);
1295 return "<color=" +
$"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}" +
">";
1300 return $"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}";
1305 b.onClick.RemoveAllListeners();
1306 b.onClick.AddListener(delegate
1314 e.RemoveAllListeners();
1315 e.AddListener(delegate
1321 public static void SetAlpha(
this Text text,
float aloha = 1f)
1323 text.color =
new Color(text.color.r, text.color.g, text.color.b, aloha);
1326 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
bool notify)
1328 slider.SetSlider(value, action, -1, -1, notify);
1331 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
int min = -1,
int max = -1,
bool notify =
true)
1333 slider.onValueChanged.RemoveAllListeners();
1334 slider.onValueChanged.AddListener(delegate(
float a)
1336 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(a);
1340 slider.minValue = min;
1341 slider.maxValue = max;
1345 slider.value = value;
1349 slider.SetValueWithoutNotify(value);
1351 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(value);
1356 T val = t.gameObject.GetComponent<T>();
1359 val = t.gameObject.AddComponent<T>();
1364 public static RectTransform
Rect(
this Component c)
1366 return c.transform as RectTransform;
1369 public static void CopyRect(
this RectTransform r, RectTransform t)
1372 r.sizeDelta = t.sizeDelta;
1373 r.anchorMin = t.anchorMin;
1374 r.anchorMax = t.anchorMax;
1375 r.anchoredPosition = t.anchoredPosition;
1380 c.SetActive(!c.gameObject.activeSelf);
1385 if (c.gameObject.activeSelf != enable)
1387 c.gameObject.SetActive(enable);
1391 public static void SetActive(
this Component c,
bool enable, Action<bool> onChangeState)
1393 if (c.gameObject.activeSelf != enable)
1395 c.gameObject.SetActive(enable);
1396 onChangeState(enable);
1402 return go.GetComponentInChildren<Selectable>();
1408 foreach (Transform
item in obj.transform)
1410 item.gameObject.SetLayerRecursively(layer);
1416 Selectable selectable = (obj ? obj.GetComponent<Selectable>() :
null);
1417 if ((
bool)selectable)
1419 return selectable.interactable;
1424 public static bool IsChildOf(
this GameObject c, GameObject root)
1426 if (c.transform == root.transform)
1430 if ((
bool)c.transform.parent)
1432 return c.transform.parent.gameObject.IsChildOf(root);
1439 return c.gameObject.scene.name ==
null;
1442 public static T
CreateMold<T>(
this Component c,
string name =
null) where T : Component
1445 for (
int i = 0; i < c.transform.childCount; i++)
1447 T component = c.transform.GetChild(i).GetComponent<T>();
1448 if ((
bool)component && (name.IsEmpty() || name == component.name))
1450 component.gameObject.SetActive(value:
false);
1455 c.DestroyChildren();
1459 public static Transform
Find(
this Component c,
string name =
null)
1461 return c.Find<Transform>(name);
1464 public static T
Find<T>(
this Component c,
string name =
null,
bool recursive =
false) where T : Component
1468 T[] componentsInChildren = c.transform.GetComponentsInChildren<T>();
1469 foreach (T val
in componentsInChildren)
1471 if (name ==
null || name == val.name)
1478 for (
int j = 0; j < c.transform.childCount; j++)
1480 T component = c.transform.GetChild(j).GetComponent<T>();
1481 if ((
bool)component && (name ==
null || name == component.name))
1489 public static GameObject
FindTagInParents(
this Component c,
string tag,
bool includeInactive =
true)
1491 Transform transform = c.transform;
1492 for (
int i = 0; i < transform.childCount; i++)
1494 Transform child = transform.GetChild(i);
1495 if ((includeInactive || child.gameObject.activeSelf) && child.tag == tag)
1497 return child.gameObject;
1500 if ((
bool)transform.parent)
1502 return transform.parent.FindTagInParents(tag, includeInactive);
1509 for (
int i = 0; i < c.childCount; i++)
1511 T component = c.GetChild(i).GetComponent<T>();
1512 if ((
bool)component)
1522 List<T> list =
new List<T>();
1523 Transform transform = comp.transform;
1524 for (
int i = 0; i < transform.childCount; i++)
1526 T component = transform.GetChild(i).GetComponent<T>();
1527 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1529 list.Add(component);
1537 List<T> list =
new List<T>();
1538 Transform transform = comp.transform;
1539 for (
int i = 0; i < transform.childCount; i++)
1541 T component = transform.GetChild(i).GetComponent<T>();
1542 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1544 list.Add(component);
1552 Transform transform = comp.transform;
1553 for (
int i = 0; i < transform.childCount; i++)
1555 T component = transform.GetChild(i).GetComponent<T>();
1556 if ((
bool)component)
1564 public static void DestroyChildren(
this Component component,
bool destroyInactive =
false,
bool ignoreDestroy =
true)
1566 if (!component || !component.transform)
1568 Debug.LogWarning(
"DestroyChlidren:" + component);
1571 for (
int num = component.transform.childCount - 1; num >= 0; num--)
1573 GameObject gameObject = component.transform.GetChild(num).gameObject;
1574 if ((!ignoreDestroy || !(gameObject.tag ==
"IgnoreDestroy")) && (destroyInactive || gameObject.activeSelf))
1576 UnityEngine.Object.DestroyImmediate(gameObject);
1583 return RectTransformUtility.RectangleContainsScreenPoint(r, Input.mousePosition, cam);
1590 foreach (Transform
item in c.transform)
1592 if (
item is RectTransform)
1594 item.RebuildLayout(recursive:
true);
1598 LayoutRebuilder.ForceRebuildLayoutImmediate(c.transform as RectTransform);
1604 if ((
bool)c.transform.parent && !c.transform.parent.GetComponent<T>())
1606 c.transform.parent.RebuildLayoutTo<T>();
1613 if (!(c == target) && (
bool)c.transform.parent)
1615 c.transform.parent.RebuildLayoutTo(target);
1619 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)
1621 r.SetPivot(pivotX, pivotY);
1622 r.SetAnchor(minX, minY, maxX, maxY);
1625 r.sizeDelta =
new Vector2(w, h);
1627 r.anchoredPosition =
new Vector2((x == -1f) ? r.anchoredPosition.x : x, (y == -1f) ? r.anchoredPosition.y : y);
1630 public static void SetPivot(
this RectTransform r,
float x,
float y)
1632 r.pivot =
new Vector2(x, y);
1635 public static void SetAnchor(
this RectTransform r,
float minX,
float minY,
float maxX,
float maxY)
1637 r.anchorMin =
new Vector2(minX, minY);
1638 r.anchorMax =
new Vector2(maxX, maxY);
1646 _rect.SetAnchor(0.5f, 1f, 0.5f, 1f);
1649 _rect.SetAnchor(0.5f, 0f, 0.5f, 0f);
1652 _rect.SetAnchor(0f, 1f, 0f, 1f);
1655 _rect.SetAnchor(1f, 1f, 1f, 1f);
1658 _rect.SetAnchor(0f, 0f, 0f, 0f);
1661 _rect.SetAnchor(1f, 0f, 1f, 0f);
1664 _rect.SetAnchor(0f, 0.5f, 0f, 0.5f);
1667 _rect.SetAnchor(1f, 0.5f, 1f, 0.5f);
1670 _rect.SetAnchor(0.5f, 0.5f, 0.5f, 0.5f);
1677 Vector3 position = _rect.position;
1678 _rect._SetAnchor((anchor ==
RectPosition.Auto) ? _rect.GetAnchor() : anchor);
1679 _rect.position = position;
1684 Vector3 position = _rect.position;
1685 int width = Screen.width;
1686 int height = Screen.height;
1687 bool flag = position.y > (float)height * 0.5f;
1688 if (position.x > (
float)width * 0.3f && position.x < (float)width * 0.7f)
1690 if (position.y > (
float)height * 0.3f && position.y < (float)height * 0.7f)
1700 if (position.x < (
float)width * 0.5f)
1717 return trans.GetChild(trans.childCount - 1);
1722 return new Vector2(
self.x,
self.z);
1725 public static void SetScale(
this SpriteRenderer renderer,
float size)
1727 float x = renderer.bounds.size.x;
1728 float y = renderer.bounds.size.y;
1729 float x2 = size / x;
1730 float y2 = size / y;
1731 renderer.transform.localScale =
new Vector3(x2, y2, 1f);
1736 if (
object.Equals(
forward, Vector2.up))
1740 object.Equals(
forward, Vector2.right);
1746 self.LookAt2D(target.position,
forward);
1752 Vector3 vector = target -
self.position;
1753 float num = Mathf.Atan2(vector.y, vector.x) * 57.29578f;
1754 self.rotation = Quaternion.AngleAxis(num - forwardDiffPoint, Vector3.forward);
1757 public static float Distance(
this Transform t, Vector2 pos)
1759 return Vector3.Distance(t.position, pos);
1762 public static Vector3
Plus(
this Vector3 v, Vector2 v2)
1769 public static Vector3
SetZ(
this Vector3 v,
float a)
1775 public static Vector3
SetY(
this Vector3 v,
float a)
1781 public static Vector3
PlusX(
this Vector3 v,
float a)
1787 public static Vector3
PlusY(
this Vector3 v,
float a)
1793 public static Vector3
PlusZ(
this Vector3 v,
float a)
1799 public static void SetPosition(
this Transform transform,
float x,
float y,
float z)
1807 vector3.Set(x, transform.position.y, transform.position.z);
1813 vector3.Set(transform.position.x, y, transform.position.z);
1819 vector3.Set(transform.position.x, transform.position.y, z);
1823 public static void AddPosition(
this Transform transform,
float x,
float y,
float z)
1825 vector3.Set(transform.position.x + x, transform.position.y + y, transform.position.z + z);
1831 vector3.Set(transform.position.x + x, transform.position.y, transform.position.z);
1837 vector3.Set(transform.position.x, transform.position.y + y, transform.position.z);
1843 vector3.Set(transform.position.x, transform.position.y, transform.position.z + z);
1850 transform.localPosition =
vector3;
1855 vector3.Set(x, transform.localPosition.y, transform.localPosition.z);
1856 transform.localPosition =
vector3;
1861 vector3.Set(transform.localPosition.x, y, transform.localPosition.z);
1862 transform.localPosition =
vector3;
1867 vector3.Set(transform.localPosition.x, transform.localPosition.y, z);
1868 transform.localPosition =
vector3;
1873 vector3.Set(transform.localPosition.x + x, transform.localPosition.y + y, transform.localPosition.z + z);
1874 transform.localPosition =
vector3;
1879 vector3.Set(transform.localPosition.x + x, transform.localPosition.y, transform.localPosition.z);
1880 transform.localPosition =
vector3;
1885 vector3.Set(transform.localPosition.x, transform.localPosition.y + y, transform.localPosition.z);
1886 transform.localPosition =
vector3;
1891 vector3.Set(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + z);
1892 transform.localPosition =
vector3;
1895 public static void SetLocalScale(
this Transform transform,
float x,
float y,
float z)
1898 transform.localScale =
vector3;
1903 vector3.Set(x, transform.localScale.y, transform.localScale.z);
1904 transform.localScale =
vector3;
1909 vector3.Set(transform.localScale.x, y, transform.localScale.z);
1910 transform.localScale =
vector3;
1915 vector3.Set(transform.localScale.x, transform.localScale.y, z);
1916 transform.localScale =
vector3;
1919 public static void AddLocalScale(
this Transform transform,
float x,
float y,
float z)
1921 vector3.Set(transform.localScale.x + x, transform.localScale.y + y, transform.localScale.z + z);
1922 transform.localScale =
vector3;
1927 vector3.Set(transform.localScale.x + x, transform.localScale.y, transform.localScale.z);
1928 transform.localScale =
vector3;
1933 vector3.Set(transform.localScale.x, transform.localScale.y + y, transform.localScale.z);
1934 transform.localScale =
vector3;
1939 vector3.Set(transform.localScale.x, transform.localScale.y, transform.localScale.z + z);
1940 transform.localScale =
vector3;
1943 public static void SetEulerAngles(
this Transform transform,
float x,
float y,
float z)
1946 transform.eulerAngles =
vector3;
1951 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1952 transform.eulerAngles =
vector3;
1957 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1958 transform.eulerAngles =
vector3;
1963 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1964 transform.eulerAngles =
vector3;
1967 public static void AddEulerAngles(
this Transform transform,
float x,
float y,
float z)
1969 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y + y, transform.eulerAngles.z + z);
1970 transform.eulerAngles =
vector3;
1975 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y, transform.eulerAngles.z);
1976 transform.eulerAngles =
vector3;
1981 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y + y, transform.eulerAngles.z);
1982 transform.eulerAngles =
vector3;
1987 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z + z);
1988 transform.eulerAngles =
vector3;
1994 transform.localEulerAngles =
vector3;
1999 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
2000 transform.localEulerAngles =
vector3;
2005 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
2006 transform.localEulerAngles =
vector3;
2011 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
2012 transform.localEulerAngles =
vector3;
2017 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y + y, transform.localEulerAngles.z + z);
2018 transform.localEulerAngles =
vector3;
2023 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y, transform.localEulerAngles.z);
2024 transform.localEulerAngles =
vector3;
2029 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y + y, transform.localEulerAngles.z);
2030 transform.localEulerAngles =
vector3;
2035 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z + z);
2036 transform.localEulerAngles =
vector3;
2043 m.EnableKeyword(
id);
2047 m.DisableKeyword(
id);
2053 for (
int num = items.Count - 1; num >= 0; num--)
2061 int num = items.Count - 1;
2062 while (num >= 0 && !action(items[num]))
2070 int num = items.LastIndexOf(
item);
2075 items.RemoveAt(num);
2083 return 360f - (0f - angle) % 360f;
2085 return angle % 360f;
2095 string name = s.name;
2096 T val = UnityEngine.Object.Instantiate(s);
2103 Type typeFromHandle = typeof(UnityEventBase);
2104 Assembly assembly = Assembly.GetAssembly(typeFromHandle);
2105 Type type = assembly.GetType(
"UnityEngine.Events.InvokableCallList");
2106 Type type2 = assembly.GetType(
"UnityEngine.Events.BaseInvokableCall");
2107 Type type3 = typeof(List<>).MakeGenericType(type2);
2108 FieldInfo field = typeFromHandle.GetField(
"m_Calls", BindingFlags.Instance | BindingFlags.NonPublic);
2109 FieldInfo field2 = type.GetField(
"m_RuntimeCalls", BindingFlags.Instance | BindingFlags.NonPublic);
2110 object value = field.GetValue(unityEvent);
2111 object value2 = field2.GetValue(value);
2112 return (
int)type3.GetProperty(
"Count").GetValue(value2,
null);
static readonly Dictionary< string, T > fuzzy
static readonly Dictionary< string, T > cached
static readonly bool IsLong
static readonly bool IsInt
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 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)
static LangSetting setting
static string Get(string id)
static string[] GetList(string id)
static string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null, string val5=null)
static int Range(int min, int max)
string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null)