using UnityEngine;
using UnityEngine.Rendering.Universal;

namespace NBF
{
    public static class CameraUtils
    {
        public static void SetOverlay(Camera camera, CameraRenderType cameraRenderType = CameraRenderType.Overlay)
        {
            var stageCameraData = camera.GetUniversalAdditionalCameraData();
            if (stageCameraData != null)
            {
                stageCameraData.renderType = cameraRenderType;
            }
        }


        public static void AddStack(this Camera camera, Camera overlayCamera)
        {
            var MainCameraData = camera.GetUniversalAdditionalCameraData();
            if (!MainCameraData.cameraStack.Contains(overlayCamera)) // 防止重复添加
            {
                SetOverlay(overlayCamera);
                MainCameraData.cameraStack.Add(overlayCamera);
            }
        }

        public static void RemoveStack(this Camera camera, Camera overlayCamera)
        {
            var MainCameraData = camera.GetUniversalAdditionalCameraData();
            if (MainCameraData.cameraStack.Contains(overlayCamera))
            {
                MainCameraData.cameraStack.Remove(overlayCamera);
                SetOverlay(overlayCamera, CameraRenderType.Base);
            }
        }
    }
}