using System.Linq; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; namespace PhxhSDK.Res { public class SceneHandle { public Scene Scene { get; private set; } public SceneHandle(Scene scene) { Scene = scene; } public Camera SceneMainCamera => GetSceneCamera();//GetSceneRootComponent(Scene); public Volume SceneVolume => GetSceneVolume(); public CameraRoot SceneCameraRoot => GetSceneRootComponent(Scene); public static T GetSceneRootComponent(Scene scene) where T : Component { return scene.GetRootGameObjects().FirstOrDefault(root => root.GetComponent() != null)?.GetComponent(); } public Camera GetSceneCamera() { if (SceneCameraRoot) { return SceneCameraRoot.Camera; } return GetSceneRootComponent(Scene); } public Volume GetSceneVolume() { GameObject[] goRoots = Scene.GetRootGameObjects(); foreach (GameObject goRoot in goRoots) // 临时获取方法 { if (goRoot.name.Equals("Art")) return goRoot.GetComponentInChildren(); } return null; } } }