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 FindComponentsInHierarchy(bool includeInactive = false) where TComponent : Component { PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if(prefabStage == null) { return SceneUtility.FindComponentsInActiveScene(includeInactive); } else { return new List(prefabStage.prefabContentsRoot.GetComponentsInChildren(includeInactive)); } } public static List FindComponentsInHierarchy(Type componentType, bool includeInactive = false) { PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if(prefabStage == null) { return SceneUtility.FindComponentsInActiveScene(componentType, includeInactive); } else { return new List(prefabStage.prefabContentsRoot.GetComponentsInChildren(componentType, includeInactive)); } } #endif } }