Files
2026-06-04 11:42:34 +02:00

594 lines
15 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using UnityEngine;
namespace ProBuilder2.Common
{
// Token: 0x02000003 RID: 3
public static class pbUtil
{
// Token: 0x06000004 RID: 4 RVA: 0x000020FC File Offset: 0x000004FC
public static T[] GetComponents<T>(this GameObject[] _gameObjects) where T : Component
{
List<T> list = new List<T>();
for (int i = 0; i < _gameObjects.Length; i++)
{
list.AddRange(_gameObjects[i].transform.GetComponentsInChildren<T>());
}
return list.ToArray();
}
// Token: 0x06000005 RID: 5 RVA: 0x0000213C File Offset: 0x0000053C
public static T[] GetComponents<T>(GameObject go) where T : Component
{
return new Transform[] { go.transform }.GetComponents<T>();
}
// Token: 0x06000006 RID: 6 RVA: 0x00002154 File Offset: 0x00000554
public static T[] GetComponents<T>(this Transform[] _transforms) where T : Component
{
List<T> list = new List<T>();
foreach (Transform transform in _transforms)
{
list.AddRange(transform.GetComponentsInChildren<T>());
}
return list.ToArray();
}
// Token: 0x06000007 RID: 7 RVA: 0x00002194 File Offset: 0x00000594
public static Vector3[] ToWorldSpace(this Transform t, Vector3[] v)
{
Vector3[] array = new Vector3[v.Length];
for (int i = 0; i < array.Length; i++)
{
array[i] = t.TransformPoint(v[i]);
}
return array;
}
// Token: 0x06000008 RID: 8 RVA: 0x000021E0 File Offset: 0x000005E0
public static GameObject EmptyGameObjectWithTransform(Transform t)
{
return new GameObject
{
transform =
{
position = t.position,
localRotation = t.localRotation,
localScale = t.localScale
}
};
}
// Token: 0x06000009 RID: 9 RVA: 0x00002228 File Offset: 0x00000628
public static T[] ValuesWithIndices<T>(this T[] arr, int[] indices)
{
T[] array = new T[indices.Length];
for (int i = 0; i < indices.Length; i++)
{
array[i] = arr[indices[i]];
}
return array;
}
// Token: 0x0600000A RID: 10 RVA: 0x00002264 File Offset: 0x00000664
public static List<T> ValuesWithIndices<T>(this IList<T> arr, IList<int> indices)
{
List<T> list = new List<T>();
foreach (int num in indices)
{
list.Add(arr[num]);
}
return list;
}
// Token: 0x0600000B RID: 11 RVA: 0x000022C8 File Offset: 0x000006C8
public static int[] AllIndexesOf<T>(T[] arr, T instance)
{
List<int> list = new List<int>();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i].Equals(instance))
{
list.Add(i);
}
}
return list.ToArray();
}
// Token: 0x0600000C RID: 12 RVA: 0x0000231C File Offset: 0x0000071C
public static bool IsEqual<T>(T[] a, T[] b)
{
if (a == null && b == null)
{
return true;
}
if ((a == null && b != null) || (a != null && b == null))
{
return false;
}
if (a.Length != b.Length)
{
return false;
}
for (int i = 0; i < a.Length; i++)
{
if (!a[i].Equals(b[i]))
{
return false;
}
}
return true;
}
// Token: 0x0600000D RID: 13 RVA: 0x0000239C File Offset: 0x0000079C
public static T[] Add<T>(this T[] arr, T val)
{
T[] array = new T[arr.Length + 1];
Array.ConstrainedCopy(arr, 0, array, 0, arr.Length);
array[arr.Length] = val;
return array;
}
// Token: 0x0600000E RID: 14 RVA: 0x000023CC File Offset: 0x000007CC
public static T[] AddRange<T>(this T[] arr, T[] val)
{
T[] array = new T[arr.Length + val.Length];
Array.ConstrainedCopy(arr, 0, array, 0, arr.Length);
Array.ConstrainedCopy(val, 0, array, arr.Length, val.Length);
return array;
}
// Token: 0x0600000F RID: 15 RVA: 0x00002404 File Offset: 0x00000804
public static T[] Remove<T>(this T[] arr, T val)
{
List<T> list = new List<T>(arr);
list.Remove(val);
return list.ToArray();
}
// Token: 0x06000010 RID: 16 RVA: 0x00002426 File Offset: 0x00000826
public static T[] Remove<T>(this T[] arr, IEnumerable<T> val)
{
return arr.Except(val).ToArray<T>();
}
// Token: 0x06000011 RID: 17 RVA: 0x00002434 File Offset: 0x00000834
public static T[] RemoveAt<T>(this T[] arr, int index)
{
T[] array = new T[arr.Length - 1];
int num = 0;
for (int i = 0; i < arr.Length; i++)
{
if (i != index)
{
array[num] = arr[i];
num++;
}
}
return array;
}
// Token: 0x06000012 RID: 18 RVA: 0x0000247C File Offset: 0x0000087C
public static T[] RemoveAt<T>(this IList<T> list, IEnumerable<int> indices)
{
List<int> list2 = new List<int>(indices);
list2.Sort();
return list.SortedRemoveAt(list2);
}
// Token: 0x06000013 RID: 19 RVA: 0x000024A0 File Offset: 0x000008A0
public static T[] SortedRemoveAt<T>(this IList<T> list, IList<int> sorted_indices)
{
int count = sorted_indices.Count;
int count2 = list.Count;
T[] array = new T[count2 - count];
int num = 0;
for (int i = 0; i < count2; i++)
{
if (num < count && sorted_indices[num] == i)
{
while (num < count && sorted_indices[num] == i)
{
num++;
}
}
else
{
array[i - num] = list[i];
}
}
return array;
}
// Token: 0x06000014 RID: 20 RVA: 0x00002528 File Offset: 0x00000928
public static int NearestIndexPriorToValue<T>(IList<T> sorted_list, T value) where T : IComparable<T>
{
int count = sorted_list.Count;
if (count < 1)
{
return -1;
}
pbUtil.SearchRange searchRange = new pbUtil.SearchRange(0, count - 1);
if (value.CompareTo(sorted_list[0]) < 0)
{
return -1;
}
if (value.CompareTo(sorted_list[count - 1]) > 0)
{
return count - 1;
}
while (searchRange.Valid())
{
T t = sorted_list[searchRange.Center()];
if (t.CompareTo(value) > 0)
{
searchRange.end = searchRange.Center();
}
else
{
searchRange.begin = searchRange.Center();
T t2 = sorted_list[searchRange.begin + 1];
if (t2.CompareTo(value) >= 0)
{
return searchRange.begin;
}
}
}
return 0;
}
// Token: 0x06000015 RID: 21 RVA: 0x0000260D File Offset: 0x00000A0D
public static T[] Fill<T>(T val, int length)
{
return pbUtil.FilledArray<T>(val, length);
}
// Token: 0x06000016 RID: 22 RVA: 0x00002618 File Offset: 0x00000A18
public static List<T> Fill<T>(Func<int, T> ctor, int length)
{
List<T> list = new List<T>(length);
for (int i = 0; i < length; i++)
{
list.Add(ctor(i));
}
return list;
}
// Token: 0x06000017 RID: 23 RVA: 0x0000264C File Offset: 0x00000A4C
public static T[] FilledArray<T>(T val, int length)
{
T[] array = new T[length];
for (int i = 0; i < length; i++)
{
array[i] = val;
}
return array;
}
// Token: 0x06000018 RID: 24 RVA: 0x0000267C File Offset: 0x00000A7C
public static bool ContainsMatch<T>(this T[] a, T[] b)
{
for (int i = 0; i < a.Length; i++)
{
int num = Array.IndexOf<T>(b, a[i]);
if (num > -1)
{
return true;
}
}
return false;
}
// Token: 0x06000019 RID: 25 RVA: 0x000026B7 File Offset: 0x00000AB7
public static bool ContainsMatch<T>(this T[] a, T[] b, out int index_a, out int index_b)
{
index_b = -1;
for (index_a = 0; index_a < a.Length; index_a++)
{
index_b = Array.IndexOf<T>(b, a[index_a]);
if (index_b > -1)
{
return true;
}
}
return false;
}
// Token: 0x0600001A RID: 26 RVA: 0x000026F0 File Offset: 0x00000AF0
public static T[] Concat<T>(this T[] x, T[] y)
{
if (x == null)
{
throw new ArgumentNullException("x");
}
if (y == null)
{
throw new ArgumentNullException("y");
}
int num = x.Length;
Array.Resize<T>(ref x, x.Length + y.Length);
Array.Copy(y, 0, x, num, y.Length);
return x;
}
// Token: 0x0600001B RID: 27 RVA: 0x00002740 File Offset: 0x00000B40
public static int IndexOf<T>(this List<List<T>> InList, T InValue)
{
for (int i = 0; i < InList.Count; i++)
{
for (int j = 0; j < InList[i].Count; j++)
{
T t = InList[i][j];
if (t.Equals(InValue))
{
return i;
}
}
}
return -1;
}
// Token: 0x0600001C RID: 28 RVA: 0x000027AC File Offset: 0x00000BAC
public static T[] Fill<T>(int count, Func<int, T> ctor)
{
T[] array = new T[count];
for (int i = 0; i < count; i++)
{
array[i] = ctor(i);
}
return array;
}
// Token: 0x0600001D RID: 29 RVA: 0x000027E4 File Offset: 0x00000BE4
public static void AddOrAppend<T, K>(this Dictionary<T, List<K>> dictionary, T key, K value)
{
List<K> list;
if (dictionary.TryGetValue(key, out list))
{
list.Add(value);
}
else
{
dictionary.Add(key, new List<K> { value });
}
}
// Token: 0x0600001E RID: 30 RVA: 0x00002820 File Offset: 0x00000C20
public static void AddOrAppendRange<T, K>(this Dictionary<T, List<K>> dictionary, T key, List<K> value)
{
List<K> list;
if (dictionary.TryGetValue(key, out list))
{
list.AddRange(value);
}
else
{
dictionary.Add(key, value);
}
}
// Token: 0x0600001F RID: 31 RVA: 0x00002850 File Offset: 0x00000C50
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> knownKeys = new HashSet<TKey>();
return source.Where((TSource x) => knownKeys.Add(keySelector(x)));
}
// Token: 0x06000020 RID: 32 RVA: 0x00002887 File Offset: 0x00000C87
[Obsolete]
public static string ToFormattedString<T>(this T[] t, string _delimiter)
{
return t.ToFormattedString(_delimiter, 0, -1);
}
// Token: 0x06000021 RID: 33 RVA: 0x00002894 File Offset: 0x00000C94
[Obsolete]
public static string ToFormattedString<T>(this T[] t, string _delimiter, int entriesPerLine, int maxEntries)
{
int num = ((maxEntries <= 0) ? t.Length : Mathf.Min(t.Length, maxEntries));
if (t == null || num < 1)
{
return "Empty Array.";
}
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < num - 1; i++)
{
if (entriesPerLine > 0 && (i + 1) % entriesPerLine == 0)
{
stringBuilder.AppendLine(((t[i] != null) ? t[i].ToString() : "null") + _delimiter);
}
else
{
stringBuilder.Append(((t[i] != null) ? t[i].ToString() : "null") + _delimiter);
}
}
stringBuilder.Append((t[num - 1] != null) ? t[num - 1].ToString() : "null");
return stringBuilder.ToString();
}
// Token: 0x06000022 RID: 34 RVA: 0x000029B5 File Offset: 0x00000DB5
[Obsolete]
public static string ToFormattedString<T>(this List<T> t, string _delimiter)
{
return t.ToArray().ToFormattedString(_delimiter);
}
// Token: 0x06000023 RID: 35 RVA: 0x000029C3 File Offset: 0x00000DC3
[Obsolete]
public static string ToFormattedString<T>(this HashSet<T> t, string _delimiter)
{
return t.ToArray<T>().ToFormattedString(_delimiter);
}
// Token: 0x06000024 RID: 36 RVA: 0x000029D4 File Offset: 0x00000DD4
public static string ToString<TKey, TValue>(this Dictionary<TKey, TValue> dict)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (KeyValuePair<TKey, TValue> keyValuePair in dict)
{
stringBuilder.AppendLine(string.Format("Key: {0} Value: {1}", keyValuePair.Key, keyValuePair.Value));
}
return stringBuilder.ToString();
}
// Token: 0x06000025 RID: 37 RVA: 0x00002A5C File Offset: 0x00000E5C
public static string ToString<T>(this IEnumerable<T> arr, string separator = ", ")
{
return string.Join(separator, arr.Select((T x) => x.ToString()).ToArray<string>());
}
// Token: 0x06000026 RID: 38 RVA: 0x00002A7C File Offset: 0x00000E7C
public static string ControlKeyString(char character)
{
if (character == '⌘')
{
return "Control";
}
if (character == '⇧')
{
return "Shift";
}
if (character == '⌥')
{
return "Alt";
}
if (character == '⎇')
{
return "Alt";
}
if (character == '⌫')
{
return "Delete";
}
return character.ToString();
}
// Token: 0x06000027 RID: 39 RVA: 0x00002AEB File Offset: 0x00000EEB
[Obsolete("ColorWithString is deprecated. Use TryParseColor.")]
public static bool ColorWithString(string value, out Color col)
{
col = Color.white;
return pbUtil.TryParseColor(value, ref col);
}
// Token: 0x06000028 RID: 40 RVA: 0x00002B00 File Offset: 0x00000F00
public static bool TryParseColor(string value, ref Color col)
{
string valid = "01234567890.,";
value = new string(value.Where((char c) => valid.Contains(c)).ToArray<char>());
string[] array = value.Split(new char[] { ',' });
if (array.Length < 4)
{
return false;
}
try
{
float num = float.Parse(array[0]);
float num2 = float.Parse(array[1]);
float num3 = float.Parse(array[2]);
float num4 = float.Parse(array[3]);
col.r = num;
col.g = num2;
col.b = num3;
col.a = num4;
}
catch
{
return false;
}
return true;
}
// Token: 0x06000029 RID: 41 RVA: 0x00002BC0 File Offset: 0x00000FC0
public static Vector3[] StringToVector3Array(string str)
{
List<Vector3> list = new List<Vector3>();
str = str.Replace(" ", string.Empty);
string[] array = str.Split(new char[] { '\n' });
foreach (string text in array)
{
if (!text.Contains("//"))
{
string[] array3 = text.Split(new char[] { ',' });
if (array3.Length >= 3)
{
float num;
if (float.TryParse(array3[0], NumberStyles.Any, CultureInfo.InvariantCulture, out num))
{
float num2;
if (float.TryParse(array3[1], NumberStyles.Any, CultureInfo.InvariantCulture, out num2))
{
float num3;
if (float.TryParse(array3[2], NumberStyles.Any, CultureInfo.InvariantCulture, out num3))
{
list.Add(new Vector3(num, num2, num3));
}
}
}
}
}
}
return list.ToArray();
}
// Token: 0x0600002A RID: 42 RVA: 0x00002CC1 File Offset: 0x000010C1
public static Vector2 DivideBy(this Vector2 v, Vector2 o)
{
return new Vector2(v.x / o.x, v.y / o.y);
}
// Token: 0x0600002B RID: 43 RVA: 0x00002CE6 File Offset: 0x000010E6
public static Vector3 DivideBy(this Vector3 v, Vector3 o)
{
return new Vector3(v.x / o.x, v.y / o.y, v.z / o.z);
}
// Token: 0x02000004 RID: 4
private struct SearchRange
{
// Token: 0x0600002D RID: 45 RVA: 0x00002D29 File Offset: 0x00001129
public SearchRange(int begin, int end)
{
this.begin = begin;
this.end = end;
}
// Token: 0x0600002E RID: 46 RVA: 0x00002D39 File Offset: 0x00001139
public bool Valid()
{
return this.end - this.begin > 1;
}
// Token: 0x0600002F RID: 47 RVA: 0x00002D4B File Offset: 0x0000114B
public int Center()
{
return this.begin + (this.end - this.begin) / 2;
}
// Token: 0x06000030 RID: 48 RVA: 0x00002D64 File Offset: 0x00001164
public override string ToString()
{
return string.Concat(new object[]
{
"{",
this.begin,
", ",
this.end,
"} : ",
this.Center()
});
}
// Token: 0x04000002 RID: 2
public int begin;
// Token: 0x04000003 RID: 3
public int end;
}
}
}