|
|
|
|
|
|
using System; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Experimental.Rendering; |
|
|
|
[CustomEditorForRenderPipeline(typeof(Camera), typeof(HDRenderPipelineAsset))] |
|
|
|
//[CustomEditorForRenderPipeline(typeof(Camera), typeof(HDRenderPipelineAsset))]
|
|
|
|
[CanEditMultipleObjects] |
|
|
|
partial class HDCameraEditor : Editor |
|
|
|
{ |
|
|
|
|
|
|
Camera m_PreviewCamera; |
|
|
|
HDAdditionalCameraData m_PreviewAdditionalCameraData; |
|
|
|
PostProcessLayer m_PreviewPostProcessLayer; |
|
|
|
HDCamera m_PreviewHDCamera; |
|
|
|
|
|
|
|
void OnEnable() |
|
|
|
{ |
|
|
|
|
|
|
m_PreviewAdditionalCameraData = m_PreviewCamera.gameObject.AddComponent<HDAdditionalCameraData>(); |
|
|
|
m_PreviewPostProcessLayer = m_PreviewCamera.gameObject.AddComponent<PostProcessLayer>(); |
|
|
|
m_PreviewCamera.enabled = false; |
|
|
|
m_PreviewHDCamera = new HDCamera(m_PreviewCamera); |
|
|
|
m_PreviewHDCamera.Update(m_PreviewPostProcessLayer, m_PreviewAdditionalCameraData.GetFrameSettings()); |
|
|
|
} |
|
|
|
|
|
|
|
void OnDisable() |
|
|
|
|
|
|
|
|
|
|
void SynchronizePreviewCameraWithCamera(Camera c) |
|
|
|
{ |
|
|
|
EditorUtility.CopySerialized(c, m_PreviewCamera); |
|
|
|
var layer = c.GetComponent<PostProcessLayer>(); |
|
|
|
if (layer != null) |
|
|
|
var layer = c.GetComponent<PostProcessLayer>() ?? Assets.ScriptableRenderLoop.PostProcessing.PostProcessing.Runtime.Utils.ComponentSingleton<PostProcessLayer>.instance; |
|
|
|
EditorUtility.CopySerialized(layer, m_PreviewPostProcessLayer); |
|
|
|
m_PreviewCamera.cameraType = CameraType.SceneView; |
|
|
|
m_PreviewHDCamera.Update(m_PreviewPostProcessLayer, m_PreviewAdditionalCameraData.GetFrameSettings()); |
|
|
|
} |
|
|
|
|
|
|
|
RenderTexture GetPreviewTextureWithSize(int width, int height) |
|
|
|
{ |
|
|
|
if (m_PreviewTexture == null || m_PreviewTexture.width != width || m_PreviewTexture.height != height) |
|
|
|
if (m_PreviewPostProcessLayer == null) |
|
|
|
m_PreviewPostProcessLayer = c.gameObject.AddComponent<PostProcessLayer>(); |
|
|
|
EditorUtility.CopySerialized(layer, m_PreviewPostProcessLayer); |
|
|
|
if (m_PreviewTexture != null) |
|
|
|
m_PreviewTexture.Release(); |
|
|
|
|
|
|
|
var baseDesc = m_PreviewHDCamera.renderTextureDesc; |
|
|
|
baseDesc.width = width; |
|
|
|
baseDesc.height = height; |
|
|
|
CoreUtils.UpdateRenderTextureDescriptor(ref baseDesc, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); |
|
|
|
m_PreviewTexture = new RenderTexture(baseDesc); |
|
|
|
else if (m_PreviewPostProcessLayer != null) |
|
|
|
{ |
|
|
|
DestroyImmediate(m_PreviewPostProcessLayer); |
|
|
|
m_PreviewPostProcessLayer = null; |
|
|
|
} |
|
|
|
return m_PreviewTexture; |
|
|
|
} |
|
|
|
} |
|
|
|
} |