This commit is contained in:
2025-02-19 17:24:26 +09:00
commit b6e88274e8
8796 changed files with 1728296 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
using System;
using UnityEngine;
namespace WI.Util
{
public static class ComponentExtension
{
public static Component GetOrAddComponent(this Transform mono, Type type)
{
if (mono.TryGetComponent(type, out var result))
{
return result;
}
return mono.gameObject.AddComponent(type);
}
public static T GetOrAddComponent<T>(this Transform mono) where T : Component
{
if (mono.TryGetComponent<T>(out T result))
{
return result;
}
return mono.gameObject.AddComponent<T>();
}
public static T GetOrAddComponent<T>(this GameObject mono) where T : Component
{
if (mono.TryGetComponent<T>(out T result))
{
return result;
}
return mono.gameObject.AddComponent<T>();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 92a39319d42d048478b80b7e5a58eb55

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace WI
{
[Serializable]
public partial class Container<T> where T : Component
{
public List<T> values = new List<T>();
public void Loading(IEnumerable<Component> loads)
{
foreach (var l in loads)
{
if (l is T t)
values.Add(t);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 31cfb27f414a08b42a89cb0ed7cb29be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 55b68a64773b3774f95802313db663c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using static UnityEngine.GraphicsBuffer;
using UnityEditor;
using System;
using System.Reflection;
using System.Linq;
#if UNITY_EDITOR
namespace WI
{
public class EditorUtil
{
public static int DrawSubclassDropdown(string label, Type target, int selectedIndex)
{
var subclass = Assembly
.GetAssembly(target)
.GetTypes()
.Where(t => t.IsSubclassOf(target))
.Select(t2 => t2.Name).Append(target.Name).ToArray();
return EditorGUILayout.Popup(label, selectedIndex, subclass);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 90279b59eabde62429020d873d117787
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using System;
namespace WI.Util
{
public static class EnumExtension
{
public static void AddFlag<TEnum>(this ref TEnum currentValue, TEnum flagToAdd) where TEnum : struct, Enum
{
// currentValue와 flagToAdd가 같은 Enum 타입인지 확인합니다.
if (!typeof(TEnum).IsEnum)
{
throw new ArgumentException("TEnum must be an enumerated type.");
}
// currentValue와 flagToAdd를 숫자형식으로 변환한 후 OR 연산합니다.
int currentValueInt = Convert.ToInt32(currentValue);
int flagToAddInt = Convert.ToInt32(flagToAdd);
int resultInt = currentValueInt | flagToAddInt;
// OR 연산 결과를 Enum 타입으로 변환하여 currentValue 매개변수에 할당합니다.
currentValue = (TEnum)Enum.ToObject(typeof(TEnum), resultInt);
}
public static void RemoveFlag<TEnum>(this ref TEnum currentValue, TEnum flagToAdd) where TEnum : struct, Enum
{
// currentValue와 flagToAdd가 같은 Enum 타입인지 확인합니다.
if (!typeof(TEnum).IsEnum)
{
throw new ArgumentException("TEnum must be an enumerated type.");
}
// currentValue와 flagToAdd를 숫자형식으로 변환한 후 OR 연산합니다.
int currentValueInt = Convert.ToInt32(currentValue);
int flagToAddInt = Convert.ToInt32(flagToAdd);
int resultInt = currentValueInt & ~flagToAddInt;
// OR 연산 결과를 Enum 타입으로 변환하여 currentValue 매개변수에 할당합니다.
currentValue = (TEnum)Enum.ToObject(typeof(TEnum), resultInt);
}
public static bool StringToEnum<T>(string value, out T result)
{
result = default;
if (!Enum.TryParse(typeof(T), value, out var parse))
return false;
result = (T)parse;
return true;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fc9f859cae01abf49a6249326cb45217

View File

@@ -0,0 +1,106 @@
using System.Collections.Generic;
using UnityEngine;
namespace WI
{
[System.Serializable]
public struct SKeyValuePair<T, T2>
{
[SerializeField] public T Key;
[SerializeField] public T2 Value;
public SKeyValuePair(T key, T2 value)
{
Key = key;
Value = value;
}
}
/// <summary>
/// SerializeDictionary For Unity
/// </summary>
[System.Serializable]
public partial class SDictionary<T, T2> : Dictionary<T, T2>
{
[SerializeField] public List<SKeyValuePair<T, T2>> datas = new List<SKeyValuePair<T, T2>>();
public SDictionary()
{
foreach (var d in datas)
{
Add(d.Key, d.Value);
}
}
void Refresh()
{
if (base.Count == datas.Count)
return;
foreach (var d in datas)
{
base.TryAdd(d.Key, d.Value);
}
}
public new T2 this[T key]
{
get
{
Refresh();
return base[key];
}
set
{
for (int i = 0; i < datas.Count; ++i)
{
var currentData = datas[i];
var ck = currentData.Key;
if (ck.Equals(key))
datas.RemoveAt(i);
}
datas.Add(new SKeyValuePair<T, T2>(key, value));
base[key] = value;
}
}
public bool Add(in T key, in T2 value)
{
if (base.ContainsKey(key))
return false;
base.Add(key, value);
datas.Add(new SKeyValuePair<T, T2>(key, value));
return true;
}
public bool Remove(in T key)
{
if (!base.ContainsKey(key))
return false;
for (int i = 0; i < datas.Count; ++i)
{
if (datas[i].Key.Equals(key))
{
datas.RemoveAt(i);
base.Remove(key);
return true;
}
}
return false;
}
public new void Clear()
{
base.Clear();
datas.Clear();
}
public bool TryGetValue(in T key, out T2 value)
{
Refresh();
return base.TryGetValue(key, out value);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b662546762d5c3a428a8c061af95d1ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine.SceneManagement; //3
namespace WI
{
#if UNITY_EDITOR
public class SelectGameObjectsWithMissingScripts : Editor
{
[MenuItem("Tools/WPAG Utilities/Select GameObjects With Missing Scripts")]
static void SelectGameObjects()
{
//Get the current scene and all top-level GameObjects in the scene hierarchy
Scene currentScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
GameObject[] rootObjects = currentScene.GetRootGameObjects();
List<Object> objectsWithDeadLinks = new List<Object>();
foreach (GameObject g in rootObjects)
{
//Get all components on the GameObject, then loop through them
Component[] components = g.GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
Component currentComponent = components[i];
//If the component is null, that means it's a missing script!
if (currentComponent == null)
{
//Add the sinner to our naughty-list
objectsWithDeadLinks.Add(g);
Selection.activeGameObject = g;
Debug.Log(g + " has a missing script!");
break;
}
}
}
if (objectsWithDeadLinks.Count > 0)
{
//Set the selection in the editor
Selection.objects = objectsWithDeadLinks.ToArray();
}
else
{
Debug.Log("No GameObjects in '" + currentScene.name + "' have missing scripts! Yay!");
}
}
}
#endif
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7bcae29630d042f4187a2232b53469c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
using UnityEditor;
using UnityEngine;
namespace WI
{
public static class Wathf
{
/// <summary>
/// 1.618 : 1 = x : y
/// ex) standard = 3
/// result[0] = f(x==standard)
/// result[1] = f(y==standard)
/// </summary>
/// <param name="standard"></param>
/// <param name="result"></param>
public static void GoldenRatio(float standard, out float[] result)
{
result = new float[2];
result[0] = standard * 1.618f;
result[1] = standard * 0.618f;
}
public static bool GetCrossVector(Vector3[] a, Vector3[] b, ref Vector3 cp)
{
if (CrossCheck2D(a, b))
{
cp = CrossCheck2DVector(a, b);
return true;
}
cp = Vector3.one * float.MaxValue;
return false;
}
static Vector3 CrossCheck2DVector(Vector3[] p1, Vector3[] p2)
{
Vector3 a = p1[0];
Vector3 b = p1[1];
Vector3 c = p2[0];
Vector3 d = p2[1];
float Y = a.y;
float x1, x2, x3, x4, z1, z2, z3, z4, X, Z;
x1 = a.x; z1 = a.z;
x2 = b.x; z2 = b.z;
x3 = c.x; z3 = c.z;
x4 = d.x; z4 = d.z;
float cross = ((x1 - x2) * (z3 - z4) - (z1 - z2) * (x3 - x4));
if (cross == 0 /* parallel */) return new Vector3(10000, 10000, 10000);
X = ((x1 * z2 - z1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * z4 - z3 * x4)) / cross;
Z = ((x1 * z2 - z1 * x2) * (z3 - z4) - (z1 - z2) * (x3 * z4 - z3 * x4)) / cross;
return new Vector3(X, Y, Z);
}
static bool CrossCheck2D(Vector3[] p1, Vector3[] p2)
{
Vector3 a = p1[0];
Vector3 b = p1[1];
Vector3 c = p2[0];
Vector3 d = p2[1];
// (x, Y , z)
float Y = a.y;
float x1, x2, x3, x4, z1, z2, z3, z4, X, Z;
x1 = a.x; z1 = a.z;
x2 = b.x; z2 = b.z;
x3 = c.x; z3 = c.z;
x4 = d.x; z4 = d.z;
float cross = ((x1 - x2) * (z3 - z4) - (z1 - z2) * (x3 - x4));
if (Mathf.Abs(cross) <0.05f /* parallel */)
{
return false;
}
X = ((x1 * z2 - z1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * z4 - z3 * x4)) / cross;
Z = ((x1 * z2 - z1 * x2) * (z3 - z4) - (z1 - z2) * (x3 * z4 - z3 * x4)) / cross;
var distance = b - a;
var legth = d - c;
if (distance.normalized == legth.normalized)
return false;
return
CheckDotInLine(a, b, new Vector3(X, Y, Z))
&& CheckDotInLine(c, d, new Vector3(X, Y, Z));
}
static bool CheckDotInLine(Vector3 a, Vector3 b, Vector3 dot)
{
float epsilon = 0.00001f;
float dAB = Vector3.Distance(a, b);
float dADot = Vector3.Distance(a, dot);
float dBDot = Vector3.Distance(b, dot);
return ((dAB + epsilon) >= (dADot + dBDot));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 751606caaaf29eb48a4d11fe8079241e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace WI
{
public static partial class Wtil
{
#if UNITY_EDITOR
public static bool GetCurrentSelectGameObject(out GameObject obj)
{
obj = Selection.activeGameObject;
if (obj == null)
return false;
return true;
}
#endif
public static bool isScreenOver(this Camera cam, Vector3 pos)
{
var viewPos = cam.WorldToViewportPoint(pos);
return viewPos.z < 0 || (viewPos.x < 0 || viewPos.x > 1) || (viewPos.y < 0 || viewPos.y > 1);
}
public static void AddLayer(this Camera cam, int layer)
{
cam.cullingMask |= 1 << layer;
}
public static bool Overlaps(this RectTransform rectTrans1, RectTransform rectTrans2)
{
var rect1 = new Rect(rectTrans1.localPosition.x, rectTrans1.localPosition.y, rectTrans1.rect.width, rectTrans1.rect.height);
var rect2 = new Rect(rectTrans2.localPosition.x, rectTrans2.localPosition.y, rectTrans2.rect.width, rectTrans2.rect.height);
return rect1.Overlaps(rect2);
}
public static void RemoveLayer(this Camera cam, int layer)
{
cam.cullingMask &= ~(1 << layer);
}
public static void NullCleaning<T, T2>(this Dictionary<T, T2> table)
{
var keys = table.Keys;
foreach (var k in keys)
{
if (k == null)
{
table.Remove(k);
continue;
}
if (table[k] == null)
{
table.Remove(k);
}
}
}
public static bool Add<T>(this HashSet<T> hash, T[] values)
{
bool result = true;
for(int i = 0; i < values.Length; ++i)
{
result = hash.Add(values[i]);
}
return result;
}
public static T2[] ArrayConvertor<T, T2>(T[] origin) where T : MonoBehaviour where T2 : MonoBehaviour
{
T2[] result = new T2[origin.Length];
for (int i = 0; i < result.Length; ++i)
{
result[i] = origin[i] as T2;
}
return result;
}
static Dictionary<Component, MeshRenderer[]> meshGroupCache = new();
public static Vector3 GetMeshGroupCenter(this Component root)
{
if (!meshGroupCache.TryGetValue(root, out _))
{
meshGroupCache.Add(root, root.GetComponentsInChildren<MeshRenderer>());
}
var meshs = meshGroupCache[root];
Vector3 total = Vector3.zero;
foreach (var m in meshs)
{
total += m.bounds.center;
}
return total / meshs.Length;
}
public static Vector3 GetMeshGroupCenter(MeshRenderer[] meshGroup)
{
Vector3 total = Vector3.zero;
foreach (var m in meshGroup)
{
total += m.bounds.center;
}
return total / meshGroup.Length;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f3a00520bc61c9044890b8f8187d7553
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: