Files
trail-into-darkness/Packages/com.jovian.utilities/Runtime/EditorRuntimeAccessible/HierarchyUtility.cs
2026-04-02 07:22:33 +02:00

33 lines
1.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using System;
using UnityEditor.SceneManagement;
#endif
namespace Jovian.Utilities {
public static class HierarchyUtility {
#if UNITY_EDITOR
public static List<TComponent> FindComponentsInHierarchy<TComponent>(bool includeInactive = false) where TComponent : Component {
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if(prefabStage == null) {
return SceneUtility.FindComponentsInActiveScene<TComponent>(includeInactive);
}
else {
return new List<TComponent>(prefabStage.prefabContentsRoot.GetComponentsInChildren<TComponent>(includeInactive));
}
}
public static List<Component> FindComponentsInHierarchy(Type componentType, bool includeInactive = false) {
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if(prefabStage == null) {
return SceneUtility.FindComponentsInActiveScene(componentType, includeInactive);
}
else {
return new List<Component>(prefabStage.prefabContentsRoot.GetComponentsInChildren(componentType, includeInactive));
}
}
#endif
}
}