Files
2026-02-21 16:45:37 +08:00

121 lines
2.9 KiB
C#

using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace ProCore.Decals
{
public static class qdUtil
{
public static GameObject[] FindDecalsWithTexture(Texture2D img)
{
List<GameObject> list = new List<GameObject>();
Object[] array = Object.FindObjectsOfType(typeof(qd_Decal));
for (int i = 0; i < array.Length; i++)
{
qd_Decal qd_Decal2 = (qd_Decal)array[i];
if (qd_Decal2.texture == img)
{
list.Add(qd_Decal2.gameObject);
}
}
return list.ToArray();
}
public static void RefreshSceneDecals(DecalGroup dg)
{
if (!dg.isPacked)
{
Debug.LogWarning("Attempting to RefreshSceneDecals without a packed material");
return;
}
qd_Decal[] array = (qd_Decal[])Object.FindObjectsOfType(typeof(qd_Decal));
for (int i = 0; i < dg.decals.Count; i++)
{
qd_Decal[] array2 = array;
foreach (qd_Decal qd_Decal2 in array2)
{
if (dg.decals[i].texture == qd_Decal2.texture)
{
qd_Decal2.GetComponent<MeshRenderer>().sharedMaterial = dg.material;
qd_Decal2.SetUVRect(dg.decals[i].atlasRect);
}
}
}
}
public static void SortDecalsUsingView(ref List<Decal> decals, DecalView decalView)
{
List<Decal> list = new List<Decal>();
foreach (Decal decal in decals)
{
int num = ((decalView != DecalView.Organizational) ? decal.atlasIndex : decal.orgIndex);
int num2 = list.Count;
for (int num3 = list.Count - 1; num3 > -1; num3--)
{
if (num < ((decalView != DecalView.Atlas) ? list[num3].orgIndex : list[num3].atlasIndex) && num < num2)
{
num2 = num;
}
}
list.Insert(num2, decal);
}
decals = list;
}
public static bool Contains(this Dictionary<int, List<int>> dic, int key, int val)
{
return dic.ContainsKey(key) && dic[key].Contains(val);
}
public static void Add(this Dictionary<int, List<int>> dic, int key, int val)
{
if (key < 0 || val < 0)
{
return;
}
if (dic.ContainsKey(key))
{
if (!dic[key].Contains(val))
{
dic[key].Add(val);
}
}
else
{
dic.Add(key, new List<int> { val });
}
}
public static string ToFormattedString(this Dictionary<int, List<int>> dic)
{
string text = string.Empty;
foreach (KeyValuePair<int, List<int>> item in dic)
{
string text2 = text;
text = text2 + item.Key + " : " + item.Value.ToFormattedString(", ") + "\n";
}
return text;
}
public static string ToFormattedString<T>(this T[] t, string _delimiter)
{
if (t == null || t.Length < 1)
{
return "Empty Array.";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(t[0].ToString());
for (int i = 1; i < t.Length; i++)
{
stringBuilder.Append(_delimiter + ((t[i] != null) ? t[i].ToString() : "null"));
}
return stringBuilder.ToString();
}
public static string ToFormattedString<T>(this List<T> t, string _delimiter)
{
return t.ToArray().ToFormattedString(_delimiter);
}
}
}