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)
69 return list[0] + str + list[1];
72 return "_bracketLeft".lang() + str +
"_bracketRight".lang();
76 public static byte[]
ToBytes(
this BitArray bits)
78 byte[] array =
new byte[(bits.Length - 1) / 8 + 1];
79 bits.CopyTo(array, 0);
83 public static bool GetBit(
this byte pByte,
int bitNo)
85 return (pByte & (1 << bitNo)) != 0;
88 public static byte SetBit(
this byte pByte,
int bitNo,
bool value)
92 return Convert.ToByte(pByte & ~(1 << bitNo));
94 return Convert.ToByte(pByte | (1 << bitNo));
97 public static int ToInt3(
this float a)
99 return (
int)(a * 1000f);
104 return (
float)a / 1000f;
109 return (
int)(a * 100f);
114 return (
float)a / 100f;
135 public static bool IsOn(
this int data,
int digit)
139 return bitArray[digit];
144 return (T)Enum.ToObject(typeof(T), value);
149 return (T)Enum.ToObject(typeof(T), value);
152 public static T
ToEnum<T>(
this string value,
bool ignoreCase =
true)
154 return (T)Enum.Parse(typeof(T), value, ignoreCase);
157 public static Type
ToType(
this string value)
159 return Type.GetType(
"Elona." + value +
", Assembly-CSharp");
164 return ((T[])Enum.GetValues(src.GetType())).NextItem(src);
169 return ((T[])Enum.GetValues(src.GetType())).PrevItem(src);
172 public static bool Within(
this int v,
int v2,
int range)
176 return v - v2 < -range;
181 public static bool Within(
this byte v,
byte v2,
byte range)
185 return v - v2 < -range;
190 public static int Clamp(
this int v,
int min,
int max,
bool loop =
false)
194 v = ((!loop) ? min : max);
198 v = ((!loop) ? max : min);
223 return (T)o.GetType().GetField(s).GetValue(o);
228 FieldInfo field = o.GetType().GetField(name);
231 return typeof(T).IsAssignableFrom(field.FieldType);
238 return (T)o.GetType().GetField(name).GetValue(o);
241 public static void SetField<T>(
this object o,
string name, T value)
243 o.GetType().GetField(name).SetValue(o, value);
248 return (T)o.GetType().GetProperty(name).GetValue(o);
253 o.GetType().GetProperty(name).SetValue(o, value);
256 public static void Sort<T>(
this IList<T> list, Comparison<T> comparison)
260 ((List<T>)list).Sort(comparison);
263 List<T> list2 =
new List<T>(list);
264 list2.Sort(comparison);
265 for (
int i = 0; i < list.Count; i++)
271 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
int defIndex = -1)
273 if (array.Count != 0)
275 if (index >= array.Count)
279 if (array.Count <= defIndex)
281 return array[Mathf.Max(0, array.Count - 1)];
283 return array[defIndex];
285 return array[Mathf.Max(0, array.Count - 1)];
287 return array[Math.Max(0, index)];
289 return default(TValue);
292 public static TValue
TryGet<TValue>(
this IList<TValue> array,
int index,
bool returnNull)
294 if (index >= array.Count)
296 return default(TValue);
305 return array.Length == 0;
310 public static int IndexOf(
this IList<Component> list, GameObject go)
316 for (
int i = 0; i < list.Count; i++)
318 if (list[i].gameObject == go)
326 public static TValue
Move<TValue>(
this IList<TValue> list, TValue target,
int a)
328 int num = list.IndexOf(target);
332 num2 = list.Count - 1;
334 if (num2 >= list.Count)
339 list.Insert(num2, target);
345 return list.ToList();
348 public static void Each<TValue>(
this IList<TValue> list, Action<TValue> action)
350 for (
int num = list.Count - 1; num >= 0; num--)
358 int num = list.Count;
363 TValue value = list[num];
364 list[num] = list[index];
372 TValue value =
default(TValue);
373 if (key !=
null && source.TryGetValue(key, out value))
382 TValue value =
default(TValue);
383 if (key !=
null && source.TryGetValue(key, out value))
387 return source[key_fallback];
392 TValue val = dict.TryGetValue(key);
395 val = ((func !=
null) ? func() : Activator.CreateInstance<TValue>());
403 TKey[] array =
new TKey[dict.Keys.Count];
404 dict.Keys.CopyTo(array, 0);
410 TValue[] array =
new TValue[dict.Keys.Count];
411 dict.Values.CopyTo(array, 0);
417 int num = ie.Count();
422 return ie.ElementAt(
Rand.
rnd(num));
427 if (source.Count != 0)
429 return source.ElementAt(
Rand.
rnd(source.Count)).Value;
431 return default(TValue);
436 if (source.Count != 0)
438 return source[
Rand.
rnd(source.Count)];
440 return default(TValue);
445 return source.RandomItem(source.IndexOf(exclude));
450 if (source.Count > 1)
457 while (num == exclude);
460 if (source.Count == 1)
464 return default(TValue);
467 public static TValue
RandomItem<TValue>(
this IList<TValue> source, Func<TValue, bool> funcValid, TValue defaultValue =
default(TValue))
469 for (
int i = 0; i < 100; i++)
471 TValue val = source[
Rand.
rnd(source.Count)];
482 if (source.Count == 0)
484 return default(TValue);
486 if (source.Count == 1)
491 foreach (TValue
item in source)
493 num += getWeight(
item);
497 foreach (TValue item2
in source)
499 num += getWeight(item2);
505 return source.First();
510 if (source.Count != 0)
512 return source[divider % source.Count];
514 return default(TValue);
521 return default(TValue);
523 return source[source.First().Key];
528 if (source.Count != 0)
530 return source[source.Count - 1];
532 return default(TValue);
538 if (index >= source.Count)
542 if (source.Count != 0)
544 return source[index];
546 return default(TValue);
555 int num = source.IndexOf(val) + 1;
556 if (num >= source.Count)
565 int num = source.IndexOf(val) + 1;
566 if (num >= source.Count)
570 if (source.Count != 0)
574 return default(TValue);
579 int num = source.IndexOf(val) - 1;
582 num = source.Count - 1;
584 if (source.Count != 0)
588 return default(TValue);
597 else if (i >= source.Count)
599 i = source.Count - 1;
606 List<T> list =
new List<T>();
607 foreach (
object value
in source.Values)
619 dic =
new Dictionary<string, T>();
620 for (
int i = 0; i < list.Count; i++)
622 dic.Add(list[i].name, list[i].value);
626 public static T
FindMax<T>(
this List<T> list, Func<T, int> func)
628 int num =
int.MinValue;
629 T result =
default(T);
630 foreach (T
item in list)
632 int num2 = func(
item);
642 public static void Set<T1, T2>(
this Dictionary<T1, T2> dic, Dictionary<T1, T2> from)
645 foreach (KeyValuePair<T1, T2>
item in from)
653 if (
string.IsNullOrEmpty(text))
655 return new string[0];
657 return text.Split(
new string[3] {
"\r\n",
"\n",
"\r" }, StringSplitOptions.None);
662 if (
string.IsNullOrEmpty(text))
666 return text.Replace(
"\r",
"").Replace(
"\n",
"");
671 if (
string.IsNullOrEmpty(text))
675 return Regex.Replace(text,
"<.*?>",
"");
678 public static int Calc(
this string str,
int power = 0,
int ele = 0,
int p2 = 0)
680 return Cal.Calcuate(str.Replace(
"p2", p2.ToString() ??
"").Replace(
"p", power.ToString() ??
"").Replace(
"e", ele.ToString() ??
"")
686 return str.ToInt(typeof(T));
689 public static int ToInt(
this string str, Type type)
691 FieldInfo field = type.GetField(str, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
694 Debug.LogError(
"Field is null:" + str +
"/" + type);
697 return (
int)field.GetValue(
null);
700 public static int ToInt(
this string str)
702 if (
int.TryParse(str, out var result))
709 public static long ToLong(
this string str)
711 if (
long.TryParse(str, out var result))
723 if (!
float.TryParse(str, out result))
725 Debug.Log(
"exception: ToFlat1" + str);
731 Debug.Log(
"exception: ToFlat2" + str);
746 public static string StripPun(
this string str,
bool stripComma,
bool insertSpaceForComma =
false)
748 StringBuilder stringBuilder =
new StringBuilder();
749 foreach (
char c
in str)
755 if (insertSpaceForComma)
757 stringBuilder.Append(
'\u3000');
762 stringBuilder.Append(c);
767 stringBuilder.Append(c);
770 return stringBuilder.ToString();
773 public static string Repeat(
this string str,
int count)
775 StringBuilder stringBuilder =
new StringBuilder();
776 for (
int i = 0; i < Mathf.Abs(count); i++)
778 stringBuilder.Append(str);
780 return stringBuilder.ToString();
785 HashSet<char> brackets =
new HashSet<char> {
'"',
'「',
'」',
'“',
'”' };
786 return string.Concat(str.Where((
char c) => !brackets.Contains(c)));
791 if (!s.Contains(
"." + ext))
793 return s +
"." + ext;
807 public static string IsEmpty(
this string str,
string defaultStr)
809 if (str !=
null && !(str ==
""))
818 while (text.EndsWith(Environment.NewLine))
820 text = text.Substring(0, text.Length - Environment.NewLine.Length);
827 string[] array = str.Split(separator);
828 int[] array2 =
new int[array.Length];
829 for (
int i = 0; i < array.Length; i++)
831 array2[i] =
int.Parse(array[i]);
838 return str.Split(Environment.NewLine.ToCharArray());
841 public static bool Contains(
this string[] strs,
string id)
843 if (strs ==
null || strs.Length == 0)
847 for (
int i = 0; i < strs.Length; i++)
857 public static string Evalute(
this string[] array,
float val)
859 return array[(int)Mathf.Clamp((
float)(array.Length - 1) * val, 0f, array.Length - 1)];
871 return a / 1000 +
"K";
881 text = a / 1000000 +
"M";
890 return a / 1000 +
"K";
892 text2 = a.ToString();
900 text2 = a / 1000000 +
"M";
915 public static string ToText(
this int a,
bool skipIfZero =
true)
918 if (!(a == 0 && skipIfZero))
939 return s +
"<color=" + c.ToHex() +
">" + txt +
"</color>";
944 return "<color=" + c.ToHex() +
">" + s +
"</color>";
947 public static string TagSize(
this string s,
string txt,
int size)
949 return s +
"<size=" + size +
">" + txt +
"</size>";
952 public static string TagSize(
this string s,
int size)
954 return "<size=" + size +
">" + s +
"</size>";
957 public static bool HasTag(
this string s,
string id,
char splitter =
'/')
959 return s.Split(splitter).Contains(
id);
962 public static string SetTag(
this string s,
string id,
bool enable,
char splitter =
'/')
964 s = ((!enable) ? s.RemoveTag(
id, splitter) : s.AddTag(
id, splitter));
968 public static string AddTag(
this string s,
string id,
char splitter =
'/')
970 if (!s.HasTag(
id, splitter))
972 s = s + (s.IsEmpty() ?
"" : ((object)splitter))?.ToString() + id;
977 public static string RemoveTag(
this string s,
string id,
char splitter =
'/')
979 string[] array = s.Split(splitter);
981 string[] array2 = array;
982 foreach (
string text
in array2)
986 s.AddTag(text, splitter);
994 return fileInfo.Directory.FullName +
"/" + Path.GetFileNameWithoutExtension(fileInfo.Name);
999 return new FileInfo(path).GetFullFileNameWithoutExtension();
1004 if (s ==
"talisman")
1013 if (a.ToLower() ==
"unicorn")
1026 char c = s.ToLower()[0];
1027 s = (
GetSpecialArticle(s) ?? ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a ")) + s;
1038 string text = ((num >= 2) ? (num.ToFormat() +
" ") : (
GetSpecialArticle(s) ?? ((c ==
'a' || c ==
'i' || c ==
'u' || c ==
'e' || c ==
'o') ?
"an " :
"a ")));
1041 s = ((replace.IsEmpty() || !s.Contains(replace) || s.Contains(
"limestone stone")) ?
Pluralize(s) : s.Replace(replace,
Pluralize(replace)));
1045 ArticleStyle.The =>
"_the".lang().ToTitleCase() +
" " + ((num > 1) ? (num +
" ") :
"") + s,
1046 ArticleStyle.None => ((num > 1) ? (num.ToFormat() +
" ") :
"") + s.ToTitleCase(),
1051 public static string ToTitleCase(
this string s,
bool wholeText =
false)
1057 char[] array = s.ToCharArray();
1059 for (
int i = 0; i < array.Length; i++)
1063 array[i] =
char.ToUpper(array[i]);
1070 if (array[i] ==
' ')
1075 return new string(array);
1078 public static void LoopTail<T>(
this List<T> list,
bool vertical =
false) where T : Selectable
1082 Navigation navigation = list[0].navigation;
1083 Navigation navigation2 = list[list.Count - 1].navigation;
1086 navigation.selectOnUp = list[list.Count - 1];
1087 navigation2.selectOnDown = list[0];
1091 navigation.selectOnLeft = list[list.Count - 1];
1092 navigation2.selectOnRight = list[0];
1094 list[0].navigation = navigation;
1095 list[list.Count - 1].navigation = navigation2;
1099 public static void SetNavigation(
this Component a, Component b,
bool vertical =
false)
1105 Selectable component = a.GetComponent<Selectable>();
1106 Selectable component2 = b.GetComponent<Selectable>();
1107 if ((
bool)component && (bool)component2)
1109 Navigation navigation = component.navigation;
1110 Navigation navigation2 = component2.navigation;
1113 navigation.selectOnUp = component2;
1114 navigation2.selectOnDown = component;
1118 navigation.selectOnLeft = component2;
1119 navigation2.selectOnRight = component;
1121 component.navigation = navigation;
1122 component2.navigation = navigation2;
1126 public static void LoopSelectable(
this List<Selectable> sels,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1128 for (
int i = 0; i < sels.Count; i++)
1130 Selectable selectable = sels[i];
1131 Selectable selectable2 = sels[0];
1132 Navigation navigation = selectable.navigation;
1135 navigation.selectOnRight = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1139 for (
int j = i + 1; j < sels.Count; j++)
1141 if (sels[j].transform.position.y < selectable.transform.position.y)
1143 selectable2 = sels[j];
1150 selectable2 = ((i + 1 < sels.Count) ? sels[i + 1] : selectable2);
1154 navigation.selectOnDown = selectable2;
1156 selectable.navigation = navigation;
1158 for (
int num = sels.Count - 1; num >= 0; num--)
1160 Selectable selectable3 = sels[num];
1161 Selectable selectable4 = sels[sels.Count - 1];
1162 Navigation navigation2 = selectable3.navigation;
1165 navigation2.selectOnLeft = ((num > 0) ? sels[num - 1] : selectable4);
1169 int num2 = sels.Count - 1;
1170 for (
int num3 = num - 1; num3 >= 0; num3--)
1172 if (sels[num3].transform.position.y > selectable3.transform.position.y)
1179 while (num4 >= 0 && !(sels[num4].transform.position.y > sels[num2].transform.position.y))
1181 selectable4 = sels[num4];
1187 selectable4 = ((num > 0) ? sels[num - 1] : selectable4);
1191 navigation2.selectOnUp = ((selectable4 == selectable3) ? sels[sels.Count - 1] : selectable4);
1193 navigation2.mode = Navigation.Mode.Explicit;
1194 selectable3.navigation = navigation2;
1198 public static void LoopSelectable(
this Transform l,
bool vertical =
true,
bool horizonal =
true,
bool asGroup =
true)
1200 List<Selectable> list = l.GetComponentsInChildren<Selectable>().ToList();
1201 for (
int num = list.Count - 1; num >= 0; num--)
1203 if (!list[num].interactable || list[num].navigation.mode == Navigation.Mode.None)
1208 list.LoopSelectable(vertical, horizonal, asGroup);
1214 ColorUtility.TryParseHtmlString(
"#" + s, out color);
1220 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1225 c.color =
new Color(c.color.r, c.color.g, c.color.b, a);
1236 return new Color(c.r * mtp + add, c.g * mtp + add, c.b * mtp + add, c.a);
1241 return "<color=" +
$"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}" +
">";
1246 return $"#{(int)(c.r * 255f):X2}{(int)(c.g * 255f):X2}{(int)(c.b * 255f):X2}";
1251 b.onClick.RemoveAllListeners();
1252 b.onClick.AddListener(delegate
1260 e.RemoveAllListeners();
1261 e.AddListener(delegate
1267 public static void SetAlpha(
this Text text,
float aloha = 1f)
1269 text.color =
new Color(text.color.r, text.color.g, text.color.b, aloha);
1272 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
bool notify)
1274 slider.SetSlider(value, action, -1, -1, notify);
1277 public static void SetSlider(
this Slider slider,
float value, Func<float, string> action,
int min = -1,
int max = -1,
bool notify =
true)
1279 slider.onValueChanged.RemoveAllListeners();
1280 slider.onValueChanged.AddListener(delegate(
float a)
1282 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(a);
1286 slider.minValue = min;
1287 slider.maxValue = max;
1291 slider.value = value;
1295 slider.SetValueWithoutNotify(value);
1297 slider.GetComponentInChildren<Text>(includeInactive:
true).text = action(value);
1302 T val = t.gameObject.GetComponent<T>();
1305 val = t.gameObject.AddComponent<T>();
1310 public static RectTransform
Rect(
this Component c)
1312 return c.transform as RectTransform;
1315 public static void CopyRect(
this RectTransform r, RectTransform t)
1318 r.sizeDelta = t.sizeDelta;
1319 r.anchorMin = t.anchorMin;
1320 r.anchorMax = t.anchorMax;
1321 r.anchoredPosition = t.anchoredPosition;
1326 c.SetActive(!c.gameObject.activeSelf);
1331 if (c.gameObject.activeSelf != enable)
1333 c.gameObject.SetActive(enable);
1337 public static void SetActive(
this Component c,
bool enable, Action<bool> onChangeState)
1339 if (c.gameObject.activeSelf != enable)
1341 c.gameObject.SetActive(enable);
1342 onChangeState(enable);
1348 return go.GetComponentInChildren<Selectable>();
1354 foreach (Transform
item in obj.transform)
1356 item.gameObject.SetLayerRecursively(layer);
1362 Selectable selectable = (obj ? obj.GetComponent<Selectable>() :
null);
1363 if ((
bool)selectable)
1365 return selectable.interactable;
1370 public static bool IsChildOf(
this GameObject c, GameObject root)
1372 if (c.transform == root.transform)
1376 if ((
bool)c.transform.parent)
1378 return c.transform.parent.gameObject.IsChildOf(root);
1385 return c.gameObject.scene.name ==
null;
1388 public static T
CreateMold<T>(
this Component c,
string name =
null) where T : Component
1391 for (
int i = 0; i < c.transform.childCount; i++)
1393 T component = c.transform.GetChild(i).GetComponent<T>();
1394 if ((
bool)component && (name.IsEmpty() || name == component.name))
1396 component.gameObject.SetActive(value:
false);
1401 c.DestroyChildren();
1405 public static Transform
Find(
this Component c,
string name =
null)
1407 return c.Find<Transform>(name);
1410 public static T
Find<T>(
this Component c,
string name =
null,
bool recursive =
false) where T : Component
1414 T[] componentsInChildren = c.transform.GetComponentsInChildren<T>();
1415 foreach (T val
in componentsInChildren)
1417 if (name ==
null || name == val.name)
1424 for (
int j = 0; j < c.transform.childCount; j++)
1426 T component = c.transform.GetChild(j).GetComponent<T>();
1427 if ((
bool)component && (name ==
null || name == component.name))
1435 public static GameObject
FindTagInParents(
this Component c,
string tag,
bool includeInactive =
true)
1437 Transform transform = c.transform;
1438 for (
int i = 0; i < transform.childCount; i++)
1440 Transform child = transform.GetChild(i);
1441 if ((includeInactive || child.gameObject.activeSelf) && child.tag == tag)
1443 return child.gameObject;
1446 if ((
bool)transform.parent)
1448 return transform.parent.FindTagInParents(tag, includeInactive);
1455 for (
int i = 0; i < c.childCount; i++)
1457 T component = c.GetChild(i).GetComponent<T>();
1458 if ((
bool)component)
1468 List<T> list =
new List<T>();
1469 Transform transform = comp.transform;
1470 for (
int i = 0; i < transform.childCount; i++)
1472 T component = transform.GetChild(i).GetComponent<T>();
1473 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1475 list.Add(component);
1483 List<T> list =
new List<T>();
1484 Transform transform = comp.transform;
1485 for (
int i = 0; i < transform.childCount; i++)
1487 T component = transform.GetChild(i).GetComponent<T>();
1488 if ((
bool)component && (includeInactive || component.gameObject.activeInHierarchy))
1490 list.Add(component);
1498 Transform transform = comp.transform;
1499 for (
int i = 0; i < transform.childCount; i++)
1501 T component = transform.GetChild(i).GetComponent<T>();
1502 if ((
bool)component)
1510 public static void DestroyChildren(
this Component component,
bool destroyInactive =
false,
bool ignoreDestroy =
true)
1512 if (!component || !component.transform)
1514 Debug.LogWarning(
"DestroyChlidren:" + component);
1517 for (
int num = component.transform.childCount - 1; num >= 0; num--)
1519 GameObject gameObject = component.transform.GetChild(num).gameObject;
1520 if ((!ignoreDestroy || !(gameObject.tag ==
"IgnoreDestroy")) && (destroyInactive || gameObject.activeSelf))
1522 UnityEngine.Object.DestroyImmediate(gameObject);
1529 return RectTransformUtility.RectangleContainsScreenPoint(r, Input.mousePosition, cam);
1536 foreach (Transform
item in c.transform)
1538 if (
item is RectTransform)
1540 item.RebuildLayout(recursive:
true);
1544 LayoutRebuilder.ForceRebuildLayoutImmediate(c.transform as RectTransform);
1550 if ((
bool)c.transform.parent && !c.transform.parent.GetComponent<T>())
1552 c.transform.parent.RebuildLayoutTo<T>();
1559 if (!(c == target) && (
bool)c.transform.parent)
1561 c.transform.parent.RebuildLayoutTo(target);
1565 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)
1567 r.SetPivot(pivotX, pivotY);
1568 r.SetAnchor(minX, minY, maxX, maxY);
1571 r.sizeDelta =
new Vector2(w, h);
1573 r.anchoredPosition =
new Vector2((x == -1f) ? r.anchoredPosition.x : x, (y == -1f) ? r.anchoredPosition.y : y);
1576 public static void SetPivot(
this RectTransform r,
float x,
float y)
1578 r.pivot =
new Vector2(x, y);
1581 public static void SetAnchor(
this RectTransform r,
float minX,
float minY,
float maxX,
float maxY)
1583 r.anchorMin =
new Vector2(minX, minY);
1584 r.anchorMax =
new Vector2(maxX, maxY);
1592 _rect.SetAnchor(0.5f, 1f, 0.5f, 1f);
1595 _rect.SetAnchor(0.5f, 0f, 0.5f, 0f);
1598 _rect.SetAnchor(0f, 1f, 0f, 1f);
1601 _rect.SetAnchor(1f, 1f, 1f, 1f);
1604 _rect.SetAnchor(0f, 0f, 0f, 0f);
1607 _rect.SetAnchor(1f, 0f, 1f, 0f);
1610 _rect.SetAnchor(0f, 0.5f, 0f, 0.5f);
1613 _rect.SetAnchor(1f, 0.5f, 1f, 0.5f);
1616 _rect.SetAnchor(0.5f, 0.5f, 0.5f, 0.5f);
1623 Vector3 position = _rect.position;
1624 _rect._SetAnchor((anchor ==
RectPosition.Auto) ? _rect.GetAnchor() : anchor);
1625 _rect.position = position;
1630 Vector3 position = _rect.position;
1631 int width = Screen.width;
1632 int height = Screen.height;
1633 bool flag = position.y > (float)height * 0.5f;
1634 if (position.x > (
float)width * 0.3f && position.x < (float)width * 0.7f)
1636 if (position.y > (
float)height * 0.3f && position.y < (float)height * 0.7f)
1646 if (position.x < (
float)width * 0.5f)
1663 return trans.GetChild(trans.childCount - 1);
1668 return new Vector2(
self.x,
self.z);
1671 public static void SetScale(
this SpriteRenderer renderer,
float size)
1673 float x = renderer.bounds.size.x;
1674 float y = renderer.bounds.size.y;
1675 float x2 = size / x;
1676 float y2 = size / y;
1677 renderer.transform.localScale =
new Vector3(x2, y2, 1f);
1682 if (
object.Equals(
forward, Vector2.up))
1686 object.Equals(
forward, Vector2.right);
1692 self.LookAt2D(target.position,
forward);
1698 Vector3 vector = target -
self.position;
1699 float num = Mathf.Atan2(vector.y, vector.x) * 57.29578f;
1700 self.rotation = Quaternion.AngleAxis(num - forwardDiffPoint, Vector3.forward);
1703 public static float Distance(
this Transform t, Vector2 pos)
1705 return Vector3.Distance(t.position, pos);
1708 public static Vector3
Plus(
this Vector3 v, Vector2 v2)
1715 public static Vector3
SetZ(
this Vector3 v,
float a)
1721 public static Vector3
SetY(
this Vector3 v,
float a)
1727 public static Vector3
PlusX(
this Vector3 v,
float a)
1733 public static Vector3
PlusY(
this Vector3 v,
float a)
1739 public static Vector3
PlusZ(
this Vector3 v,
float a)
1745 public static void SetPosition(
this Transform transform,
float x,
float y,
float z)
1753 vector3.Set(x, transform.position.y, transform.position.z);
1759 vector3.Set(transform.position.x, y, transform.position.z);
1765 vector3.Set(transform.position.x, transform.position.y, z);
1769 public static void AddPosition(
this Transform transform,
float x,
float y,
float z)
1771 vector3.Set(transform.position.x + x, transform.position.y + y, transform.position.z + z);
1777 vector3.Set(transform.position.x + x, transform.position.y, transform.position.z);
1783 vector3.Set(transform.position.x, transform.position.y + y, transform.position.z);
1789 vector3.Set(transform.position.x, transform.position.y, transform.position.z + z);
1796 transform.localPosition =
vector3;
1801 vector3.Set(x, transform.localPosition.y, transform.localPosition.z);
1802 transform.localPosition =
vector3;
1807 vector3.Set(transform.localPosition.x, y, transform.localPosition.z);
1808 transform.localPosition =
vector3;
1813 vector3.Set(transform.localPosition.x, transform.localPosition.y, z);
1814 transform.localPosition =
vector3;
1819 vector3.Set(transform.localPosition.x + x, transform.localPosition.y + y, transform.localPosition.z + z);
1820 transform.localPosition =
vector3;
1825 vector3.Set(transform.localPosition.x + x, transform.localPosition.y, transform.localPosition.z);
1826 transform.localPosition =
vector3;
1831 vector3.Set(transform.localPosition.x, transform.localPosition.y + y, transform.localPosition.z);
1832 transform.localPosition =
vector3;
1837 vector3.Set(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z + z);
1838 transform.localPosition =
vector3;
1841 public static void SetLocalScale(
this Transform transform,
float x,
float y,
float z)
1844 transform.localScale =
vector3;
1849 vector3.Set(x, transform.localScale.y, transform.localScale.z);
1850 transform.localScale =
vector3;
1855 vector3.Set(transform.localScale.x, y, transform.localScale.z);
1856 transform.localScale =
vector3;
1861 vector3.Set(transform.localScale.x, transform.localScale.y, z);
1862 transform.localScale =
vector3;
1865 public static void AddLocalScale(
this Transform transform,
float x,
float y,
float z)
1867 vector3.Set(transform.localScale.x + x, transform.localScale.y + y, transform.localScale.z + z);
1868 transform.localScale =
vector3;
1873 vector3.Set(transform.localScale.x + x, transform.localScale.y, transform.localScale.z);
1874 transform.localScale =
vector3;
1879 vector3.Set(transform.localScale.x, transform.localScale.y + y, transform.localScale.z);
1880 transform.localScale =
vector3;
1885 vector3.Set(transform.localScale.x, transform.localScale.y, transform.localScale.z + z);
1886 transform.localScale =
vector3;
1889 public static void SetEulerAngles(
this Transform transform,
float x,
float y,
float z)
1892 transform.eulerAngles =
vector3;
1897 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1898 transform.eulerAngles =
vector3;
1903 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1904 transform.eulerAngles =
vector3;
1909 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1910 transform.eulerAngles =
vector3;
1913 public static void AddEulerAngles(
this Transform transform,
float x,
float y,
float z)
1915 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y + y, transform.eulerAngles.z + z);
1916 transform.eulerAngles =
vector3;
1921 vector3.Set(transform.eulerAngles.x + x, transform.eulerAngles.y, transform.eulerAngles.z);
1922 transform.eulerAngles =
vector3;
1927 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y + y, transform.eulerAngles.z);
1928 transform.eulerAngles =
vector3;
1933 vector3.Set(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z + z);
1934 transform.eulerAngles =
vector3;
1940 transform.localEulerAngles =
vector3;
1945 vector3.Set(x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1946 transform.localEulerAngles =
vector3;
1951 vector3.Set(transform.localEulerAngles.x, y, transform.localEulerAngles.z);
1952 transform.localEulerAngles =
vector3;
1957 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, z);
1958 transform.localEulerAngles =
vector3;
1963 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y + y, transform.localEulerAngles.z + z);
1964 transform.localEulerAngles =
vector3;
1969 vector3.Set(transform.localEulerAngles.x + x, transform.localEulerAngles.y, transform.localEulerAngles.z);
1970 transform.localEulerAngles =
vector3;
1975 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y + y, transform.localEulerAngles.z);
1976 transform.localEulerAngles =
vector3;
1981 vector3.Set(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z + z);
1982 transform.localEulerAngles =
vector3;
1989 m.EnableKeyword(
id);
1993 m.DisableKeyword(
id);
1999 for (
int num = items.Count - 1; num >= 0; num--)
2007 int num = items.Count - 1;
2008 while (num >= 0 && !action(items[num]))
2018 return 360f - (0f - angle) % 360f;
2020 return angle % 360f;
2030 string name = s.name;
2031 T val = UnityEngine.Object.Instantiate(s);
2038 Type typeFromHandle = typeof(UnityEventBase);
2039 Assembly assembly = Assembly.GetAssembly(typeFromHandle);
2040 Type type = assembly.GetType(
"UnityEngine.Events.InvokableCallList");
2041 Type type2 = assembly.GetType(
"UnityEngine.Events.BaseInvokableCall");
2042 Type type3 = typeof(List<>).MakeGenericType(type2);
2043 FieldInfo field = typeFromHandle.GetField(
"m_Calls", BindingFlags.Instance | BindingFlags.NonPublic);
2044 FieldInfo field2 = type.GetField(
"m_RuntimeCalls", BindingFlags.Instance | BindingFlags.NonPublic);
2045 object value = field.GetValue(unityEvent);
2046 object value2 = field2.GetValue(value);
2047 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 string GetSpecialArticle(string a)
static void LookAt2D(this Transform self, Transform target, Vector2 forward)
static void SetLocalScaleZ(this Transform transform, float z)
static void SetEulerAngles(this Transform transform, float x, float y, float z)
static float ClampAngle(this float angle)
static int Clamp(this int v, int min, int max, bool loop=false)
static string TrimNewLines(this string text)
static string TagColor(this string s, Color c)
static string[] SplitNewline(this string str)
static void CopyRect(this RectTransform r, RectTransform t)
static Color Multiply(this Color c, float mtp, float add)
static TValue[] CopyValues< TKey, TValue >(this IDictionary< TKey, TValue > dict)
static void SetLocalPositionY(this Transform transform, float y)
static Vector3 PlusZ(this Vector3 v, float a)
static void SetPositionZ(this Transform transform, float z)
static Color SetAlpha(this Color c, float a)
static void SetLocalScaleY(this Transform transform, float y)
static TValue LastItem< TValue >(this IList< TValue > source)
static byte[] ToBytes(this BitArray bits)
static T ToField< T >(this string s, object o)
static void SetLocalScale(this Transform transform, float x, float y, float z)
static string AddArticle(this string s)
static TValue Remainder< TValue >(this IList< TValue > source, int divider)
static int ToInt2(this float a)
static List< T > GetList< T >(this IDictionary source)
static void AddLocalPositionY(this Transform transform, float y)
static void AddPositionZ(this Transform transform, float z)
static bool HasField< T >(this object o, string name)
static void AddEulerAnglesY(this Transform transform, float y)
static void LookAt2D(this Transform self, Vector3 target, Vector2 forward)
static LangSetting setting
static string Get(string id)
static string[] GetList(string id)
static string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null, string val5=null)
static int Range(int min, int max)
string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null)