2using System.Collections;
3using System.Collections.Generic;
6using System.Reflection;
10using UnityEngine.Events;
19 public static string lang(
this string s)
30 public static string lang(
this string s,
string ref1,
string ref2 =
null,
string ref3 =
null,
string ref4 =
null,
string ref5 =
null)
32 return Lang.
Parse(s, ref1, ref2, ref3, ref4, ref5);
40 public static string langGame(
this string s,
string ref1,
string ref2 =
null,
string ref3 =
null,
string ref4 =
null)
47 return "(" + str +
")";
50 public static string Bracket(
this string str,
int type = 0)
59 _ =>
"_bracketLeft".lang() + str +
"_bracketRight".lang(),
63 public static byte[]
ToBytes(
this BitArray bits)
65 byte[] array =
new byte[(bits.Length - 1) / 8 + 1];
66 bits.CopyTo(array, 0);
70 public static bool GetBit(
this byte pByte,
int bitNo)
72 return (pByte & (1 << bitNo)) != 0;
75 public static byte SetBit(
this byte pByte,
int bitNo,
bool value)
79 return Convert.ToByte(pByte & ~(1 << bitNo));
81 return Convert.ToByte(pByte | (1 << bitNo));
84 public static int ToInt3(
this float a)
86 return (
int)(a * 1000f);
91 return (
float)a / 1000f;
94 public static int ToInt2(
this float a)
96 return (
int)(a * 100f);
101 return (
float)a / 100f;
122 public static bool IsOn(
this int data,
int digit)
126 return bitArray[digit];
131 return (T)Enum.ToObject(typeof(T), value);
136 return (T)Enum.ToObject(typeof(T), value);
139 public static T
ToEnum<T>(
this string value,
bool ignoreCase =
true)
141 return (T)Enum.Parse(typeof(T), value, ignoreCase);
144 public static Type
ToType(
this string value)
146 return Type.GetType(
"Elona." + value +
", Assembly-CSharp");
151 return ((T[])Enum.GetValues(src.GetType())).NextItem(src);
156 return ((T[])Enum.GetValues(src.GetType())).PrevItem(src);
159 public static bool Within(
this int v,
int v2,
int range)
163 return v - v2 < -range;
168 public static bool Within(
this byte v,
byte v2,
byte range)
172 return v - v2 < -range;
177 public static int Clamp(
this int v,
int min,
int max,
bool loop =
false)
181 v = ((!loop) ? min : max);
185 v = ((!loop) ? max : min);
210 return (T)o.GetType().GetField(s).GetValue(o);
215 FieldInfo field = o.GetType().GetField(name);
218 return typeof(T).IsAssignableFrom(field.FieldType);
225 return (T)o.GetType().GetField(name).GetValue(o);
228 public static void SetField<T>(
this object o,
string name, T value)
230 o.GetType().GetField(name).SetValue(o, value);
235 return (T)o.GetType().GetProperty(name).GetValue(o);
240 o.GetType().GetProperty(name).SetValue(o, value);
243 public static void Sort<T>(
this IList<T> list, Comparison<T> comparison)
247 ((List<T>)list).Sort(comparison);
250 List<T> list2 =
new List<T>(list);
251 list2.Sort(comparison);
252 for (
int i = 0; i < list.Count; i++)
258 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
int defIndex = -1)
260 if (array.Count != 0)
262 if (index >= array.Count)
266 if (array.Count <= defIndex)
268 return array[Mathf.Max(0, array.Count - 1)];
270 return array[defIndex];
272 return array[Mathf.Max(0, array.Count - 1)];
274 return array[Math.Max(0, index)];
276 return default(TValue);
279 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
bool returnNull)
281 if (index >= array.Count)
283 return default(TValue);
292 return array.Length == 0;
297 public static int IndexOf(
this IList<Component> list, GameObject go)
303 for (
int i = 0; i < list.Count; i++)
305 if (list[i].gameObject == go)
313 public static TValue
Move<TValue>(
this IList<TValue> list, TValue target,
int a)
315 int num = list.IndexOf(target);
319 num2 = list.Count - 1;
321 if (num2 >= list.Count)
326 list.Insert(num2, target);
332 return list.ToList();
335 public static void Each<TValue>(
this IList<TValue> list, Action<TValue> action)
337 for (
int num = list.Count - 1; num >= 0; num--)
345 int num = list.Count;
350 TValue value = list[num];
351 list[num] = list[index];
359 TValue value =
default(TValue);
360 if (key !=
null && source.TryGetValue(key, out value))
369 TValue value =
default(TValue);
370 if (key !=
null && source.TryGetValue(key, out value))
374 return source[key_fallback];
379 TValue val = dict.TryGetValue(key);
382 val = ((func !=
null) ? func() : Activator.CreateInstance<TValue>());
390 TKey[] array =
new TKey[dict.Keys.Count];
391 dict.Keys.CopyTo(array, 0);
397 TValue[] array =
new TValue[dict.Keys.Count];
398 dict.Values.CopyTo(array, 0);
404 int num = ie.Count();
409 return ie.ElementAt(
Rand.
rnd(num));
414 if (source.Count != 0)
416 return source.ElementAt(
Rand.
rnd(source.Count)).Value;
418 return default(TValue);
423 if (source.Count != 0)
425 return source[
Rand.
rnd(source.Count)];
427 return default(TValue);
432 return source.RandomItem(source.IndexOf(exclude));
437 if (source.Count > 1)
444 while (num == exclude);
447 if (source.Count == 1)
451 return default(TValue);
454 public static TValue
RandomItem<TValue>(
this IList<TValue> source, Func<TValue, bool> funcValid, TValue defaultValue =
default(TValue))
456 for (
int i = 0; i < 100; i++)
458 TValue val = source[
Rand.
rnd(source.Count)];
469 if (source.Count == 0)
471 return default(TValue);
473 if (source.Count == 1)
478 foreach (TValue
item in source)
480 num += getWeight(
item);
484 foreach (TValue item2
in source)
486 num += getWeight(item2);
492 return source.First();
497 if (source.Count != 0)
499 return source[divider % source.Count];
501 return default(TValue);
508 return default(TValue);
510 return source[source.First().Key];
515 if (source.Count != 0)
517 return source[source.Count - 1];
519 return default(TValue);
525 if (index >= source.Count)
529 if (source.Count != 0)
531 return source[index];
533 return default(TValue);
542 int num = source.IndexOf(val) + 1;
543 if (num >= source.Count)
552 int num = source.IndexOf(val) + 1;
553 if (num >= source.Count)
557 if (source.Count != 0)
561 return default(TValue);
566 int num = source.IndexOf(val) - 1;
569 num = source.Count - 1;
571 if (source.Count != 0)
575 return default(TValue);
584 else if (i >= source.Count)
586 i = source.Count - 1;
593 List<T> list =
new List<T>();
594 foreach (
object value
in source.Values)
606 dic =
new Dictionary<string, T>();
607 for (
int i = 0; i < list.Count; i++)
609 dic.Add(list[i].name, list[i].value);
613 public static T
FindMax<T>(
this List<T> list, Func<T, int> func)
615 int num =
int.MinValue;
616 T result =
default(T);
617 foreach (T
item in list)
619 int num2 = func(
item);
629 public static void Set<T1, T2>(
this Dictionary<T1, T2> dic, Dictionary<T1, T2> from)
632 foreach (KeyValuePair<T1, T2>
item in from)
638 public static int Calc(
this string str,
int power = 0,
int ele = 0,
int p2 = 0)
640 return Cal.Calcuate(str.Replace(
"p2", p2.ToString() ??
"").Replace(
"p", power.ToString() ??
"").Replace(
"e", ele.ToString() ??
""));
645 return str.ToInt(typeof(T));
648 public static int ToInt(
this string str, Type type)
650 FieldInfo field = type.GetField(str, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
653 Debug.LogError(
"Field is null:" + str +
"/" + type);
656 return (
int)field.GetValue(
null);
659 public static int ToInt(
this string str)
661 if (
int.TryParse(str, out var result))
673 if (!
float.TryParse(str, out result))
675 Debug.Log(
"exception: ToFlat1" + str);
681 Debug.Log(
"exception: ToFlat2" + str);
696 public static string StripPun(
this string str,
bool stripComma,
bool insertSpaceForComma =
false)
698 StringBuilder stringBuilder =
new StringBuilder();
699 foreach (
char c
in str)
705 if (insertSpaceForComma)
707 stringBuilder.Append(
'\u3000');
712 stringBuilder.Append(c);
717 stringBuilder.Append(c);
720 return stringBuilder.ToString();
723 public static string Repeat(
this string str,
int count)
725 StringBuilder stringBuilder =
new StringBuilder();
726 for (
int i = 0; i < Mathf.Abs(count); i++)
728 stringBuilder.Append(str);
730 return stringBuilder.ToString();
735 return str.Replace(
"\"",
"").Replace(
"「",
"").Replace(
"」",
"")
742 if (!s.Contains(
"." + ext))
744 return s +
"." + ext;
758 public static string IsEmpty(
this string str,
string defaultStr)
760 if (str !=
null && !(str ==
""))
769 while (text.EndsWith(Environment.NewLine))
771 text = text.Substring(0, text.Length - Environment.NewLine.Length);
778 string[] array = str.Split(separator);
779 int[] array2 =
new int[array.Length];
780 for (
int i = 0; i < array.Length; i++)
782 array2[i] =
int.Parse(array[i]);
789 return str.Split(Environment.NewLine.ToCharArray());
792 public static bool Contains(
this string[] strs,
string id)
794 if (strs ==
null || strs.Length == 0)
798 for (
int i = 0; i < strs.Length; i++)
808 public static string Evalute(
this string[] array,
float val)
810 return array[(int)Mathf.Clamp((
float)(array.Length - 1) * val, 0f, array.Length - 1)];
820 return a / 1000 +
"K";
830 text = a / 1000000 +
"M";
845 public static string ToText(
this int a,
bool skipIfZero =
true)
848 if (!(a == 0 && skipIfZero))
869 return s +
"<color=" + c.ToHex() +
">" + txt +
"</color>";
874 return "<color=" + c.ToHex() +
">" + s +
"</color>";
877 public static string TagSize(
this string s,
string txt,
int size)
879 return s +
"<size=" + size +
">" + txt +
"</size>";
882 public static string TagSize(
this string s,
int size)
884 return "<size=" + size +
">" + s +
"</size>";
889 return fileInfo.Directory.FullName +
"/" + Path.GetFileNameWithoutExtension(fileInfo.Name);
894 return new FileInfo(path).GetFullFileNameWithoutExtension();
904 s = ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a ") + s;
915 string text = ((num >= 2) ? (num.ToFormat() +
" ") : ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a "));
918 s = ((replace.IsEmpty() || !s.Contains(replace) || s.Contains(
"limestone stone")) ?
pluralizer.Pluralize(s) : s.Replace(replace,
pluralizer.Pluralize(replace)));
922 ArticleStyle.The =>
"_the".lang().ToTitleCase() +
" " + ((num > 1) ? (num +
" ") :
"") + s,
923 ArticleStyle.None => ((num > 1) ? (num.ToFormat() +
" ") :
"") + s.ToTitleCase(),
928 public static string ToTitleCase(
this string s,
bool wholeText =
false)
934 char[] array = s.ToCharArray();
936 for (
int i = 0; i < array.Length; i++)
940 array[i] =
char.ToUpper(array[i]);
952 return new string(array);
955 public static void LoopTail<T>(
this List<T> list,
bool vertical =
false) where T : Selectable
959 Navigation navigation = list[0].navigation;
960 Navigation navigation2 = list[list.Count - 1].navigation;
963 navigation.selectOnUp = list[list.Count - 1];
964 navigation2.selectOnDown = list[0];
968 navigation.selectOnLeft = list[list.Count - 1];
969 navigation2.selectOnRight = list[0];
971 list[0].navigation = navigation;
972 list[list.Count - 1].navigation = navigation2;
976 public static void SetNavigation(
this Component a, Component b,
bool vertical =
false)
982 Selectable component = a.GetComponent<Selectable>();
983 Selectable component2 = b.GetComponent<Selectable>();
984 if ((
bool)component && (bool)component2)
986 Navigation navigation = component.navigation;
987 Navigation navigation2 = component2.navigation;
990 navigation.selectOnUp = component2;
991 navigation2.selectOnDown = component;
995 navigation.selectOnLeft = component2;
996 navigation2.selectOnRight = component;
998 component.navigation = navigation;
999 component2.navigation = navigation2;
1003 public static void LoopSelectable(
this List<Selectable> sels,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1005 for (
int i = 0; i < sels.Count; i++)
1007 Selectable selectable = sels[i];
1008 Selectable selectable2 = sels[0];
1009 Navigation navigation = selectable.navigation;
1012 navigation.selectOnRight = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1016 for (
int j = i + 1; j < sels.Count; j++)
1018 if (sels[j].transform.position.y < selectable.transform.position.y)
1020 selectable2 = sels[j];
1027 selectable2 = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1031 navigation.selectOnDown = selectable2;
1033 selectable.navigation = navigation;
1035 for (
int num = sels.Count - 1; num >= 0; num--)
1037 Selectable selectable3 = sels[num];
1038 Selectable selectable4 = sels[sels.Count - 1];
1039 Navigation navigation2 = selectable3.navigation;
1042 navigation2.selectOnLeft = ((num > 0) ? sels[num - 1] : selectable4);
1046 int num2 = sels.Count - 1;
1047 for (
int num3 = num - 1; num3 >= 0; num3--)
1049 if (sels[num3].transform.position.y > selectable3.transform.position.y)
1056 while (num4 >= 0 && !(sels[num4].transform.position.y > sels[num2].transform.position.y))
1058 selectable4 = sels[num4];
1064 selectable4 = ((num > 0) ? sels[num - 1] : selectable4);
1068 navigation2.selectOnUp = ((selectable4 == selectable3) ? sels[sels.Count - 1] : selectable4);
1070 navigation2.mode = Navigation.Mode.Explicit;
1071 selectable3.navigation = navigation2;
1075 public static void LoopSelectable(
this Transform l,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1077 List<Selectable> list = l.GetComponentsInChildren<Selectable>().ToList();
1078 for (
int num = list.Count - 1; num >= 0; num--)
1080 if (!list[num].interactable || list[num].navigation.mode == Navigation.Mode.None)
1085 list.LoopSelectable(vertical, horizonal, asGroup);
1091 ColorUtility.TryParseHtmlString(
"#" + s, out color);
1097 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1102 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1113 return new Color(c.r * mtp + add, c.g * mtp + add, c.b * mtp + add, c.a);
1118 return "<color=" +
$"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}" +
">";
1123 return $"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}";
1128 b.onClick.RemoveAllListeners();
1129 b.onClick.AddListener(delegate
1137 e.RemoveAllListeners();
1138 e.AddListener(delegate
1144 public static void SetAlpha(
this Text text,
float aloha = 1f)
1146 text.color =
new Color(text.color.r, text.color.g, text.color.b, aloha);
1149 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
bool notify)
1151 slider.SetSlider(value, action, -1, -1, notify);
1154 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
int min = -1,
int max = -1,
bool notify =
true)
1156 slider.onValueChanged.RemoveAllListeners();
1157 slider.onValueChanged.AddListener(delegate(
float a)
1159 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(a);
1163 slider.minValue = min;
1164 slider.maxValue = max;
1168 slider.value = value;
1172 slider.SetValueWithoutNotify(value);
1174 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(value);
1179 T val = t.gameObject.GetComponent<T>();
1182 val = t.gameObject.AddComponent<T>();
1187 public static RectTransform
Rect(
this Component c)
1189 return c.transform as RectTransform;
1192 public static void CopyRect(
this RectTransform r, RectTransform t)
1195 r.sizeDelta = t.sizeDelta;
1196 r.anchorMin = t.anchorMin;
1197 r.anchorMax = t.anchorMax;
1198 r.anchoredPosition = t.anchoredPosition;
1203 c.SetActive(!c.gameObject.activeSelf);
1208 if (c.gameObject.activeSelf != enable)
1210 c.gameObject.SetActive(enable);
1214 public static void SetActive(
this Component c,
bool enable, Action<bool> onChangeState)
1216 if (c.gameObject.activeSelf != enable)
1218 c.gameObject.SetActive(enable);
1219 onChangeState(enable);
1225 return go.GetComponentInChildren<Selectable>();
1231 foreach (Transform
item in obj.transform)
1233 item.gameObject.SetLayerRecursively(layer);
1239 Selectable selectable = (obj ? obj.GetComponent<Selectable>() :
null);
1240 if ((
bool)selectable)
1242 return selectable.interactable;
1247 public static bool IsChildOf(
this GameObject c, GameObject root)
1249 if (c.transform == root.transform)
1253 if ((
bool)c.transform.parent)
1255 return c.transform.parent.gameObject.IsChildOf(root);
1262 return c.gameObject.scene.name ==
null;
1265 public static T
CreateMold<T>(
this Component c,
string name =
null) where T : Component
1268 for (
int i = 0; i < c.transform.childCount; i++)
1270 T component = c.transform.GetChild(i).GetComponent<T>();
1271 if ((
bool)component && (name.IsEmpty() || name == component.name))
1273 component.gameObject.SetActive(value:
false);
1278 c.DestroyChildren();
1282 public static Transform
Find(
this Component c,
string name =
null)
1284 return c.Find<Transform>(name);
1287 public static T
Find<T>(
this Component c,
string name =
null,
bool recursive =
false) where T : Component
1291 T[] componentsInChildren = c.transform.GetComponentsInChildren<T>();
1292 foreach (T val
in componentsInChildren)
1294 if (name ==
null || name == val.name)
1301 for (
int j = 0; j < c.transform.childCount; j++)
1303 T component = c.transform.GetChild(j).GetComponent<T>();
1304 if ((
bool)component && (name ==
null || name == component.name))
1312 public static GameObject
FindTagInParents(
this Component c,
string tag,
bool includeInactive =
true)
1314 Transform transform = c.transform;
1315 for (
int i = 0; i < transform.childCount; i++)
1317 Transform child = transform.GetChild(i);
1318 if ((includeInactive || child.gameObject.activeSelf) && child.tag == tag)
1320 return child.gameObject;
1323 if ((
bool)transform.parent)
1325 return transform.parent.FindTagInParents(tag, includeInactive);
1332 for (
int i = 0; i < c.childCount; i++)
1334 T component = c.GetChild(i).GetComponent<T>();
1335 if ((
bool)component)
1345 List<T> list =
new List<T>();
1346 Transform transform = comp.transform;
1347 for (
int i = 0; i < transform.childCount; i++)
1349 T component = transform.GetChild(i).GetComponent<T>();
1350 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1352 list.Add(component);
1360 List<T> list =
new List<T>();
1361 Transform transform = comp.transform;
1362 for (
int i = 0; i < transform.childCount; i++)
1364 T component = transform.GetChild(i).GetComponent<T>();
1365 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1367 list.Add(component);
1375 Transform transform = comp.transform;
1376 for (
int i = 0; i < transform.childCount; i++)
1378 T component = transform.GetChild(i).GetComponent<T>();
1379 if ((
bool)component)
1387 public static void DestroyChildren(
this Component component,
bool destroyInactive =
false,
bool ignoreDestroy =
true)
1389 if (!component || !component.transform)
1391 Debug.LogWarning(
"DestroyChlidren:" + component);
1394 for (
int num = component.transform.childCount - 1; num >= 0; num--)
1396 GameObject gameObject = component.transform.GetChild(num).gameObject;
1397 if ((!ignoreDestroy || !(gameObject.tag ==
"IgnoreDestroy")) && (destroyInactive || gameObject.activeSelf))
1399 UnityEngine.Object.DestroyImmediate(gameObject);
1406 return RectTransformUtility.RectangleContainsScreenPoint(r, Input.mousePosition, cam);
1413 foreach (Transform
item in c.transform)
1415 if (
item is RectTransform)
1417 item.RebuildLayout(recursive:
true);
1421 LayoutRebuilder.ForceRebuildLayoutImmediate(c.transform as RectTransform);
1427 if ((
bool)c.transform.parent && !c.transform.parent.GetComponent<T>())
1429 c.transform.parent.RebuildLayoutTo<T>();
1436 if (!(c == target) && (
bool)c.transform.parent)
1438 c.transform.parent.RebuildLayoutTo(target);
1442 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)
1444 r.SetPivot(pivotX, pivotY);
1445 r.SetAnchor(minX, minY, maxX, maxY);
1448 r.sizeDelta =
new Vector2(w, h);
1450 r.anchoredPosition =
new Vector2((x == -1f) ? r.anchoredPosition.x : x, (y == -1f) ? r.anchoredPosition.y : y);
1453 public static void SetPivot(
this RectTransform r,
float x,
float y)
1455 r.pivot =
new Vector2(x, y);
1458 public static void SetAnchor(
this RectTransform r,
float minX,
float minY,
float maxX,
float maxY)
1460 r.anchorMin =
new Vector2(minX, minY);
1461 r.anchorMax =
new Vector2(maxX, maxY);
1469 _rect.SetAnchor(0.5f, 1f, 0.5f, 1f);
1472 _rect.SetAnchor(0.5f, 0f, 0.5f, 0f);
1475 _rect.SetAnchor(0f, 1f, 0f, 1f);
1478 _rect.SetAnchor(1f, 1f, 1f, 1f);
1481 _rect.SetAnchor(0f, 0f, 0f, 0f);
1484 _rect.SetAnchor(1f, 0f, 1f, 0f);
1487 _rect.SetAnchor(0f, 0.5f, 0f, 0.5f);
1490 _rect.SetAnchor(1f, 0.5f, 1f, 0.5f);
1493 _rect.SetAnchor(0.5f, 0.5f, 0.5f, 0.5f);
1500 Vector3 position = _rect.position;
1501 _rect._SetAnchor((anchor ==
RectPosition.Auto) ? _rect.GetAnchor() : anchor);
1502 _rect.position = position;
1507 Vector3 position = _rect.position;
1508 int width = Screen.width;
1509 int height = Screen.height;
1510 bool flag = position.y > (float)height * 0.5f;
1511 if (position.x > (
float)width * 0.3f && position.x < (float)width * 0.7f)
1513 if (position.y > (
float)height * 0.3f && position.y < (float)height * 0.7f)
1523 if (position.x < (
float)width * 0.5f)
1540 return trans.GetChild(trans.childCount - 1);
1545 return new Vector2(
self.x,
self.z);
1548 public static void SetScale(
this SpriteRenderer renderer,
float size)
1550 float x = renderer.bounds.size.x;
1551 float y = renderer.bounds.size.y;
1552 float x2 = size / x;
1553 float y2 = size / y;
1554 renderer.transform.localScale =
new Vector3(x2, y2, 1f);
1559 if (
object.Equals(
forward, Vector2.up))
1563 object.Equals(
forward, Vector2.right);
1569 self.LookAt2D(target.position,
forward);
1575 Vector3 vector = target -
self.position;
1576 float num = Mathf.Atan2(vector.y, vector.x) * 57.29578f;
1577 self.rotation = Quaternion.AngleAxis(num - forwardDiffPoint, Vector3.forward);
1580 public static float Distance(
this Transform t, Vector2 pos)
1582 return Vector3.Distance(t.position, pos);
1585 public static Vector3
Plus(
this Vector3 v, Vector2 v2)
1592 public static Vector3
SetZ(
this Vector3 v,
float a)
1598 public static Vector3
SetY(
this Vector3 v,
float a)
1604 public static Vector3
PlusX(
this Vector3 v,
float a)
1610 public static Vector3
PlusY(
this Vector3 v,
float a)
1616 public static Vector3
PlusZ(
this Vector3 v,
float a)
1622 public static void SetPosition(
this Transform transform,
float x,
float y,
float z)
1630 vector3.Set(x, transform.position.y, transform.position.z);
1636 vector3.Set(transform.position.x, y, transform.position.z);
1642 vector3.Set(transform.position.x, transform.position.y, z);
1646 public static void AddPosition(
this Transform transform,
float x,
float y,
float z)
1648 vector3.Set(transform.position.x + x, transform.position.y + y, transform.position.z + z);
1654 vector3.Set(transform.position.x + x, transform.position.y, transform.position.z);
1660 vector3.Set(transform.position.x, transform.position.y + y, transform.position.z);
1666 vector3.Set(transform.position.x, transform.position.y, transform.position.z + z);
1673 transform.localPosition =
vector3;
1678 vector3.Set(x, transform.localPosition.y, transform.localPosition.z);
1679 transform.localPosition =
vector3;
1684 vector3.Set(transform.localPosition.x, y, transform.localPosition.z);
1685 transform.localPosition =
vector3;
1690 vector3.Set(transform.localPosition.x, transform.localPosition.y, z);
1691 transform.localPosition =
vector3;
1696 vector3.Set(transform.localPosition.x + x, transform.localPosition.y + y, transform.localPosition.z + z);
1697 transform.localPosition =
vector3;
1702 vector3.Set(transform.localPosition.x + x, transform.localPosition.y, transform.localPosition.z);
1703 transform.localPosition =
vector3;
1708 vector3.Set(transform.localPosition.x, transform.localPosition.y + y, transform.localPosition.z);
1709 transform.localPosition =
vector3;
1714 vector3.Set(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + z);
1715 transform.localPosition =
vector3;
1718 public static void SetLocalScale(
this Transform transform,
float x,
float y,
float z)
1721 transform.localScale =
vector3;
1726 vector3.Set(x, transform.localScale.y, transform.localScale.z);
1727 transform.localScale =
vector3;
1732 vector3.Set(transform.localScale.x, y, transform.localScale.z);
1733 transform.localScale =
vector3;
1738 vector3.Set(transform.localScale.x, transform.localScale.y, z);
1739 transform.localScale =
vector3;
1742 public static void AddLocalScale(
this Transform transform,
float x,
float y,
float z)
1744 vector3.Set(transform.localScale.x + x, transform.localScale.y + y, transform.localScale.z + z);
1745 transform.localScale =
vector3;
1750 vector3.Set(transform.localScale.x + x, transform.localScale.y, transform.localScale.z);
1751 transform.localScale =
vector3;
1756 vector3.Set(transform.localScale.x, transform.localScale.y + y, transform.localScale.z);
1757 transform.localScale =
vector3;
1762 vector3.Set(transform.localScale.x, transform.localScale.y, transform.localScale.z + z);
1763 transform.localScale =
vector3;
1766 public static void SetEulerAngles(
this Transform transform,
float x,
float y,
float z)
1769 transform.eulerAngles =
vector3;
1774 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1775 transform.eulerAngles =
vector3;
1780 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1781 transform.eulerAngles =
vector3;
1786 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1787 transform.eulerAngles =
vector3;
1790 public static void AddEulerAngles(
this Transform transform,
float x,
float y,
float z)
1792 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y + y, transform.eulerAngles.z + z);
1793 transform.eulerAngles =
vector3;
1798 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y, transform.eulerAngles.z);
1799 transform.eulerAngles =
vector3;
1804 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y + y, transform.eulerAngles.z);
1805 transform.eulerAngles =
vector3;
1810 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z + z);
1811 transform.eulerAngles =
vector3;
1817 transform.localEulerAngles =
vector3;
1822 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1823 transform.localEulerAngles =
vector3;
1828 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1829 transform.localEulerAngles =
vector3;
1834 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1835 transform.localEulerAngles =
vector3;
1840 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y + y, transform.localEulerAngles.z + z);
1841 transform.localEulerAngles =
vector3;
1846 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1847 transform.localEulerAngles =
vector3;
1852 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y + y, transform.localEulerAngles.z);
1853 transform.localEulerAngles =
vector3;
1858 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z + z);
1859 transform.localEulerAngles =
vector3;
1866 m.EnableKeyword(
id);
1870 m.DisableKeyword(
id);
1876 for (
int num = items.Count - 1; num >= 0; num--)
1884 int num = items.Count - 1;
1885 while (num >= 0 && !action(items[num]))
1895 return 360f - (0f - angle) % 360f;
1897 return angle % 360f;
1907 string name = s.name;
1908 T val = UnityEngine.Object.Instantiate(s);
1915 Type typeFromHandle = typeof(UnityEventBase);
1916 Assembly assembly = Assembly.GetAssembly(typeFromHandle);
1917 Type type = assembly.GetType(
"UnityEngine.Events.InvokableCallList");
1918 Type type2 = assembly.GetType(
"UnityEngine.Events.BaseInvokableCall");
1919 Type type3 = typeof(List<>).MakeGenericType(type2);
1920 FieldInfo field = typeFromHandle.GetField(
"m_Calls", BindingFlags.Instance | BindingFlags.NonPublic);
1921 FieldInfo field2 = type.GetField(
"m_RuntimeCalls", BindingFlags.Instance | BindingFlags.NonPublic);
1922 object value = field.GetValue(unityEvent);
1923 object value2 = field2.GetValue(value);
1924 return (
int)type3.GetProperty(
"Count").GetValue(value2,
null);
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 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 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 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 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 void LoopSelectable(this Transform l, bool vertical=true, bool horizonal=true, bool asGroup=true)
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 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 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 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 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)
static LangSetting setting
static string Get(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)