50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
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<Camera>(Scene);
|
|
|
|
public Volume SceneVolume => GetSceneVolume();
|
|
|
|
public CameraRoot SceneCameraRoot => GetSceneRootComponent<CameraRoot>(Scene);
|
|
|
|
public static T GetSceneRootComponent<T>(Scene scene) where T : Component
|
|
{
|
|
return scene.GetRootGameObjects().FirstOrDefault(root => root.GetComponent<T>() != null)?.GetComponent<T>();
|
|
}
|
|
|
|
public Camera GetSceneCamera()
|
|
{
|
|
if (SceneCameraRoot)
|
|
{
|
|
return SceneCameraRoot.Camera;
|
|
}
|
|
|
|
return GetSceneRootComponent<Camera>(Scene);
|
|
}
|
|
|
|
public Volume GetSceneVolume()
|
|
{
|
|
GameObject[] goRoots = Scene.GetRootGameObjects();
|
|
foreach (GameObject goRoot in goRoots) // 临时获取方法
|
|
{
|
|
if (goRoot.name.Equals("Art"))
|
|
return goRoot.GetComponentInChildren<Volume>();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|