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);
45 public static string langGame(
this string s,
string ref1,
string ref2 =
null,
string ref3 =
null,
string ref4 =
null)
52 return "(" + str +
")";
55 public static string Bracket(
this string str,
int type = 0)
64 _ =>
"_bracketLeft".lang() + str +
"_bracketRight".lang(),
68 public static byte[]
ToBytes(
this BitArray bits)
70 byte[] array =
new byte[(bits.Length - 1) / 8 + 1];
71 bits.CopyTo(array, 0);
75 public static bool GetBit(
this byte pByte,
int bitNo)
77 return (pByte & (1 << bitNo)) != 0;
80 public static byte SetBit(
this byte pByte,
int bitNo,
bool value)
84 return Convert.ToByte(pByte & ~(1 << bitNo));
86 return Convert.ToByte(pByte | (1 << bitNo));
89 public static int ToInt3(
this float a)
91 return (
int)(a * 1000f);
96 return (
float)a / 1000f;
99 public static int ToInt2(
this float a)
101 return (
int)(a * 100f);
106 return (
float)a / 100f;
127 public static bool IsOn(
this int data,
int digit)
131 return bitArray[digit];
136 return (T)Enum.ToObject(typeof(T), value);
141 return (T)Enum.ToObject(typeof(T), value);
144 public static T
ToEnum<T>(
this string value,
bool ignoreCase =
true)
146 return (T)Enum.Parse(typeof(T), value, ignoreCase);
149 public static Type
ToType(
this string value)
151 return Type.GetType(
"Elona." + value +
", Assembly-CSharp");
156 return ((T[])Enum.GetValues(src.GetType())).NextItem(src);
161 return ((T[])Enum.GetValues(src.GetType())).PrevItem(src);
164 public static bool Within(
this int v,
int v2,
int range)
168 return v - v2 < -range;
173 public static bool Within(
this byte v,
byte v2,
byte range)
177 return v - v2 < -range;
182 public static int Clamp(
this int v,
int min,
int max,
bool loop =
false)
186 v = ((!loop) ? min : max);
190 v = ((!loop) ? max : min);
215 return (T)o.GetType().GetField(s).GetValue(o);
220 FieldInfo field = o.GetType().GetField(name);
223 return typeof(T).IsAssignableFrom(field.FieldType);
230 return (T)o.GetType().GetField(name).GetValue(o);
233 public static void SetField<T>(
this object o,
string name, T value)
235 o.GetType().GetField(name).SetValue(o, value);
240 return (T)o.GetType().GetProperty(name).GetValue(o);
245 o.GetType().GetProperty(name).SetValue(o, value);
248 public static void Sort<T>(
this IList<T> list, Comparison<T> comparison)
252 ((List<T>)list).Sort(comparison);
255 List<T> list2 =
new List<T>(list);
256 list2.Sort(comparison);
257 for (
int i = 0; i < list.Count; i++)
263 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
int defIndex = -1)
265 if (array.Count != 0)
267 if (index >= array.Count)
271 if (array.Count <= defIndex)
273 return array[Mathf.Max(0, array.Count - 1)];
275 return array[defIndex];
277 return array[Mathf.Max(0, array.Count - 1)];
279 return array[Math.Max(0, index)];
281 return default(TValue);
284 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
bool returnNull)
286 if (index >= array.Count)
288 return default(TValue);
297 return array.Length == 0;
302 public static int IndexOf(
this IList<Component> list, GameObject go)
308 for (
int i = 0; i < list.Count; i++)
310 if (list[i].gameObject == go)
318 public static TValue
Move<TValue>(
this IList<TValue> list, TValue target,
int a)
320 int num = list.IndexOf(target);
324 num2 = list.Count - 1;
326 if (num2 >= list.Count)
331 list.Insert(num2, target);
337 return list.ToList();
340 public static void Each<TValue>(
this IList<TValue> list, Action<TValue> action)
342 for (
int num = list.Count - 1; num >= 0; num--)
350 int num = list.Count;
355 TValue value = list[num];
356 list[num] = list[index];
364 TValue value =
default(TValue);
365 if (key !=
null && source.TryGetValue(key, out value))
374 TValue value =
default(TValue);
375 if (key !=
null && source.TryGetValue(key, out value))
379 return source[key_fallback];
384 TValue val = dict.TryGetValue(key);
387 val = ((func !=
null) ? func() : Activator.CreateInstance<TValue>());
395 TKey[] array =
new TKey[dict.Keys.Count];
396 dict.Keys.CopyTo(array, 0);
402 TValue[] array =
new TValue[dict.Keys.Count];
403 dict.Values.CopyTo(array, 0);
409 int num = ie.Count();
414 return ie.ElementAt(
Rand.
rnd(num));
419 if (source.Count != 0)
421 return source.ElementAt(
Rand.
rnd(source.Count)).Value;
423 return default(TValue);
428 if (source.Count != 0)
430 return source[
Rand.
rnd(source.Count)];
432 return default(TValue);
437 return source.RandomItem(source.IndexOf(exclude));
442 if (source.Count > 1)
449 while (num == exclude);
452 if (source.Count == 1)
456 return default(TValue);
459 public static TValue
RandomItem<TValue>(
this IList<TValue> source, Func<TValue, bool> funcValid, TValue defaultValue =
default(TValue))
461 for (
int i = 0; i < 100; i++)
463 TValue val = source[
Rand.
rnd(source.Count)];
474 if (source.Count == 0)
476 return default(TValue);
478 if (source.Count == 1)
483 foreach (TValue
item in source)
485 num += getWeight(
item);
489 foreach (TValue item2
in source)
491 num += getWeight(item2);
497 return source.First();
502 if (source.Count != 0)
504 return source[divider % source.Count];
506 return default(TValue);
513 return default(TValue);
515 return source[source.First().Key];
520 if (source.Count != 0)
522 return source[source.Count - 1];
524 return default(TValue);
530 if (index >= source.Count)
534 if (source.Count != 0)
536 return source[index];
538 return default(TValue);
547 int num = source.IndexOf(val) + 1;
548 if (num >= source.Count)
557 int num = source.IndexOf(val) + 1;
558 if (num >= source.Count)
562 if (source.Count != 0)
566 return default(TValue);
571 int num = source.IndexOf(val) - 1;
574 num = source.Count - 1;
576 if (source.Count != 0)
580 return default(TValue);
589 else if (i >= source.Count)
591 i = source.Count - 1;
598 List<T> list =
new List<T>();
599 foreach (
object value
in source.Values)
611 dic =
new Dictionary<string, T>();
612 for (
int i = 0; i < list.Count; i++)
614 dic.Add(list[i].name, list[i].value);
618 public static T
FindMax<T>(
this List<T> list, Func<T, int> func)
620 int num =
int.MinValue;
621 T result =
default(T);
622 foreach (T
item in list)
624 int num2 = func(
item);
634 public static void Set<T1, T2>(
this Dictionary<T1, T2> dic, Dictionary<T1, T2> from)
637 foreach (KeyValuePair<T1, T2>
item in from)
643 public static int Calc(
this string str,
int power = 0,
int ele = 0,
int p2 = 0)
645 return Cal.Calcuate(str.Replace(
"p2", p2.ToString() ??
"").Replace(
"p", power.ToString() ??
"").Replace(
"e", ele.ToString() ??
"")
651 return str.ToInt(typeof(T));
654 public static int ToInt(
this string str, Type type)
656 FieldInfo field = type.GetField(str, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
659 Debug.LogError(
"Field is null:" + str +
"/" + type);
662 return (
int)field.GetValue(
null);
665 public static int ToInt(
this string str)
667 if (
int.TryParse(str, out var result))
679 if (!
float.TryParse(str, out result))
681 Debug.Log(
"exception: ToFlat1" + str);
687 Debug.Log(
"exception: ToFlat2" + str);
702 public static string StripPun(
this string str,
bool stripComma,
bool insertSpaceForComma =
false)
704 StringBuilder stringBuilder =
new StringBuilder();
705 foreach (
char c
in str)
711 if (insertSpaceForComma)
713 stringBuilder.Append(
'\u3000');
718 stringBuilder.Append(c);
723 stringBuilder.Append(c);
726 return stringBuilder.ToString();
729 public static string Repeat(
this string str,
int count)
731 StringBuilder stringBuilder =
new StringBuilder();
732 for (
int i = 0; i < Mathf.Abs(count); i++)
734 stringBuilder.Append(str);
736 return stringBuilder.ToString();
741 return str.Replace(
"\"",
"").Replace(
"「",
"").Replace(
"」",
"")
748 if (!s.Contains(
"." + ext))
750 return s +
"." + ext;
764 public static string IsEmpty(
this string str,
string defaultStr)
766 if (str !=
null && !(str ==
""))
775 while (text.EndsWith(Environment.NewLine))
777 text = text.Substring(0, text.Length - Environment.NewLine.Length);
784 string[] array = str.Split(separator);
785 int[] array2 =
new int[array.Length];
786 for (
int i = 0; i < array.Length; i++)
788 array2[i] =
int.Parse(array[i]);
795 return str.Split(Environment.NewLine.ToCharArray());
798 public static bool Contains(
this string[] strs,
string id)
800 if (strs ==
null || strs.Length == 0)
804 for (
int i = 0; i < strs.Length; i++)
814 public static string Evalute(
this string[] array,
float val)
816 return array[(int)Mathf.Clamp((
float)(array.Length - 1) * val, 0f, array.Length - 1)];
828 return a / 1000 +
"K";
838 text = a / 1000000 +
"M";
847 return a / 1000 +
"K";
849 text2 = a.ToString();
857 text2 = a / 1000000 +
"M";
872 public static string ToText(
this int a,
bool skipIfZero =
true)
875 if (!(a == 0 && skipIfZero))
896 return s +
"<color=" + c.ToHex() +
">" + txt +
"</color>";
901 return "<color=" + c.ToHex() +
">" + s +
"</color>";
904 public static string TagSize(
this string s,
string txt,
int size)
906 return s +
"<size=" + size +
">" + txt +
"</size>";
909 public static string TagSize(
this string s,
int size)
911 return "<size=" + size +
">" + s +
"</size>";
914 public static bool HasTag(
this string s,
string id,
char splitter =
'/')
916 return s.Split(splitter).Contains(
id);
919 public static string SetTag(
this string s,
string id,
bool enable,
char splitter =
'/')
921 s = ((!enable) ? s.RemoveTag(
id, splitter) : s.AddTag(
id, splitter));
925 public static string AddTag(
this string s,
string id,
char splitter =
'/')
927 if (!s.HasTag(
id, splitter))
929 s = s + (s.IsEmpty() ?
"" : ((object)splitter))?.ToString() + id;
934 public static string RemoveTag(
this string s,
string id,
char splitter =
'/')
936 string[] array = s.Split(splitter);
938 string[] array2 = array;
939 foreach (
string text
in array2)
943 s.AddTag(text, splitter);
951 return fileInfo.Directory.FullName +
"/" + Path.GetFileNameWithoutExtension(fileInfo.Name);
956 return new FileInfo(path).GetFullFileNameWithoutExtension();
974 char c = s.ToLower()[0];
975 s = ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a ") + s;
986 string text = ((num >= 2) ? (num.ToFormat() +
" ") : ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a "));
989 s = ((replace.IsEmpty() || !s.Contains(replace) || s.Contains(
"limestone stone")) ?
Pluralize(s) : s.Replace(replace,
Pluralize(replace)));
993 ArticleStyle.The =>
"_the".lang().ToTitleCase() +
" " + ((num > 1) ? (num +
" ") :
"") + s,
994 ArticleStyle.None => ((num > 1) ? (num.ToFormat() +
" ") :
"") + s.ToTitleCase(),
999 public static string ToTitleCase(
this string s,
bool wholeText =
false)
1005 char[] array = s.ToCharArray();
1007 for (
int i = 0; i < array.Length; i++)
1011 array[i] =
char.ToUpper(array[i]);
1018 if (array[i] ==
' ')
1023 return new string(array);
1026 public static void LoopTail<T>(
this List<T> list,
bool vertical =
false) where T : Selectable
1030 Navigation navigation = list[0].navigation;
1031 Navigation navigation2 = list[list.Count - 1].navigation;
1034 navigation.selectOnUp = list[list.Count - 1];
1035 navigation2.selectOnDown = list[0];
1039 navigation.selectOnLeft = list[list.Count - 1];
1040 navigation2.selectOnRight = list[0];
1042 list[0].navigation = navigation;
1043 list[list.Count - 1].navigation = navigation2;
1047 public static void SetNavigation(
this Component a, Component b,
bool vertical =
false)
1053 Selectable component = a.GetComponent<Selectable>();
1054 Selectable component2 = b.GetComponent<Selectable>();
1055 if ((
bool)component && (bool)component2)
1057 Navigation navigation = component.navigation;
1058 Navigation navigation2 = component2.navigation;
1061 navigation.selectOnUp = component2;
1062 navigation2.selectOnDown = component;
1066 navigation.selectOnLeft = component2;
1067 navigation2.selectOnRight = component;
1069 component.navigation = navigation;
1070 component2.navigation = navigation2;
1074 public static void LoopSelectable(
this List<Selectable> sels,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1076 for (
int i = 0; i < sels.Count; i++)
1078 Selectable selectable = sels[i];
1079 Selectable selectable2 = sels[0];
1080 Navigation navigation = selectable.navigation;
1083 navigation.selectOnRight = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1087 for (
int j = i + 1; j < sels.Count; j++)
1089 if (sels[j].transform.position.y < selectable.transform.position.y)
1091 selectable2 = sels[j];
1098 selectable2 = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1102 navigation.selectOnDown = selectable2;
1104 selectable.navigation = navigation;
1106 for (
int num = sels.Count - 1; num >= 0; num--)
1108 Selectable selectable3 = sels[num];
1109 Selectable selectable4 = sels[sels.Count - 1];
1110 Navigation navigation2 = selectable3.navigation;
1113 navigation2.selectOnLeft = ((num > 0) ? sels[num - 1] : selectable4);
1117 int num2 = sels.Count - 1;
1118 for (
int num3 = num - 1; num3 >= 0; num3--)
1120 if (sels[num3].transform.position.y > selectable3.transform.position.y)
1127 while (num4 >= 0 && !(sels[num4].transform.position.y > sels[num2].transform.position.y))
1129 selectable4 = sels[num4];
1135 selectable4 = ((num > 0) ? sels[num - 1] : selectable4);
1139 navigation2.selectOnUp = ((selectable4 == selectable3) ? sels[sels.Count - 1] : selectable4);
1141 navigation2.mode = Navigation.Mode.Explicit;
1142 selectable3.navigation = navigation2;
1146 public static void LoopSelectable(
this Transform l,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1148 List<Selectable> list = l.GetComponentsInChildren<Selectable>().ToList();
1149 for (
int num = list.Count - 1; num >= 0; num--)
1151 if (!list[num].interactable || list[num].navigation.mode == Navigation.Mode.None)
1156 list.LoopSelectable(vertical, horizonal, asGroup);
1162 ColorUtility.TryParseHtmlString(
"#" + s, out color);
1168 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1173 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1184 return new Color(c.r * mtp + add, c.g * mtp + add, c.b * mtp + add, c.a);
1189 return "<color=" +
$"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}" +
">";
1194 return $"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}";
1199 b.onClick.RemoveAllListeners();
1200 b.onClick.AddListener(delegate
1208 e.RemoveAllListeners();
1209 e.AddListener(delegate
1215 public static void SetAlpha(
this Text text,
float aloha = 1f)
1217 text.color =
new Color(text.color.r, text.color.g, text.color.b, aloha);
1220 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
bool notify)
1222 slider.SetSlider(value, action, -1, -1, notify);
1225 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
int min = -1,
int max = -1,
bool notify =
true)
1227 slider.onValueChanged.RemoveAllListeners();
1228 slider.onValueChanged.AddListener(delegate(
float a)
1230 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(a);
1234 slider.minValue = min;
1235 slider.maxValue = max;
1239 slider.value = value;
1243 slider.SetValueWithoutNotify(value);
1245 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(value);
1250 T val = t.gameObject.GetComponent<T>();
1253 val = t.gameObject.AddComponent<T>();
1258 public static RectTransform
Rect(
this Component c)
1260 return c.transform as RectTransform;
1263 public static void CopyRect(
this RectTransform r, RectTransform t)
1266 r.sizeDelta = t.sizeDelta;
1267 r.anchorMin = t.anchorMin;
1268 r.anchorMax = t.anchorMax;
1269 r.anchoredPosition = t.anchoredPosition;
1274 c.SetActive(!c.gameObject.activeSelf);
1279 if (c.gameObject.activeSelf != enable)
1281 c.gameObject.SetActive(enable);
1285 public static void SetActive(
this Component c,
bool enable, Action<bool> onChangeState)
1287 if (c.gameObject.activeSelf != enable)
1289 c.gameObject.SetActive(enable);
1290 onChangeState(enable);
1296 return go.GetComponentInChildren<Selectable>();
1302 foreach (Transform
item in obj.transform)
1304 item.gameObject.SetLayerRecursively(layer);
1310 Selectable selectable = (obj ? obj.GetComponent<Selectable>() :
null);
1311 if ((
bool)selectable)
1313 return selectable.interactable;
1318 public static bool IsChildOf(
this GameObject c, GameObject root)
1320 if (c.transform == root.transform)
1324 if ((
bool)c.transform.parent)
1326 return c.transform.parent.gameObject.IsChildOf(root);
1333 return c.gameObject.scene.name ==
null;
1336 public static T
CreateMold<T>(
this Component c,
string name =
null) where T : Component
1339 for (
int i = 0; i < c.transform.childCount; i++)
1341 T component = c.transform.GetChild(i).GetComponent<T>();
1342 if ((
bool)component && (name.IsEmpty() || name == component.name))
1344 component.gameObject.SetActive(value:
false);
1349 c.DestroyChildren();
1353 public static Transform
Find(
this Component c,
string name =
null)
1355 return c.Find<Transform>(name);
1358 public static T
Find<T>(
this Component c,
string name =
null,
bool recursive =
false) where T : Component
1362 T[] componentsInChildren = c.transform.GetComponentsInChildren<T>();
1363 foreach (T val
in componentsInChildren)
1365 if (name ==
null || name == val.name)
1372 for (
int j = 0; j < c.transform.childCount; j++)
1374 T component = c.transform.GetChild(j).GetComponent<T>();
1375 if ((
bool)component && (name ==
null || name == component.name))
1383 public static GameObject
FindTagInParents(
this Component c,
string tag,
bool includeInactive =
true)
1385 Transform transform = c.transform;
1386 for (
int i = 0; i < transform.childCount; i++)
1388 Transform child = transform.GetChild(i);
1389 if ((includeInactive || child.gameObject.activeSelf) && child.tag == tag)
1391 return child.gameObject;
1394 if ((
bool)transform.parent)
1396 return transform.parent.FindTagInParents(tag, includeInactive);
1403 for (
int i = 0; i < c.childCount; i++)
1405 T component = c.GetChild(i).GetComponent<T>();
1406 if ((
bool)component)
1416 List<T> list =
new List<T>();
1417 Transform transform = comp.transform;
1418 for (
int i = 0; i < transform.childCount; i++)
1420 T component = transform.GetChild(i).GetComponent<T>();
1421 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1423 list.Add(component);
1431 List<T> list =
new List<T>();
1432 Transform transform = comp.transform;
1433 for (
int i = 0; i < transform.childCount; i++)
1435 T component = transform.GetChild(i).GetComponent<T>();
1436 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1438 list.Add(component);
1446 Transform transform = comp.transform;
1447 for (
int i = 0; i < transform.childCount; i++)
1449 T component = transform.GetChild(i).GetComponent<T>();
1450 if ((
bool)component)
1458 public static void DestroyChildren(
this Component component,
bool destroyInactive =
false,
bool ignoreDestroy =
true)
1460 if (!component || !component.transform)
1462 Debug.LogWarning(
"DestroyChlidren:" + component);
1465 for (
int num = component.transform.childCount - 1; num >= 0; num--)
1467 GameObject gameObject = component.transform.GetChild(num).gameObject;
1468 if ((!ignoreDestroy || !(gameObject.tag ==
"IgnoreDestroy")) && (destroyInactive || gameObject.activeSelf))
1470 UnityEngine.Object.DestroyImmediate(gameObject);
1477 return RectTransformUtility.RectangleContainsScreenPoint(r, Input.mousePosition, cam);
1484 foreach (Transform
item in c.transform)
1486 if (
item is RectTransform)
1488 item.RebuildLayout(recursive:
true);
1492 LayoutRebuilder.ForceRebuildLayoutImmediate(c.transform as RectTransform);
1498 if ((
bool)c.transform.parent && !c.transform.parent.GetComponent<T>())
1500 c.transform.parent.RebuildLayoutTo<T>();
1507 if (!(c == target) && (
bool)c.transform.parent)
1509 c.transform.parent.RebuildLayoutTo(target);
1513 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)
1515 r.SetPivot(pivotX, pivotY);
1516 r.SetAnchor(minX, minY, maxX, maxY);
1519 r.sizeDelta =
new Vector2(w, h);
1521 r.anchoredPosition =
new Vector2((x == -1f) ? r.anchoredPosition.x : x, (y == -1f) ? r.anchoredPosition.y : y);
1524 public static void SetPivot(
this RectTransform r,
float x,
float y)
1526 r.pivot =
new Vector2(x, y);
1529 public static void SetAnchor(
this RectTransform r,
float minX,
float minY,
float maxX,
float maxY)
1531 r.anchorMin =
new Vector2(minX, minY);
1532 r.anchorMax =
new Vector2(maxX, maxY);
1540 _rect.SetAnchor(0.5f, 1f, 0.5f, 1f);
1543 _rect.SetAnchor(0.5f, 0f, 0.5f, 0f);
1546 _rect.SetAnchor(0f, 1f, 0f, 1f);
1549 _rect.SetAnchor(1f, 1f, 1f, 1f);
1552 _rect.SetAnchor(0f, 0f, 0f, 0f);
1555 _rect.SetAnchor(1f, 0f, 1f, 0f);
1558 _rect.SetAnchor(0f, 0.5f, 0f, 0.5f);
1561 _rect.SetAnchor(1f, 0.5f, 1f, 0.5f);
1564 _rect.SetAnchor(0.5f, 0.5f, 0.5f, 0.5f);
1571 Vector3 position = _rect.position;
1572 _rect._SetAnchor((anchor ==
RectPosition.Auto) ? _rect.GetAnchor() : anchor);
1573 _rect.position = position;
1578 Vector3 position = _rect.position;
1579 int width = Screen.width;
1580 int height = Screen.height;
1581 bool flag = position.y > (float)height * 0.5f;
1582 if (position.x > (
float)width * 0.3f && position.x < (float)width * 0.7f)
1584 if (position.y > (
float)height * 0.3f && position.y < (float)height * 0.7f)
1594 if (position.x < (
float)width * 0.5f)
1611 return trans.GetChild(trans.childCount - 1);
1616 return new Vector2(
self.x,
self.z);
1619 public static void SetScale(
this SpriteRenderer renderer,
float size)
1621 float x = renderer.bounds.size.x;
1622 float y = renderer.bounds.size.y;
1623 float x2 = size / x;
1624 float y2 = size / y;
1625 renderer.transform.localScale =
new Vector3(x2, y2, 1f);
1630 if (
object.Equals(
forward, Vector2.up))
1634 object.Equals(
forward, Vector2.right);
1640 self.LookAt2D(target.position,
forward);
1646 Vector3 vector = target -
self.position;
1647 float num = Mathf.Atan2(vector.y, vector.x) * 57.29578f;
1648 self.rotation = Quaternion.AngleAxis(num - forwardDiffPoint, Vector3.forward);
1651 public static float Distance(
this Transform t, Vector2 pos)
1653 return Vector3.Distance(t.position, pos);
1656 public static Vector3
Plus(
this Vector3 v, Vector2 v2)
1663 public static Vector3
SetZ(
this Vector3 v,
float a)
1669 public static Vector3
SetY(
this Vector3 v,
float a)
1675 public static Vector3
PlusX(
this Vector3 v,
float a)
1681 public static Vector3
PlusY(
this Vector3 v,
float a)
1687 public static Vector3
PlusZ(
this Vector3 v,
float a)
1693 public static void SetPosition(
this Transform transform,
float x,
float y,
float z)
1701 vector3.Set(x, transform.position.y, transform.position.z);
1707 vector3.Set(transform.position.x, y, transform.position.z);
1713 vector3.Set(transform.position.x, transform.position.y, z);
1717 public static void AddPosition(
this Transform transform,
float x,
float y,
float z)
1719 vector3.Set(transform.position.x + x, transform.position.y + y, transform.position.z + z);
1725 vector3.Set(transform.position.x + x, transform.position.y, transform.position.z);
1731 vector3.Set(transform.position.x, transform.position.y + y, transform.position.z);
1737 vector3.Set(transform.position.x, transform.position.y, transform.position.z + z);
1744 transform.localPosition =
vector3;
1749 vector3.Set(x, transform.localPosition.y, transform.localPosition.z);
1750 transform.localPosition =
vector3;
1755 vector3.Set(transform.localPosition.x, y, transform.localPosition.z);
1756 transform.localPosition =
vector3;
1761 vector3.Set(transform.localPosition.x, transform.localPosition.y, z);
1762 transform.localPosition =
vector3;
1767 vector3.Set(transform.localPosition.x + x, transform.localPosition.y + y, transform.localPosition.z + z);
1768 transform.localPosition =
vector3;
1773 vector3.Set(transform.localPosition.x + x, transform.localPosition.y, transform.localPosition.z);
1774 transform.localPosition =
vector3;
1779 vector3.Set(transform.localPosition.x, transform.localPosition.y + y, transform.localPosition.z);
1780 transform.localPosition =
vector3;
1785 vector3.Set(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + z);
1786 transform.localPosition =
vector3;
1789 public static void SetLocalScale(
this Transform transform,
float x,
float y,
float z)
1792 transform.localScale =
vector3;
1797 vector3.Set(x, transform.localScale.y, transform.localScale.z);
1798 transform.localScale =
vector3;
1803 vector3.Set(transform.localScale.x, y, transform.localScale.z);
1804 transform.localScale =
vector3;
1809 vector3.Set(transform.localScale.x, transform.localScale.y, z);
1810 transform.localScale =
vector3;
1813 public static void AddLocalScale(
this Transform transform,
float x,
float y,
float z)
1815 vector3.Set(transform.localScale.x + x, transform.localScale.y + y, transform.localScale.z + z);
1816 transform.localScale =
vector3;
1821 vector3.Set(transform.localScale.x + x, transform.localScale.y, transform.localScale.z);
1822 transform.localScale =
vector3;
1827 vector3.Set(transform.localScale.x, transform.localScale.y + y, transform.localScale.z);
1828 transform.localScale =
vector3;
1833 vector3.Set(transform.localScale.x, transform.localScale.y, transform.localScale.z + z);
1834 transform.localScale =
vector3;
1837 public static void SetEulerAngles(
this Transform transform,
float x,
float y,
float z)
1840 transform.eulerAngles =
vector3;
1845 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1846 transform.eulerAngles =
vector3;
1851 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1852 transform.eulerAngles =
vector3;
1857 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1858 transform.eulerAngles =
vector3;
1861 public static void AddEulerAngles(
this Transform transform,
float x,
float y,
float z)
1863 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y + y, transform.eulerAngles.z + z);
1864 transform.eulerAngles =
vector3;
1869 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y, transform.eulerAngles.z);
1870 transform.eulerAngles =
vector3;
1875 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y + y, transform.eulerAngles.z);
1876 transform.eulerAngles =
vector3;
1881 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z + z);
1882 transform.eulerAngles =
vector3;
1888 transform.localEulerAngles =
vector3;
1893 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1894 transform.localEulerAngles =
vector3;
1899 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1900 transform.localEulerAngles =
vector3;
1905 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1906 transform.localEulerAngles =
vector3;
1911 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y + y, transform.localEulerAngles.z + z);
1912 transform.localEulerAngles =
vector3;
1917 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1918 transform.localEulerAngles =
vector3;
1923 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y + y, transform.localEulerAngles.z);
1924 transform.localEulerAngles =
vector3;
1929 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z + z);
1930 transform.localEulerAngles =
vector3;
1937 m.EnableKeyword(
id);
1941 m.DisableKeyword(
id);
1947 for (
int num = items.Count - 1; num >= 0; num--)
1955 int num = items.Count - 1;
1956 while (num >= 0 && !action(items[num]))
1966 return 360f - (0f - angle) % 360f;
1968 return angle % 360f;
1978 string name = s.name;
1979 T val = UnityEngine.Object.Instantiate(s);
1986 Type typeFromHandle = typeof(UnityEventBase);
1987 Assembly assembly = Assembly.GetAssembly(typeFromHandle);
1988 Type type = assembly.GetType(
"UnityEngine.Events.InvokableCallList");
1989 Type type2 = assembly.GetType(
"UnityEngine.Events.BaseInvokableCall");
1990 Type type3 = typeof(List<>).MakeGenericType(type2);
1991 FieldInfo field = typeFromHandle.GetField(
"m_Calls", BindingFlags.Instance | BindingFlags.NonPublic);
1992 FieldInfo field2 = type.GetField(
"m_RuntimeCalls", BindingFlags.Instance | BindingFlags.NonPublic);
1993 object value = field.GetValue(unityEvent);
1994 object value2 = field2.GetValue(value);
1995 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 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 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 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 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)