First commit

This commit is contained in:
sbularca
2026-05-19 15:52:04 +02:00
commit 27b7aeee46
1660 changed files with 240354 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
using System;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Jovian.Utilities {
public static class GameObjectUtilities {
public static void DestroyGameObjectsOfType<T>() where T : MonoBehaviour {
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) {
return false;
}
var potentialParentTransform = potentialParentGameObject.transform;
var checkTransform = targetGameObject.transform;
do {
if(checkTransform == potentialParentTransform) {
return true;
}
checkTransform = checkTransform.parent;
} while(checkTransform);
return false;
}
public static bool TryFindChildByName(this GameObject gameObject,
string name,
out GameObject childGameObject,
bool includeInactive = false,
bool allowPartialMatch = false,
StringComparison stringComparison = StringComparison.Ordinal) {
childGameObject = null;
if(!gameObject) {
return false;
}
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)) {
childGameObject = child.gameObject;
return true;
}
}
return false;
}
}
}