added zlinq

This commit is contained in:
Sebastian Bularca
2026-04-02 07:43:33 +02:00
parent 81b8eadaf1
commit 36d3f112ef
52 changed files with 3430 additions and 17 deletions

View File

@@ -5,26 +5,26 @@ using Object = UnityEngine.Object;
namespace Jovian.Utilities {
public static class GameObjectUtilities {
public static void DestroyGameObjectsOfType<T>() where T : MonoBehaviour {
T[] objects = Object.FindObjectsOfType<T>();
for (int i = 0; i < objects.Length; ++i) {
Object.Destroy(objects[i].gameObject);
var objects = Object.FindObjectsByType<T>(FindObjectsInactive.Include, FindObjectsSortMode.None);
foreach(var t in objects) {
Object.Destroy(t.gameObject);
}
}
public static bool IsGameObjectAChildOfGameObject(this GameObject targetGameObject, GameObject potentialParentGameObject) {
if (targetGameObject == null) {
if(!targetGameObject) {
return false;
}
Transform potentialParentTransform = potentialParentGameObject.transform;
Transform checkTransform = targetGameObject.transform;
var potentialParentTransform = potentialParentGameObject.transform;
var checkTransform = targetGameObject.transform;
do {
if (checkTransform == potentialParentTransform) {
if(checkTransform == potentialParentTransform) {
return true;
}
checkTransform = checkTransform.parent;
} while (checkTransform != null);
} while(checkTransform);
return false;
}
@@ -36,18 +36,18 @@ namespace Jovian.Utilities {
bool allowPartialMatch = false,
StringComparison stringComparison = StringComparison.Ordinal) {
childGameObject = null;
if (gameObject == null) {
if(!gameObject) {
return false;
}
Transform[] children = gameObject.GetComponentsInChildren<Transform>(includeInactive);
foreach (Transform child in children) {
if (allowPartialMatch && child.name.Contains(name, stringComparison)) {
var children = gameObject.GetComponentsInChildren<Transform>(includeInactive);
foreach(var child in children) {
if(allowPartialMatch && child.name.Contains(name, stringComparison)) {
childGameObject = child.gameObject;
return true;
}
if (!allowPartialMatch && child.name.Equals(name, stringComparison)) {
if(!allowPartialMatch && child.name.Equals(name, stringComparison)) {
childGameObject = child.gameObject;
return true;
}
@@ -56,4 +56,4 @@ namespace Jovian.Utilities {
return false;
}
}
}
}