using System.Collections.Generic; using UnityEngine; using UnityScene = UnityEngine.SceneManagement.Scene; namespace Projectiles { public static class SceneExtensions { // PUBLIC METHODS public static T GetComponent(this UnityScene scene, bool includeInactive = false) where T : class { List roots = new List(); scene.GetRootGameObjects(roots); for (int i = 0, count = roots.Count; i < count; ++i) { T component = roots[i].GetComponentInChildren(includeInactive); if (component != null) return component; } return default; } public static List GetComponents(this UnityScene scene, bool includeInactive = false) where T : class { List allComponents = new List(); List objectComponents = new List(); List sceneRootObjects = new List(); scene.GetRootGameObjects(sceneRootObjects); for (int i = 0, count = sceneRootObjects.Count; i < count; ++i) { sceneRootObjects[i].GetComponentsInChildren(includeInactive, objectComponents); allComponents.AddRange(objectComponents); objectComponents.Clear(); } return allComponents; } public static void GetComponents(this UnityScene scene, List components, bool includeInactive = false) where T : class { List objectComponents = new List(); List sceneRootObjects = new List(); scene.GetRootGameObjects(sceneRootObjects); components.Clear(); for (int i = 0, count = sceneRootObjects.Count; i < count; ++i) { sceneRootObjects[i].GetComponentsInChildren(includeInactive, objectComponents); components.AddRange(objectComponents); objectComponents.Clear(); } } } }