forked from Shardstone/trail-into-darkness
added zlinq
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user