浏览代码

(ip) update reflection probe editor refactoring

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
1dc19592
共有 5 个文件被更改,包括 291 次插入111 次删除
  1. 139
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  2. 95
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  3. 11
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs.meta
  4. 146
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  5. 11
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs.meta

139
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs


using System;
using UnityEditor.AnimatedValues;
using UnityEditor.Experimental.Rendering;
using UnityEditor.Experimental.Rendering;
using UnityEngine.Events;
using UnityEngine.Rendering;
class HDReflectionProbeEditor : Editor
partial class HDReflectionProbeEditor : Editor
class SerializedReflectionProbe
{
internal SerializedProperty mode;
internal SerializedProperty renderDynamicObjects;
internal SerializedProperty customBakedTexture;
internal SerializedProperty refreshMode;
internal SerializedProperty timeSlicingMode;
internal SerializedProperty intensityMultiplier;
internal SerializedProperty influenceShape;
public SerializedReflectionProbe(SerializedObject so, SerializedObject addso)
{
var o = new PropertyFetcher<HDAdditionalReflectionData>(addso);
mode = so.FindProperty("m_Mode");
customBakedTexture = so.FindProperty("m_CustomBakedTexture");
renderDynamicObjects = so.FindProperty("m_RenderDynamicObjects");
refreshMode = so.FindProperty("m_RefreshMode");
timeSlicingMode = so.FindProperty("m_TimeSlicingMode");
intensityMultiplier = so.FindProperty("m_IntensityMultiplier");
influenceShape = o.Find(d => d.m_InfluenceShape);
}
}
class UIState
{
AnimBool[] m_ModeSettingsDisplays = new AnimBool[Enum.GetValues(typeof(ReflectionProbeMode)).Length];
internal UIState()
{
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
m_ModeSettingsDisplays[i] = new AnimBool();
}
internal void Reset(UnityAction repaint, ReflectionProbeMode mode)
{
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
{
m_ModeSettingsDisplays[i].valueChanged.RemoveAllListeners();
m_ModeSettingsDisplays[i].valueChanged.AddListener(repaint);
m_ModeSettingsDisplays[i].value = (int)mode == i;
}
}
public float GetModeFaded(ReflectionProbeMode mode)
{
return m_ModeSettingsDisplays[(int)mode].faded;
}
public void SetModeTarget(int value)
{
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
m_ModeSettingsDisplays[i].target = i == value;
}
}
delegate void Drawer(UIState s, SerializedReflectionProbe p);
Matrix4x4 m_OldLocalSpace = Matrix4x4.identity;
m_UIState.Reset(Repaint, (ReflectionProbeMode)m_SerializedReflectionProbe.mode.enumValueIndex);
m_UIState.Reset(this, Repaint, m_SerializedReflectionProbe.mode.intValue);
}
public override void OnInspectorGUI()

var s = m_UIState;
var p = m_SerializedReflectionProbe;
Drawer_ReflectionProbeMode(s, p);
Drawer_ModeSettings(s, p);
Drawer_ReflectionProbeMode(s, p, this);
Drawer_ModeSettings(s, p, this);
Drawer_InfluenceShape(s, p);
Drawer_IntensityMultiplier(s, p);
Drawer_InfluenceShape(s, p, this);
Drawer_IntensityMultiplier(s, p, this);
Drawer_Toolbar(s, p, this);
if (s.shouldUpdateOldLocalSpace)
{
s.shouldUpdateOldLocalSpace = false;
UpdateOldLocalSpace();
}
static void Drawer_NOOP(UIState s, SerializedReflectionProbe p) { }
// Mode
static readonly GUIContent[] k_Content_ReflectionProbeMode = { new GUIContent("Baked"), new GUIContent("Custom"), new GUIContent("Realtime") };
static readonly int[] k_Content_ReflectionProbeModeValues = { (int)ReflectionProbeMode.Baked, (int)ReflectionProbeMode.Custom, (int)ReflectionProbeMode.Realtime };
static void Drawer_ReflectionProbeMode(UIState s, SerializedReflectionProbe p)
{
EditorGUILayout.IntPopup(p.mode, k_Content_ReflectionProbeMode, k_Content_ReflectionProbeModeValues, CoreEditorUtils.GetContent("Type|'Baked Cubemap' uses the 'Auto Baking' mode from the Lighting window. If it is enabled then baking is automatic otherwise manual bake is needed (use the bake button below). \n'Custom' can be used if a custom cubemap is wanted. \n'Realtime' can be used to dynamically re-render the cubemap during runtime (via scripting)."));
s.SetModeTarget(p.mode.intValue);
}
static void Drawer_InfluenceShape(UIState s, SerializedReflectionProbe p)
void UpdateOldLocalSpace()
EditorGUILayout.PropertyField(p.influenceShape, CoreEditorUtils.GetContent("Shape"));
m_OldLocalSpace = GetLocalSpace((ReflectionProbe)target);
static void Drawer_IntensityMultiplier(UIState s, SerializedReflectionProbe p)
static Matrix4x4 GetLocalSpace(ReflectionProbe probe)
EditorGUILayout.PropertyField(p.intensityMultiplier, CoreEditorUtils.GetContent("Intensity"));
}
// Mode specific settings
static void Drawer_ModeSettings(UIState s, SerializedReflectionProbe p)
{
for (var i = 0; i < k_ModeDrawers.Length; ++i)
{
if (EditorGUILayout.BeginFadeGroup(s.GetModeFaded((ReflectionProbeMode)i)))
{
++EditorGUI.indentLevel;
k_ModeDrawers[i](s, p);
--EditorGUI.indentLevel;
}
EditorGUILayout.EndFadeGroup();
}
}
static readonly Drawer[] k_ModeDrawers = { Drawer_NOOP, Drawer_ModeRealtime , Drawer_ModeCustom };
static void Drawer_ModeCustom(UIState s, SerializedReflectionProbe p)
{
EditorGUILayout.PropertyField(p.renderDynamicObjects, CoreEditorUtils.GetContent("Dynamic Objects|If enabled dynamic objects are also rendered into the cubemap"));
p.customBakedTexture.objectReferenceValue = EditorGUILayout.ObjectField(CoreEditorUtils.GetContent("Cubemap"), p.customBakedTexture.objectReferenceValue, typeof(Cubemap), false);
Vector3 t = probe.transform.position;
return Matrix4x4.TRS(t, GetLocalSpaceRotation(probe), Vector3.one);
static void Drawer_ModeRealtime(UIState s, SerializedReflectionProbe p)
static Quaternion GetLocalSpaceRotation(ReflectionProbe probe)
EditorGUILayout.PropertyField(p.refreshMode, CoreEditorUtils.GetContent("Refresh Mode|Controls how this probe refreshes in the Player"));
EditorGUILayout.PropertyField(p.timeSlicingMode, CoreEditorUtils.GetContent("Time Slicing|If enabled this probe will update over several frames, to help reduce the impact on the frame rate"));
bool supportsRotation = (SupportedRenderingFeatures.active.reflectionProbeSupportFlags & SupportedRenderingFeatures.ReflectionProbeSupportFlags.Rotation) != 0;
if (supportsRotation)
return probe.transform.rotation;
else
return Quaternion.identity;
}
}
}

95
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs


using System;
using UnityEditor.AnimatedValues;
using UnityEditor.Experimental.Rendering;
using UnityEditorInternal;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
namespace UnityEditor
{
partial class HDReflectionProbeEditor
{
class SerializedReflectionProbe
{
internal SerializedObject so;
internal SerializedProperty mode;
internal SerializedProperty renderDynamicObjects;
internal SerializedProperty customBakedTexture;
internal SerializedProperty refreshMode;
internal SerializedProperty timeSlicingMode;
internal SerializedProperty intensityMultiplier;
internal SerializedProperty influenceShape;
public SerializedReflectionProbe(SerializedObject so, SerializedObject addso)
{
var o = new PropertyFetcher<HDAdditionalReflectionData>(addso);
this.so = so;
mode = so.FindProperty("m_Mode");
customBakedTexture = so.FindProperty("m_CustomBakedTexture");
renderDynamicObjects = so.FindProperty("m_RenderDynamicObjects");
refreshMode = so.FindProperty("m_RefreshMode");
timeSlicingMode = so.FindProperty("m_TimeSlicingMode");
intensityMultiplier = so.FindProperty("m_IntensityMultiplier");
influenceShape = o.Find(d => d.m_InfluenceShape);
}
}
class UIState
{
AnimBool[] m_ModeSettingsDisplays = new AnimBool[Enum.GetValues(typeof(ReflectionProbeMode)).Length];
Editor owner { get; set; }
public bool shouldUpdateOldLocalSpace { get; set; }
public bool sceneViewEditing
{
get { return IsReflectionProbeEditMode(EditMode.editMode) && EditMode.IsOwner(owner); }
}
internal UIState()
{
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
m_ModeSettingsDisplays[i] = new AnimBool();
}
internal void Reset(Editor owner, UnityAction repaint, int modeValue)
{
this.owner = owner;
shouldUpdateOldLocalSpace = false;
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
{
m_ModeSettingsDisplays[i].valueChanged.RemoveAllListeners();
m_ModeSettingsDisplays[i].valueChanged.AddListener(repaint);
m_ModeSettingsDisplays[i].value = modeValue == i;
}
}
public float GetModeFaded(ReflectionProbeMode mode)
{
return m_ModeSettingsDisplays[(int)mode].faded;
}
public void SetModeTarget(int value)
{
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
m_ModeSettingsDisplays[i].target = i == value;
}
static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode)
{
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin;
}
}
delegate void Drawer(UIState s, SerializedReflectionProbe p, Editor owner);
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs.meta


fileFormatVersion: 2
guid: 4e4bdea98ec8e664b95e5c89aa680636
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

146
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs


using UnityEditor.Experimental.Rendering;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor
{
partial class HDReflectionProbeEditor
{
static void Drawer_NOOP(UIState s, SerializedReflectionProbe p, Editor owner) { }
#region Field Drawers
static readonly GUIContent[] k_Content_ReflectionProbeMode = { new GUIContent("Baked"), new GUIContent("Custom"), new GUIContent("Realtime") };
static readonly int[] k_Content_ReflectionProbeModeValues = { (int)ReflectionProbeMode.Baked, (int)ReflectionProbeMode.Custom, (int)ReflectionProbeMode.Realtime };
static void Drawer_ReflectionProbeMode(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUI.showMixedValue = p.mode.hasMultipleDifferentValues;
EditorGUILayout.IntPopup(p.mode, k_Content_ReflectionProbeMode, k_Content_ReflectionProbeModeValues, CoreEditorUtils.GetContent("Type|'Baked Cubemap' uses the 'Auto Baking' mode from the Lighting window. If it is enabled then baking is automatic otherwise manual bake is needed (use the bake button below). \n'Custom' can be used if a custom cubemap is wanted. \n'Realtime' can be used to dynamically re-render the cubemap during runtime (via scripting)."));
EditorGUI.showMixedValue = false;
s.SetModeTarget(p.mode.intValue);
}
static void Drawer_InfluenceShape(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.PropertyField(p.influenceShape, CoreEditorUtils.GetContent("Shape"));
}
static void Drawer_IntensityMultiplier(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.PropertyField(p.intensityMultiplier, CoreEditorUtils.GetContent("Intensity"));
}
#endregion
#region Toolbar
static readonly EditMode.SceneViewEditMode[] k_Toolbar_SceneViewEditModes =
{
EditMode.SceneViewEditMode.ReflectionProbeBox,
EditMode.SceneViewEditMode.GridBox,
EditMode.SceneViewEditMode.Collider,
EditMode.SceneViewEditMode.ReflectionProbeOrigin
};
static GUIContent[] s_Toolbar_Contents = null;
static GUIContent[] toolbar_Contents
{
get
{
return s_Toolbar_Contents ?? (s_Toolbar_Contents = new []
{
EditorGUIUtility.IconContent("d_EditCollider", "|Modify the influence volume of the reflection probe."),
EditorGUIUtility.IconContent("d_PreMatCube", "|Modify the projection volume of the reflection probe."),
EditorGUIUtility.IconContent("d_Navigation", "|Fit the reflection probe volume to the surrounding colliders."),
EditorGUIUtility.IconContent("MoveTool", "|Move the selected objects.")
});
}
}
const string k_BaseSceneEditingToolText = "<color=grey>Probe Scene Editing Mode:</color> \n";
static readonly GUIContent[] k_ToolNames =
{
new GUIContent(k_BaseSceneEditingToolText + "Box Influence Bounds", ""),
new GUIContent(k_BaseSceneEditingToolText + "Box Projection Bounds", ""),
new GUIContent(k_BaseSceneEditingToolText + "Fit Projection Volume", ""),
new GUIContent(k_BaseSceneEditingToolText + "Probe Origin", "")
};
static readonly Bounds k_BoundsZero = new Bounds();
static Bounds DummyBound() { return k_BoundsZero; }
static Editor s_LastInteractedEditor = null;
static void Drawer_Toolbar(UIState s, SerializedReflectionProbe p, Editor owner)
{
if (p.so.targetObjects.Length > 1)
return;
// Show the master tool selector
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.changed = false;
var oldEditMode = EditMode.editMode;
EditorGUI.BeginChangeCheck();
EditMode.DoInspectorToolbar(k_Toolbar_SceneViewEditModes, toolbar_Contents, DummyBound, owner);
if (EditorGUI.EndChangeCheck())
s_LastInteractedEditor = owner;
if (oldEditMode != EditMode.editMode)
{
switch (EditMode.editMode)
{
case EditMode.SceneViewEditMode.ReflectionProbeOrigin:
s.shouldUpdateOldLocalSpace = true;
break;
}
// HDRP if (Toolbar.get != null)
// HDRP Toolbar.get.Repaint();
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
// Info box for tools
GUILayout.BeginHorizontal();
GUILayout.Space(EditorGUIUtility.labelWidth);
GUILayout.BeginVertical(EditorStyles.helpBox);
var helpText = k_BaseSceneEditingToolText;
if (s.sceneViewEditing)
{
var index = ArrayUtility.IndexOf(k_Toolbar_SceneViewEditModes, EditMode.editMode);
if (index >= 0)
helpText = k_ToolNames[index].text;
}
GUILayout.Label(helpText, EditorStyles.miniLabel);
GUILayout.EndVertical();
GUILayout.Space(EditorGUIUtility.fieldWidth);
GUILayout.EndHorizontal();
}
#endregion
#region Mode Specific Settings
static void Drawer_ModeSettings(UIState s, SerializedReflectionProbe p, Editor owner)
{
for (var i = 0; i < k_ModeDrawers.Length; ++i)
{
if (EditorGUILayout.BeginFadeGroup(s.GetModeFaded((ReflectionProbeMode)i)))
{
++EditorGUI.indentLevel;
k_ModeDrawers[i](s, p, owner);
--EditorGUI.indentLevel;
}
EditorGUILayout.EndFadeGroup();
}
}
static readonly Drawer[] k_ModeDrawers = { Drawer_NOOP, Drawer_ModeSettingsRealtime , Drawer_ModeSettingsCustom };
static void Drawer_ModeSettingsCustom(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.PropertyField(p.renderDynamicObjects, CoreEditorUtils.GetContent("Dynamic Objects|If enabled dynamic objects are also rendered into the cubemap"));
p.customBakedTexture.objectReferenceValue = EditorGUILayout.ObjectField(CoreEditorUtils.GetContent("Cubemap"), p.customBakedTexture.objectReferenceValue, typeof(Cubemap), false);
}
static void Drawer_ModeSettingsRealtime(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.PropertyField(p.refreshMode, CoreEditorUtils.GetContent("Refresh Mode|Controls how this probe refreshes in the Player"));
EditorGUILayout.PropertyField(p.timeSlicingMode, CoreEditorUtils.GetContent("Time Slicing|If enabled this probe will update over several frames, to help reduce the impact on the frame rate"));
}
#endregion
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs.meta


fileFormatVersion: 2
guid: 4b3481acd0445e340a0737660cab9226
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存