您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

163 行
6.1 KiB

using System;
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
[CustomEditorForRenderPipeline(typeof(Camera), typeof(LightweightPipelineAsset))]
[CanEditMultipleObjects]
internal class LightweightRenderPipelineCameraEditor : CameraEditor
{
internal class Styles
{
public readonly GUIContent renderingPathLabel = EditorGUIUtility.TrTextContent("Rendering Path", "Lightweight Render Pipeline only supports Forward rendering path.");
public readonly GUIContent[] renderingPathOptions = { EditorGUIUtility.TrTextContent("Forward") };
public readonly string hdrDisabledWarning = "HDR rendering is disabled in the Lightweight Render Pipeline asset.";
public readonly string mssaDisabledWarning = "Anti-aliasing is disabled in the Lightweight Render Pipeline asset.";
};
public Camera camera { get { return target as Camera; } }
// Animation Properties
public bool isSameClearFlags { get { return !settings.clearFlags.hasMultipleDifferentValues; } }
public bool isSameOrthographic { get { return !settings.orthographic.hasMultipleDifferentValues; } }
static readonly int[] s_RenderingPathValues = {0};
static Styles s_Styles;
LightweightPipelineAsset m_LightweightPipeline;
readonly AnimBool m_ShowBGColorAnim = new AnimBool();
readonly AnimBool m_ShowOrthoAnim = new AnimBool();
readonly AnimBool m_ShowTargetEyeAnim = new AnimBool();
void SetAnimationTarget(AnimBool anim, bool initialize, bool targetValue)
{
if (initialize)
{
anim.value = targetValue;
anim.valueChanged.AddListener(Repaint);
}
else
{
anim.target = targetValue;
}
}
void UpdateAnimationValues(bool initialize)
{
SetAnimationTarget(m_ShowBGColorAnim, initialize, isSameClearFlags && (camera.clearFlags == CameraClearFlags.SolidColor || camera.clearFlags == CameraClearFlags.Skybox));
SetAnimationTarget(m_ShowOrthoAnim, initialize, isSameOrthographic && camera.orthographic);
SetAnimationTarget(m_ShowTargetEyeAnim, initialize, settings.targetEye.intValue != (int)StereoTargetEyeMask.Both || PlayerSettings.virtualRealitySupported);
}
public new void OnEnable()
{
m_LightweightPipeline = GraphicsSettings.renderPipelineAsset as LightweightPipelineAsset;
settings.OnEnable();
UpdateAnimationValues(true);
}
public void OnDisable()
{
m_ShowBGColorAnim.valueChanged.RemoveListener(Repaint);
m_ShowOrthoAnim.valueChanged.RemoveListener(Repaint);
m_ShowTargetEyeAnim.valueChanged.RemoveListener(Repaint);
m_LightweightPipeline = null;
}
public override void OnInspectorGUI()
{
if (s_Styles == null)
s_Styles = new Styles();
settings.Update();
UpdateAnimationValues(false);
settings.DrawClearFlags();
using (var group = new EditorGUILayout.FadeGroupScope(m_ShowBGColorAnim.faded))
if (group.visible) settings.DrawBackgroundColor();
settings.DrawCullingMask();
EditorGUILayout.Space();
settings.DrawProjection();
settings.DrawClippingPlanes();
settings.DrawNormalizedViewPort();
EditorGUILayout.Space();
settings.DrawDepth();
DrawRenderingPath();
DrawTargetTexture();
settings.DrawOcclusionCulling();
DrawHDR();
DrawMSAA();
settings.DrawVR();
settings.DrawMultiDisplay();
using (var group = new EditorGUILayout.FadeGroupScope(m_ShowTargetEyeAnim.faded))
if (group.visible) settings.DrawTargetEye();
EditorGUILayout.Space();
EditorGUILayout.Space();
settings.ApplyModifiedProperties();
}
void DrawRenderingPath()
{
using (new EditorGUI.DisabledScope(true))
{
EditorGUILayout.IntPopup(s_Styles.renderingPathLabel, 0, s_Styles.renderingPathOptions, s_RenderingPathValues);
}
}
void DrawHDR()
{
bool disabled = settings.HDR.boolValue && !m_LightweightPipeline.supportsHDR;
using (new EditorGUI.DisabledScope(disabled))
{
settings.DrawHDR();
}
if (disabled)
EditorGUILayout.HelpBox(s_Styles.hdrDisabledWarning, MessageType.Info);
}
void DrawTargetTexture()
{
EditorGUILayout.PropertyField(settings.targetTexture);
if (!settings.targetTexture.hasMultipleDifferentValues)
{
var texture = settings.targetTexture.objectReferenceValue as RenderTexture;
int pipelineSamplesCount = m_LightweightPipeline.msaaSampleCount;
if (texture && texture.antiAliasing > pipelineSamplesCount)
{
string pipelineMSAACaps = (pipelineSamplesCount > 1)
? String.Format("is set to support {0}x", pipelineSamplesCount)
: "has MSAA disabled";
EditorGUILayout.HelpBox(String.Format("Camera target texture requires {0}x MSAA. Lightweight pipeline {1}.", texture.antiAliasing, pipelineMSAACaps),
MessageType.Warning, true);
}
}
}
void DrawMSAA()
{
bool disabled = settings.allowMSAA.boolValue && m_LightweightPipeline.msaaSampleCount <= 1;
using (new EditorGUI.DisabledScope(disabled))
{
settings.DrawMSAA();
}
if (disabled)
EditorGUILayout.HelpBox(s_Styles.mssaDisabledWarning, MessageType.Info);
}
}
}