您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
77 行
3.5 KiB
77 行
3.5 KiB
using System;
|
|
using System.Reflection;
|
|
using UnityEngine;
|
|
using UnityEngine.Experimental.Rendering;
|
|
using UnityEngine.Experimental.Rendering.HDPipeline;
|
|
using UnityEngine.Rendering.PostProcessing;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace UnityEditor.Experimental.Rendering
|
|
{
|
|
using _ = CoreEditorUtils;
|
|
|
|
partial class HDCameraEditor
|
|
{
|
|
void OnSceneGUI()
|
|
{
|
|
var c = (Camera)target;
|
|
|
|
if (!CameraEditorUtils.IsViewPortRectValidToRender(c.rect))
|
|
return;
|
|
|
|
SceneViewOverlay_Window(_.GetContent("Camera Preview"), OnOverlayGUI, -100, target);
|
|
|
|
CameraEditorUtils.HandleFrustrum(c);
|
|
}
|
|
|
|
void OnOverlayGUI(Object target, SceneView sceneView)
|
|
{
|
|
CameraEditorUtils.DrawCameraSceneViewOverlay(target, sceneView, InitializePreviewCamera);
|
|
}
|
|
|
|
Camera InitializePreviewCamera(Camera c, Vector2 previewSize)
|
|
{
|
|
m_PreviewCamera.CopyFrom(c);
|
|
EditorUtility.CopySerialized(c, m_PreviewCamera);
|
|
var cameraData = c.GetComponent<HDAdditionalCameraData>();
|
|
EditorUtility.CopySerialized(cameraData, m_PreviewAdditionalCameraData);
|
|
var layer = c.GetComponent<PostProcessLayer>() ?? ComponentSingleton<PostProcessLayer>.instance;
|
|
EditorUtility.CopySerialized(layer, m_PreviewPostProcessLayer);
|
|
m_PreviewCamera.cameraType = CameraType.SceneView; // This is required else if we use Preview the image is flipped... (Unity...)
|
|
|
|
// We need to call UpdateDirtyFrameSettings to update the dirty flags that was set in the CopySerialized call
|
|
m_PreviewAdditionalCameraData.UpdateDirtyFrameSettings(true, cameraData.GetFrameSettings());
|
|
// And then to copy the runtime frame settings
|
|
// So this includes the runtime frame settings properly
|
|
cameraData.GetFrameSettings().CopyTo(m_PreviewAdditionalCameraData.GetFrameSettings());
|
|
m_PreviewHDCamera.Update(m_PreviewPostProcessLayer, m_PreviewAdditionalCameraData.GetFrameSettings());
|
|
|
|
var previewTexture = GetPreviewTextureWithSize((int)previewSize.x, (int)previewSize.y);
|
|
m_PreviewCamera.targetTexture = previewTexture;
|
|
m_PreviewCamera.pixelRect = new Rect(0, 0, previewSize.x, previewSize.y);
|
|
|
|
return m_PreviewCamera;
|
|
}
|
|
|
|
static Type k_SceneViewOverlay_WindowFunction = Type.GetType("UnityEditor.SceneViewOverlay+WindowFunction,UnityEditor");
|
|
static Type k_SceneViewOverlay_WindowDisplayOption = Type.GetType("UnityEditor.SceneViewOverlay+WindowDisplayOption,UnityEditor");
|
|
static MethodInfo k_SceneViewOverlay_Window = Type.GetType("UnityEditor.SceneViewOverlay,UnityEditor")
|
|
.GetMethod(
|
|
"Window",
|
|
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public,
|
|
null,
|
|
CallingConventions.Any,
|
|
new[] { typeof(GUIContent), k_SceneViewOverlay_WindowFunction, typeof(int), typeof(Object), k_SceneViewOverlay_WindowDisplayOption },
|
|
null);
|
|
static void SceneViewOverlay_Window(GUIContent title, Action<Object, SceneView> sceneViewFunc, int order, Object target)
|
|
{
|
|
k_SceneViewOverlay_Window.Invoke(null, new[]
|
|
{
|
|
title, DelegateUtility.Cast(sceneViewFunc, k_SceneViewOverlay_WindowFunction),
|
|
order,
|
|
target,
|
|
Enum.ToObject(k_SceneViewOverlay_WindowDisplayOption, 1)
|
|
});
|
|
}
|
|
}
|
|
}
|