2using System.Collections;
3using System.Collections.Generic;
6using System.Reflection;
8using System.Text.RegularExpressions;
11using UnityEngine.Events;
20 public static string lang(
this string s)
31 public static string lang(
this string s,
string ref1,
string ref2 =
null,
string ref3 =
null,
string ref4 =
null,
string ref5 =
null)
33 return Lang.
Parse(s, ref1, ref2, ref3, ref4, ref5);
46 public static string langGame(
this string s,
string ref1,
string ref2 =
null,
string ref3 =
null,
string ref4 =
null)
53 return "(" + str +
")";
56 public static string Bracket(
this string str,
int type = 0)
65 _ =>
"_bracketLeft".lang() + str +
"_bracketRight".lang(),
69 public static byte[]
ToBytes(
this BitArray bits)
71 byte[] array =
new byte[(bits.Length - 1) / 8 + 1];
72 bits.CopyTo(array, 0);
76 public static bool GetBit(
this byte pByte,
int bitNo)
78 return (pByte & (1 << bitNo)) != 0;
81 public static byte SetBit(
this byte pByte,
int bitNo,
bool value)
85 return Convert.ToByte(pByte & ~(1 << bitNo));
87 return Convert.ToByte(pByte | (1 << bitNo));
90 public static int ToInt3(
this float a)
92 return (
int)(a * 1000f);
97 return (
float)a / 1000f;
102 return (
int)(a * 100f);
107 return (
float)a / 100f;
128 public static bool IsOn(
this int data,
int digit)
132 return bitArray[digit];
137 return (T)Enum.ToObject(typeof(T), value);
142 return (T)Enum.ToObject(typeof(T), value);
145 public static T
ToEnum<T>(
this string value,
bool ignoreCase =
true)
147 return (T)Enum.Parse(typeof(T), value, ignoreCase);
150 public static Type
ToType(
this string value)
152 return Type.GetType(
"Elona." + value +
", Assembly-CSharp");
157 return ((T[])Enum.GetValues(src.GetType())).NextItem(src);
162 return ((T[])Enum.GetValues(src.GetType())).PrevItem(src);
165 public static bool Within(
this int v,
int v2,
int range)
169 return v - v2 < -range;
174 public static bool Within(
this byte v,
byte v2,
byte range)
178 return v - v2 < -range;
183 public static int Clamp(
this int v,
int min,
int max,
bool loop =
false)
187 v = ((!loop) ? min : max);
191 v = ((!loop) ? max : min);
216 return (T)o.GetType().GetField(s).GetValue(o);
221 FieldInfo field = o.GetType().GetField(name);
224 return typeof(T).IsAssignableFrom(field.FieldType);
231 return (T)o.GetType().GetField(name).GetValue(o);
234 public static void SetField<T>(
this object o,
string name, T value)
236 o.GetType().GetField(name).SetValue(o, value);
241 return (T)o.GetType().GetProperty(name).GetValue(o);
246 o.GetType().GetProperty(name).SetValue(o, value);
249 public static void Sort<T>(
this IList<T> list, Comparison<T> comparison)
253 ((List<T>)list).Sort(comparison);
256 List<T> list2 =
new List<T>(list);
257 list2.Sort(comparison);
258 for (
int i = 0; i < list.Count; i++)
264 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
int defIndex = -1)
266 if (array.Count != 0)
268 if (index >= array.Count)
272 if (array.Count <= defIndex)
274 return array[Mathf.Max(0, array.Count - 1)];
276 return array[defIndex];
278 return array[Mathf.Max(0, array.Count - 1)];
280 return array[Math.Max(0, index)];
282 return default(TValue);
285 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
bool returnNull)
287 if (index >= array.Count)
289 return default(TValue);
298 return array.Length == 0;
303 public static int IndexOf(
this IList<Component> list, GameObject go)
309 for (
int i = 0; i < list.Count; i++)
311 if (list[i].gameObject == go)
319 public static TValue
Move<TValue>(
this IList<TValue> list, TValue target,
int a)
321 int num = list.IndexOf(target);
325 num2 = list.Count - 1;
327 if (num2 >= list.Count)
332 list.Insert(num2, target);
338 return list.ToList();
341 public static void Each<TValue>(
this IList<TValue> list, Action<TValue> action)
343 for (
int num = list.Count - 1; num >= 0; num--)
351 int num = list.Count;
356 TValue value = list[num];
357 list[num] = list[index];
365 TValue value =
default(TValue);
366 if (key !=
null && source.TryGetValue(key, out value))
375 TValue value =
default(TValue);
376 if (key !=
null && source.TryGetValue(key, out value))
380 return source[key_fallback];
385 TValue val = dict.TryGetValue(key);
388 val = ((func !=
null) ? func() : Activator.CreateInstance<TValue>());
396 TKey[] array =
new TKey[dict.Keys.Count];
397 dict.Keys.CopyTo(array, 0);
403 TValue[] array =
new TValue[dict.Keys.Count];
404 dict.Values.CopyTo(array, 0);
410 int num = ie.Count();
415 return ie.ElementAt(
Rand.
rnd(num));
420 if (source.Count != 0)
422 return source.ElementAt(
Rand.
rnd(source.Count)).Value;
424 return default(TValue);
429 if (source.Count != 0)
431 return source[
Rand.
rnd(source.Count)];
433 return default(TValue);
438 return source.RandomItem(source.IndexOf(exclude));
443 if (source.Count > 1)
450 while (num == exclude);
453 if (source.Count == 1)
457 return default(TValue);
460 public static TValue
RandomItem<TValue>(
this IList<TValue> source, Func<TValue, bool> funcValid, TValue defaultValue =
default(TValue))
462 for (
int i = 0; i < 100; i++)
464 TValue val = source[
Rand.
rnd(source.Count)];
475 if (source.Count == 0)
477 return default(TValue);
479 if (source.Count == 1)
484 foreach (TValue
item in source)
486 num += getWeight(
item);
490 foreach (TValue item2
in source)
492 num += getWeight(item2);
498 return source.First();
503 if (source.Count != 0)
505 return source[divider % source.Count];
507 return default(TValue);
514 return default(TValue);
516 return source[source.First().Key];
521 if (source.Count != 0)
523 return source[source.Count - 1];
525 return default(TValue);
531 if (index >= source.Count)
535 if (source.Count != 0)
537 return source[index];
539 return default(TValue);
548 int num = source.IndexOf(val) + 1;
549 if (num >= source.Count)
558 int num = source.IndexOf(val) + 1;
559 if (num >= source.Count)
563 if (source.Count != 0)
567 return default(TValue);
572 int num = source.IndexOf(val) - 1;
575 num = source.Count - 1;
577 if (source.Count != 0)
581 return default(TValue);
590 else if (i >= source.Count)
592 i = source.Count - 1;
599 List<T> list =
new List<T>();
600 foreach (
object value
in source.Values)
612 dic =
new Dictionary<string, T>();
613 for (
int i = 0; i < list.Count; i++)
615 dic.Add(list[i].name, list[i].value);
619 public static T
FindMax<T>(
this List<T> list, Func<T, int> func)
621 int num =
int.MinValue;
622 T result =
default(T);
623 foreach (T
item in list)
625 int num2 = func(
item);
635 public static void Set<T1, T2>(
this Dictionary<T1, T2> dic, Dictionary<T1, T2> from)
638 foreach (KeyValuePair<T1, T2>
item in from)
646 if (
string.IsNullOrEmpty(text))
648 return new string[0];
650 return text.Split(
new string[3] {
"\r\n",
"\n",
"\r" }, StringSplitOptions.None);
655 if (
string.IsNullOrEmpty(text))
659 return text.Replace(
"\r",
"").Replace(
"\n",
"");
664 if (
string.IsNullOrEmpty(text))
668 return Regex.Replace(text,
"<.*?>",
"");
671 public static int Calc(
this string str,
int power = 0,
int ele = 0,
int p2 = 0)
673 return Cal.Calcuate(str.Replace(
"p2", p2.ToString() ??
"").Replace(
"p", power.ToString() ??
"").Replace(
"e", ele.ToString() ??
"")
679 return str.ToInt(typeof(T));
682 public static int ToInt(
this string str, Type type)
684 FieldInfo field = type.GetField(str, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
687 Debug.LogError(
"Field is null:" + str +
"/" + type);
690 return (
int)field.GetValue(
null);
693 public static int ToInt(
this string str)
695 if (
int.TryParse(str, out var result))
702 public static long ToLong(
this string str)
704 if (
long.TryParse(str, out var result))
716 if (!
float.TryParse(str, out result))
718 Debug.Log(
"exception: ToFlat1" + str);
724 Debug.Log(
"exception: ToFlat2" + str);
739 public static string StripPun(
this string str,
bool stripComma,
bool insertSpaceForComma =
false)
741 StringBuilder stringBuilder =
new StringBuilder();
742 foreach (
char c
in str)
748 if (insertSpaceForComma)
750 stringBuilder.Append(
'\u3000');
755 stringBuilder.Append(c);
760 stringBuilder.Append(c);
763 return stringBuilder.ToString();
766 public static string Repeat(
this string str,
int count)
768 StringBuilder stringBuilder =
new StringBuilder();
769 for (
int i = 0; i < Mathf.Abs(count); i++)
771 stringBuilder.Append(str);
773 return stringBuilder.ToString();
778 HashSet<char> brackets =
new HashSet<char> {
'"',
'「',
'」',
'“',
'”' };
779 return string.Concat(str.Where((
char c) => !brackets.Contains(c)));
784 if (!s.Contains(
"." + ext))
786 return s +
"." + ext;
800 public static string IsEmpty(
this string str,
string defaultStr)
802 if (str !=
null && !(str ==
""))
811 while (text.EndsWith(Environment.NewLine))
813 text = text.Substring(0, text.Length - Environment.NewLine.Length);
820 string[] array = str.Split(separator);
821 int[] array2 =
new int[array.Length];
822 for (
int i = 0; i < array.Length; i++)
824 array2[i] =
int.Parse(array[i]);
831 return str.Split(Environment.NewLine.ToCharArray());
834 public static bool Contains(
this string[] strs,
string id)
836 if (strs ==
null || strs.Length == 0)
840 for (
int i = 0; i < strs.Length; i++)
850 public static string Evalute(
this string[] array,
float val)
852 return array[(int)Mathf.Clamp((
float)(array.Length - 1) * val, 0f, array.Length - 1)];
864 return a / 1000 +
"K";
874 text = a / 1000000 +
"M";
883 return a / 1000 +
"K";
885 text2 = a.ToString();
893 text2 = a / 1000000 +
"M";
908 public static string ToText(
this int a,
bool skipIfZero =
true)
911 if (!(a == 0 && skipIfZero))
932 return s +
"<color=" + c.ToHex() +
">" + txt +
"</color>";
937 return "<color=" + c.ToHex() +
">" + s +
"</color>";
940 public static string TagSize(
this string s,
string txt,
int size)
942 return s +
"<size=" + size +
">" + txt +
"</size>";
945 public static string TagSize(
this string s,
int size)
947 return "<size=" + size +
">" + s +
"</size>";
950 public static bool HasTag(
this string s,
string id,
char splitter =
'/')
952 return s.Split(splitter).Contains(
id);
955 public static string SetTag(
this string s,
string id,
bool enable,
char splitter =
'/')
957 s = ((!enable) ? s.RemoveTag(
id, splitter) : s.AddTag(
id, splitter));
961 public static string AddTag(
this string s,
string id,
char splitter =
'/')
963 if (!s.HasTag(
id, splitter))
965 s = s + (s.IsEmpty() ?
"" : ((object)splitter))?.ToString() + id;
970 public static string RemoveTag(
this string s,
string id,
char splitter =
'/')
972 string[] array = s.Split(splitter);
974 string[] array2 = array;
975 foreach (
string text
in array2)
979 s.AddTag(text, splitter);
987 return fileInfo.Directory.FullName +
"/" + Path.GetFileNameWithoutExtension(fileInfo.Name);
992 return new FileInfo(path).GetFullFileNameWithoutExtension();
1010 char c = s.ToLower()[0];
1011 s = ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a ") + s;
1022 string text = ((num >= 2) ? (num.ToFormat() +
" ") : ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a "));
1025 s = ((replace.IsEmpty() || !s.Contains(replace) || s.Contains(
"limestone stone")) ?
Pluralize(s) : s.Replace(replace,
Pluralize(replace)));
1029 ArticleStyle.The =>
"_the".lang().ToTitleCase() +
" " + ((num > 1) ? (num +
" ") :
"") + s,
1030 ArticleStyle.None => ((num > 1) ? (num.ToFormat() +
" ") :
"") + s.ToTitleCase(),
1035 public static string ToTitleCase(
this string s,
bool wholeText =
false)
1041 char[] array = s.ToCharArray();
1043 for (
int i = 0; i < array.Length; i++)
1047 array[i] =
char.ToUpper(array[i]);
1054 if (array[i] ==
' ')
1059 return new string(array);
1062 public static void LoopTail<T>(
this List<T> list,
bool vertical =
false) where T : Selectable
1066 Navigation navigation = list[0].navigation;
1067 Navigation navigation2 = list[list.Count - 1].navigation;
1070 navigation.selectOnUp = list[list.Count - 1];
1071 navigation2.selectOnDown = list[0];
1075 navigation.selectOnLeft = list[list.Count - 1];
1076 navigation2.selectOnRight = list[0];
1078 list[0].navigation = navigation;
1079 list[list.Count - 1].navigation = navigation2;
1083 public static void SetNavigation(
this Component a, Component b,
bool vertical =
false)
1089 Selectable component = a.GetComponent<Selectable>();
1090 Selectable component2 = b.GetComponent<Selectable>();
1091 if ((
bool)component && (bool)component2)
1093 Navigation navigation = component.navigation;
1094 Navigation navigation2 = component2.navigation;
1097 navigation.selectOnUp = component2;
1098 navigation2.selectOnDown = component;
1102 navigation.selectOnLeft = component2;
1103 navigation2.selectOnRight = component;
1105 component.navigation = navigation;
1106 component2.navigation = navigation2;
1110 public static void LoopSelectable(
this List<Selectable> sels,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1112 for (
int i = 0; i < sels.Count; i++)
1114 Selectable selectable = sels[i];
1115 Selectable selectable2 = sels[0];
1116 Navigation navigation = selectable.navigation;
1119 navigation.selectOnRight = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1123 for (
int j = i + 1; j < sels.Count; j++)
1125 if (sels[j].transform.position.y < selectable.transform.position.y)
1127 selectable2 = sels[j];
1134 selectable2 = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1138 navigation.selectOnDown = selectable2;
1140 selectable.navigation = navigation;
1142 for (
int num = sels.Count - 1; num >= 0; num--)
1144 Selectable selectable3 = sels[num];
1145 Selectable selectable4 = sels[sels.Count - 1];
1146 Navigation navigation2 = selectable3.navigation;
1149 navigation2.selectOnLeft = ((num > 0) ? sels[num - 1] : selectable4);
1153 int num2 = sels.Count - 1;
1154 for (
int num3 = num - 1; num3 >= 0; num3--)
1156 if (sels[num3].transform.position.y > selectable3.transform.position.y)
1163 while (num4 >= 0 && !(sels[num4].transform.position.y > sels[num2].transform.position.y))
1165 selectable4 = sels[num4];
1171 selectable4 = ((num > 0) ? sels[num - 1] : selectable4);
1175 navigation2.selectOnUp = ((selectable4 == selectable3) ? sels[sels.Count - 1] : selectable4);
1177 navigation2.mode = Navigation.Mode.Explicit;
1178 selectable3.navigation = navigation2;
1182 public static void LoopSelectable(
this Transform l,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1184 List<Selectable> list = l.GetComponentsInChildren<Selectable>().ToList();
1185 for (
int num = list.Count - 1; num >= 0; num--)
1187 if (!list[num].interactable || list[num].navigation.mode == Navigation.Mode.None)
1192 list.LoopSelectable(vertical, horizonal, asGroup);
1198 ColorUtility.TryParseHtmlString(
"#" + s, out color);
1204 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1209 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1220 return new Color(c.r * mtp + add, c.g * mtp + add, c.b * mtp + add, c.a);
1225 return "<color=" +
$"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}" +
">";
1230 return $"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}";
1235 b.onClick.RemoveAllListeners();
1236 b.onClick.AddListener(delegate
1244 e.RemoveAllListeners();
1245 e.AddListener(delegate
1251 public static void SetAlpha(
this Text text,
float aloha = 1f)
1253 text.color =
new Color(text.color.r, text.color.g, text.color.b, aloha);
1256 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
bool notify)
1258 slider.SetSlider(value, action, -1, -1, notify);
1261 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
int min = -1,
int max = -1,
bool notify =
true)
1263 slider.onValueChanged.RemoveAllListeners();
1264 slider.onValueChanged.AddListener(delegate(
float a)
1266 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(a);
1270 slider.minValue = min;
1271 slider.maxValue = max;
1275 slider.value = value;
1279 slider.SetValueWithoutNotify(value);
1281 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(value);
1286 T val = t.gameObject.GetComponent<T>();
1289 val = t.gameObject.AddComponent<T>();
1294 public static RectTransform
Rect(
this Component c)
1296 return c.transform as RectTransform;
1299 public static void CopyRect(
this RectTransform r, RectTransform t)
1302 r.sizeDelta = t.sizeDelta;
1303 r.anchorMin = t.anchorMin;
1304 r.anchorMax = t.anchorMax;
1305 r.anchoredPosition = t.anchoredPosition;
1310 c.SetActive(!c.gameObject.activeSelf);
1315 if (c.gameObject.activeSelf != enable)
1317 c.gameObject.SetActive(enable);
1321 public static void SetActive(
this Component c,
bool enable, Action<bool> onChangeState)
1323 if (c.gameObject.activeSelf != enable)
1325 c.gameObject.SetActive(enable);
1326 onChangeState(enable);
1332 return go.GetComponentInChildren<Selectable>();
1338 foreach (Transform
item in obj.transform)
1340 item.gameObject.SetLayerRecursively(layer);
1346 Selectable selectable = (obj ? obj.GetComponent<Selectable>() :
null);
1347 if ((
bool)selectable)
1349 return selectable.interactable;
1354 public static bool IsChildOf(
this GameObject c, GameObject root)
1356 if (c.transform == root.transform)
1360 if ((
bool)c.transform.parent)
1362 return c.transform.parent.gameObject.IsChildOf(root);
1369 return c.gameObject.scene.name ==
null;
1372 public static T
CreateMold<T>(
this Component c,
string name =
null) where T : Component
1375 for (
int i = 0; i < c.transform.childCount; i++)
1377 T component = c.transform.GetChild(i).GetComponent<T>();
1378 if ((
bool)component && (name.IsEmpty() || name == component.name))
1380 component.gameObject.SetActive(value:
false);
1385 c.DestroyChildren();
1389 public static Transform
Find(
this Component c,
string name =
null)
1391 return c.Find<Transform>(name);
1394 public static T
Find<T>(
this Component c,
string name =
null,
bool recursive =
false) where T : Component
1398 T[] componentsInChildren = c.transform.GetComponentsInChildren<T>();
1399 foreach (T val
in componentsInChildren)
1401 if (name ==
null || name == val.name)
1408 for (
int j = 0; j < c.transform.childCount; j++)
1410 T component = c.transform.GetChild(j).GetComponent<T>();
1411 if ((
bool)component && (name ==
null || name == component.name))
1419 public static GameObject
FindTagInParents(
this Component c,
string tag,
bool includeInactive =
true)
1421 Transform transform = c.transform;
1422 for (
int i = 0; i < transform.childCount; i++)
1424 Transform child = transform.GetChild(i);
1425 if ((includeInactive || child.gameObject.activeSelf) && child.tag == tag)
1427 return child.gameObject;
1430 if ((
bool)transform.parent)
1432 return transform.parent.FindTagInParents(tag, includeInactive);
1439 for (
int i = 0; i < c.childCount; i++)
1441 T component = c.GetChild(i).GetComponent<T>();
1442 if ((
bool)component)
1452 List<T> list =
new List<T>();
1453 Transform transform = comp.transform;
1454 for (
int i = 0; i < transform.childCount; i++)
1456 T component = transform.GetChild(i).GetComponent<T>();
1457 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1459 list.Add(component);
1467 List<T> list =
new List<T>();
1468 Transform transform = comp.transform;
1469 for (
int i = 0; i < transform.childCount; i++)
1471 T component = transform.GetChild(i).GetComponent<T>();
1472 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1474 list.Add(component);
1482 Transform transform = comp.transform;
1483 for (
int i = 0; i < transform.childCount; i++)
1485 T component = transform.GetChild(i).GetComponent<T>();
1486 if ((
bool)component)
1494 public static void DestroyChildren(
this Component component,
bool destroyInactive =
false,
bool ignoreDestroy =
true)
1496 if (!component || !component.transform)
1498 Debug.LogWarning(
"DestroyChlidren:" + component);
1501 for (
int num = component.transform.childCount - 1; num >= 0; num--)
1503 GameObject gameObject = component.transform.GetChild(num).gameObject;
1504 if ((!ignoreDestroy || !(gameObject.tag ==
"IgnoreDestroy")) && (destroyInactive || gameObject.activeSelf))
1506 UnityEngine.Object.DestroyImmediate(gameObject);
1513 return RectTransformUtility.RectangleContainsScreenPoint(r, Input.mousePosition, cam);
1520 foreach (Transform
item in c.transform)
1522 if (
item is RectTransform)
1524 item.RebuildLayout(recursive:
true);
1528 LayoutRebuilder.ForceRebuildLayoutImmediate(c.transform as RectTransform);
1534 if ((
bool)c.transform.parent && !c.transform.parent.GetComponent<T>())
1536 c.transform.parent.RebuildLayoutTo<T>();
1543 if (!(c == target) && (
bool)c.transform.parent)
1545 c.transform.parent.RebuildLayoutTo(target);
1549 public static void SetRect(
this RectTransform r,
float x,
float y,
float w,
float h,
float pivotX,
float pivotY,
float minX,
float minY,
float maxX,
float maxY)
1551 r.SetPivot(pivotX, pivotY);
1552 r.SetAnchor(minX, minY, maxX, maxY);
1555 r.sizeDelta =
new Vector2(w, h);
1557 r.anchoredPosition =
new Vector2((x == -1f) ? r.anchoredPosition.x : x, (y == -1f) ? r.anchoredPosition.y : y);
1560 public static void SetPivot(
this RectTransform r,
float x,
float y)
1562 r.pivot =
new Vector2(x, y);
1565 public static void SetAnchor(
this RectTransform r,
float minX,
float minY,
float maxX,
float maxY)
1567 r.anchorMin =
new Vector2(minX, minY);
1568 r.anchorMax =
new Vector2(maxX, maxY);
1576 _rect.SetAnchor(0.5f, 1f, 0.5f, 1f);
1579 _rect.SetAnchor(0.5f, 0f, 0.5f, 0f);
1582 _rect.SetAnchor(0f, 1f, 0f, 1f);
1585 _rect.SetAnchor(1f, 1f, 1f, 1f);
1588 _rect.SetAnchor(0f, 0f, 0f, 0f);
1591 _rect.SetAnchor(1f, 0f, 1f, 0f);
1594 _rect.SetAnchor(0f, 0.5f, 0f, 0.5f);
1597 _rect.SetAnchor(1f, 0.5f, 1f, 0.5f);
1600 _rect.SetAnchor(0.5f, 0.5f, 0.5f, 0.5f);
1607 Vector3 position = _rect.position;
1608 _rect._SetAnchor((anchor ==
RectPosition.Auto) ? _rect.GetAnchor() : anchor);
1609 _rect.position = position;
1614 Vector3 position = _rect.position;
1615 int width = Screen.width;
1616 int height = Screen.height;
1617 bool flag = position.y > (float)height * 0.5f;
1618 if (position.x > (
float)width * 0.3f && position.x < (float)width * 0.7f)
1620 if (position.y > (
float)height * 0.3f && position.y < (float)height * 0.7f)
1630 if (position.x < (
float)width * 0.5f)
1647 return trans.GetChild(trans.childCount - 1);
1652 return new Vector2(
self.x,
self.z);
1655 public static void SetScale(
this SpriteRenderer renderer,
float size)
1657 float x = renderer.bounds.size.x;
1658 float y = renderer.bounds.size.y;
1659 float x2 = size / x;
1660 float y2 = size / y;
1661 renderer.transform.localScale =
new Vector3(x2, y2, 1f);
1666 if (
object.Equals(
forward, Vector2.up))
1670 object.Equals(
forward, Vector2.right);
1676 self.LookAt2D(target.position,
forward);
1682 Vector3 vector = target -
self.position;
1683 float num = Mathf.Atan2(vector.y, vector.x) * 57.29578f;
1684 self.rotation = Quaternion.AngleAxis(num - forwardDiffPoint, Vector3.forward);
1687 public static float Distance(
this Transform t, Vector2 pos)
1689 return Vector3.Distance(t.position, pos);
1692 public static Vector3
Plus(
this Vector3 v, Vector2 v2)
1699 public static Vector3
SetZ(
this Vector3 v,
float a)
1705 public static Vector3
SetY(
this Vector3 v,
float a)
1711 public static Vector3
PlusX(
this Vector3 v,
float a)
1717 public static Vector3
PlusY(
this Vector3 v,
float a)
1723 public static Vector3
PlusZ(
this Vector3 v,
float a)
1729 public static void SetPosition(
this Transform transform,
float x,
float y,
float z)
1737 vector3.Set(x, transform.position.y, transform.position.z);
1743 vector3.Set(transform.position.x, y, transform.position.z);
1749 vector3.Set(transform.position.x, transform.position.y, z);
1753 public static void AddPosition(
this Transform transform,
float x,
float y,
float z)
1755 vector3.Set(transform.position.x + x, transform.position.y + y, transform.position.z + z);
1761 vector3.Set(transform.position.x + x, transform.position.y, transform.position.z);
1767 vector3.Set(transform.position.x, transform.position.y + y, transform.position.z);
1773 vector3.Set(transform.position.x, transform.position.y, transform.position.z + z);
1780 transform.localPosition =
vector3;
1785 vector3.Set(x, transform.localPosition.y, transform.localPosition.z);
1786 transform.localPosition =
vector3;
1791 vector3.Set(transform.localPosition.x, y, transform.localPosition.z);
1792 transform.localPosition =
vector3;
1797 vector3.Set(transform.localPosition.x, transform.localPosition.y, z);
1798 transform.localPosition =
vector3;
1803 vector3.Set(transform.localPosition.x + x, transform.localPosition.y + y, transform.localPosition.z + z);
1804 transform.localPosition =
vector3;
1809 vector3.Set(transform.localPosition.x + x, transform.localPosition.y, transform.localPosition.z);
1810 transform.localPosition =
vector3;
1815 vector3.Set(transform.localPosition.x, transform.localPosition.y + y, transform.localPosition.z);
1816 transform.localPosition =
vector3;
1821 vector3.Set(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + z);
1822 transform.localPosition =
vector3;
1825 public static void SetLocalScale(
this Transform transform,
float x,
float y,
float z)
1828 transform.localScale =
vector3;
1833 vector3.Set(x, transform.localScale.y, transform.localScale.z);
1834 transform.localScale =
vector3;
1839 vector3.Set(transform.localScale.x, y, transform.localScale.z);
1840 transform.localScale =
vector3;
1845 vector3.Set(transform.localScale.x, transform.localScale.y, z);
1846 transform.localScale =
vector3;
1849 public static void AddLocalScale(
this Transform transform,
float x,
float y,
float z)
1851 vector3.Set(transform.localScale.x + x, transform.localScale.y + y, transform.localScale.z + z);
1852 transform.localScale =
vector3;
1857 vector3.Set(transform.localScale.x + x, transform.localScale.y, transform.localScale.z);
1858 transform.localScale =
vector3;
1863 vector3.Set(transform.localScale.x, transform.localScale.y + y, transform.localScale.z);
1864 transform.localScale =
vector3;
1869 vector3.Set(transform.localScale.x, transform.localScale.y, transform.localScale.z + z);
1870 transform.localScale =
vector3;
1873 public static void SetEulerAngles(
this Transform transform,
float x,
float y,
float z)
1876 transform.eulerAngles =
vector3;
1881 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1882 transform.eulerAngles =
vector3;
1887 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1888 transform.eulerAngles =
vector3;
1893 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1894 transform.eulerAngles =
vector3;
1897 public static void AddEulerAngles(
this Transform transform,
float x,
float y,
float z)
1899 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y + y, transform.eulerAngles.z + z);
1900 transform.eulerAngles =
vector3;
1905 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y, transform.eulerAngles.z);
1906 transform.eulerAngles =
vector3;
1911 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y + y, transform.eulerAngles.z);
1912 transform.eulerAngles =
vector3;
1917 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z + z);
1918 transform.eulerAngles =
vector3;
1924 transform.localEulerAngles =
vector3;
1929 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1930 transform.localEulerAngles =
vector3;
1935 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1936 transform.localEulerAngles =
vector3;
1941 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1942 transform.localEulerAngles =
vector3;
1947 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y + y, transform.localEulerAngles.z + z);
1948 transform.localEulerAngles =
vector3;
1953 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1954 transform.localEulerAngles =
vector3;
1959 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y + y, transform.localEulerAngles.z);
1960 transform.localEulerAngles =
vector3;
1965 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z + z);
1966 transform.localEulerAngles =
vector3;
1973 m.EnableKeyword(
id);
1977 m.DisableKeyword(
id);
1983 for (
int num = items.Count - 1; num >= 0; num--)
1991 int num = items.Count - 1;
1992 while (num >= 0 && !action(items[num]))
2002 return 360f - (0f - angle) % 360f;
2004 return angle % 360f;
2014 string name = s.name;
2015 T val = UnityEngine.Object.Instantiate(s);
2022 Type typeFromHandle = typeof(UnityEventBase);
2023 Assembly assembly = Assembly.GetAssembly(typeFromHandle);
2024 Type type = assembly.GetType(
"UnityEngine.Events.InvokableCallList");
2025 Type type2 = assembly.GetType(
"UnityEngine.Events.BaseInvokableCall");
2026 Type type3 = typeof(List<>).MakeGenericType(type2);
2027 FieldInfo field = typeFromHandle.GetField(
"m_Calls", BindingFlags.Instance | BindingFlags.NonPublic);
2028 FieldInfo field2 = type.GetField(
"m_RuntimeCalls", BindingFlags.Instance | BindingFlags.NonPublic);
2029 object value = field.GetValue(unityEvent);
2030 object value2 = field2.GetValue(value);
2031 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 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 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)
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)