浏览代码

Added drawers

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
d9fa2f6c
共有 6 个文件被更改,包括 301 次插入77 次删除
  1. 15
      ScriptableRenderPipeline/Core/Editor/PropertyFetcher.cs
  2. 71
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  3. 133
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  4. 48
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  5. 100
      ScriptableRenderPipeline/Core/Editor/CoreEditorDrawers.cs
  6. 11
      ScriptableRenderPipeline/Core/Editor/CoreEditorDrawers.cs.meta

15
ScriptableRenderPipeline/Core/Editor/PropertyFetcher.cs


// Nothing to do here, still needed so we can rely on the using/IDisposable pattern
}
}
public static class PropertyFetcherExtensions
{
public static SerializedProperty Find<TSource, TValue>(this SerializedObject obj, Expression<Func<TSource, TValue>> expr)
{
var path = CoreEditorUtils.FindProperty(expr);
return obj.FindProperty(path);
}
public static SerializedProperty Find<TSource, TValue>(this SerializedProperty obj, Expression<Func<TSource, TValue>> expr)
{
var path = CoreEditorUtils.FindProperty(expr);
return obj.FindPropertyRelative(path);
}
}
}

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


using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
namespace UnityEditor
namespace UnityEditor.Experimental.Rendering
class SerializedReflectionProbe
internal class SerializedReflectionProbe
{
internal SerializedObject so;

internal SerializedProperty refreshMode;
internal SerializedProperty timeSlicingMode;
internal SerializedProperty intensityMultiplier;
internal SerializedProperty blendDistance;
internal SerializedProperty boxSize;
internal SerializedProperty boxOffset;
internal SerializedProperty influenceSphereRadius;
internal SerializedProperty useSeparateProjectionVolume;
var o = new PropertyFetcher<HDAdditionalReflectionData>(addso);
this.so = so;
mode = so.FindProperty("m_Mode");

timeSlicingMode = so.FindProperty("m_TimeSlicingMode");
intensityMultiplier = so.FindProperty("m_IntensityMultiplier");
intensityMultiplier = so.FindProperty("m_IntensityMultiplier");
blendDistance = so.FindProperty("m_BlendDistance");
boxSize = so.FindProperty("m_BoxSize");
boxOffset = so.FindProperty("m_BoxOffset");
influenceShape = o.Find(d => d.m_InfluenceShape);
influenceShape = addso.Find((HDAdditionalReflectionData d) => d.m_InfluenceShape);
influenceSphereRadius = addso.Find((HDAdditionalReflectionData d) => d.m_InfluenceSphereRadius);
useSeparateProjectionVolume = addso.Find((HDAdditionalReflectionData d) => d.m_UseSeparateProjectionVolume);
class UIState
[Flags]
internal enum Operation
{
None = 0,
UpdateOldLocalSpace = 1 << 0,
FitVolumeToSurroundings = 1 << 1
}
internal class UIState
AnimBool[] m_InfluenceShapeDisplays = new AnimBool[Enum.GetValues(typeof(ReflectionInfluenceShape)).Length];
Operation operations { get; set; }
public bool shouldUpdateOldLocalSpace { get; set; }
public bool HasOperation(Operation op) { return (operations & op) == op; }
public void ClearOperation(Operation op) { operations &= ~op; }
public void AddOperation(Operation op) { operations |= op; }
public bool HasAndClearOperation(Operation op)
{
var has = HasOperation(op);
ClearOperation(op);
return has;
}
public bool sceneViewEditing
{

{
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
m_ModeSettingsDisplays[i] = new AnimBool();
for (var i = 0; i < m_InfluenceShapeDisplays.Length; i++)
m_InfluenceShapeDisplays[i] = new AnimBool();
internal void Reset(Editor owner, UnityAction repaint, int modeValue)
internal void Reset(Editor owner, UnityAction repaint, int modeValue, int shapeValue)
shouldUpdateOldLocalSpace = false;
operations = 0;
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++)
{

}
for (var i = 0; i < m_InfluenceShapeDisplays.Length; i++)
{
m_InfluenceShapeDisplays[i].valueChanged.RemoveAllListeners();
m_InfluenceShapeDisplays[i].valueChanged.AddListener(repaint);
m_InfluenceShapeDisplays[i].value = shapeValue == i;
}
}
public float GetModeFaded(ReflectionProbeMode mode)

m_ModeSettingsDisplays[i].target = i == value;
}
public float GetShapeFaded(ReflectionInfluenceShape value)
{
return m_InfluenceShapeDisplays[(int)value].faded;
}
public void SetShapeTarget(int value)
{
for (var i = 0; i < m_InfluenceShapeDisplays.Length; i++)
m_InfluenceShapeDisplays[i].target = i == value;
}
static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode)
{
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||

delegate void Drawer(UIState s, SerializedReflectionProbe p, Editor owner);
}
}

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


using UnityEditor.Experimental.Rendering;
using UnityEditorInternal;
using UnityEditorInternal;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor
namespace UnityEditor.Experimental.Rendering
using CED = CoreEditorDrawer<HDReflectionProbeEditor.UIState, HDReflectionProbeEditor.SerializedReflectionProbe>;
static readonly CED.IDrawer k_Drawer_Space = CED.Action(Drawer_Space);
static readonly CED.IDrawer k_Drawer_NOOP = CED.Action(Drawer_NOOP);
static void Drawer_Space(UIState s, SerializedReflectionProbe p, Editor owner) { EditorGUILayout.Space(); }
#region Sections
static readonly CED.IDrawer k_InfluenceVolumeSection = CED.FoldoutGroup(
"Influence volume settings",
(s, p, o) => p.blendDistance,
CED.FadeGroup(
(s, p, o, i) => s.GetShapeFaded((ReflectionInfluenceShape)i),
CED.Action(Drawer_InfluenceBoxSettings), // Box
CED.Action(Drawer_InfluenceSphereSettings) // Sphere
),
CED.Action(Drawer_UseSeparateProjectionVolume)
);
static readonly CED.IDrawer[] k_PrimarySection =
{
CED.Action(Drawer_ReflectionProbeMode),
CED.FadeGroup((s, p, o, i) => s.GetModeFaded((ReflectionProbeMode)i),
k_Drawer_NOOP, // Baked
CED.Action(Drawer_ModeSettingsRealtime), // Realtime
CED.Action(Drawer_ModeSettingsCustom) // Custom
),
k_Drawer_Space,
CED.Action(Drawer_InfluenceShape),
CED.Action(Drawer_IntensityMultiplier),
k_Drawer_Space,
CED.Action(Drawer_Toolbar),
k_Drawer_Space
};
void Draw(CED.IDrawer[] drawers, UIState s, SerializedReflectionProbe p, Editor owner)
{
for (var i = 0; i < drawers.Length; i++)
drawers[i].Draw(s, p, owner);
}
#endregion
static void Drawer_InfluenceBoxSettings(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(p.boxSize, CoreEditorUtils.GetContent("Box Size|The size of the box in which the reflections will be applied to objects. The value is not affected by the Transform of the Game Object."));
EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Box Offset|The center of the box in which the reflections will be applied to objects. The value is relative to the position of the Game Object."));
if (EditorGUI.EndChangeCheck())
{
var center = p.boxSize.vector3Value;
var size = p.boxOffset.vector3Value;
if (ValidateAABB((ReflectionProbe)p.so.targetObject, ref center, ref size))
{
p.boxOffset.vector3Value = center;
p.boxSize.vector3Value = size;
}
}
}
static void Drawer_InfluenceSphereSettings(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.PropertyField(p.influenceSphereRadius, CoreEditorUtils.GetContent("Radius"));
}
static void Drawer_UseSeparateProjectionVolume(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.PropertyField(p.useSeparateProjectionVolume);
}
#region Field Drawers
static readonly GUIContent[] k_Content_ReflectionProbeMode = { new GUIContent("Baked"), new GUIContent("Custom"), new GUIContent("Realtime") };

static void Drawer_InfluenceShape(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = p.influenceShape.hasMultipleDifferentValues;
EditorGUI.showMixedValue = false;
if (EditorGUI.EndChangeCheck())
s.SetShapeTarget(p.influenceShape.intValue);
}
static void Drawer_IntensityMultiplier(UIState s, SerializedReflectionProbe p, Editor owner)

{
EditMode.SceneViewEditMode.ReflectionProbeBox,
EditMode.SceneViewEditMode.GridBox,
EditMode.SceneViewEditMode.Collider,
EditMode.SceneViewEditMode.ReflectionProbeOrigin
};
static GUIContent[] s_Toolbar_Contents = null;

{
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("EditCollider", "|Modify the influence volume of the reflection probe."),
EditorGUIUtility.IconContent("PreMatCube", "|Modify the projection volume of the reflection probe."),
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;

if (EditorGUI.EndChangeCheck())
s_LastInteractedEditor = owner;
if (GUILayout.Button(EditorGUIUtility.IconContent("Navigation", "|Fit the reflection probe volume to the surrounding colliders.")))
s.AddOperation(Operation.FitVolumeToSurroundings);
s.shouldUpdateOldLocalSpace = true;
s.AddOperation(Operation.UpdateOldLocalSpace);
// HDRP if (Toolbar.get != null)
// HDRP Toolbar.get.Repaint();
// 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();
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"));

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


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor
namespace UnityEditor.Experimental.Rendering
{
[CustomEditorForRenderPipeline(typeof(ReflectionProbe), typeof(HDRenderPipelineAsset))]
[CanEditMultipleObjects]

var additionalData = CoreEditorUtils.GetAdditionalData<HDAdditionalReflectionData>(targets);
m_AdditionalDataSerializedObject = new SerializedObject(additionalData);
m_SerializedReflectionProbe = new SerializedReflectionProbe(serializedObject, m_AdditionalDataSerializedObject);
m_UIState.Reset(this, Repaint, m_SerializedReflectionProbe.mode.intValue);
m_UIState.Reset(
this,
Repaint,
m_SerializedReflectionProbe.mode.intValue,
m_SerializedReflectionProbe.influenceShape.intValue);
}
public override void OnInspectorGUI()

var s = m_UIState;
var p = m_SerializedReflectionProbe;
Drawer_ReflectionProbeMode(s, p, this);
Drawer_ModeSettings(s, p, this);
EditorGUILayout.Space();
Drawer_InfluenceShape(s, p, this);
Drawer_IntensityMultiplier(s, p, this);
Drawer_Toolbar(s, p, this);
Draw(k_PrimarySection, s, p, this);
k_InfluenceVolumeSection.Draw(s, p, this);
if (s.shouldUpdateOldLocalSpace)
{
s.shouldUpdateOldLocalSpace = false;
UpdateOldLocalSpace();
}
PerformOperations(s, p, this);
void PerformOperations(UIState s, SerializedReflectionProbe p, HDReflectionProbeEditor o)
{
if (s.HasAndClearOperation(Operation.UpdateOldLocalSpace))
UpdateOldLocalSpace();
}
void UpdateOldLocalSpace()
{

return probe.transform.rotation;
else
return Quaternion.identity;
}
// Ensures that probe's AABB encapsulates probe's position
// Returns true, if center or size was modified
static bool ValidateAABB(ReflectionProbe p, ref Vector3 center, ref Vector3 size)
{
var localSpace = GetLocalSpace(p);
var localTransformPosition = localSpace.inverse.MultiplyPoint3x4(p.transform.position);
var b = new Bounds(center, size);
if (b.Contains(localTransformPosition))
return false;
b.Encapsulate(localTransformPosition);
center = b.center;
size = b.size;
return true;
}
}
}

100
ScriptableRenderPipeline/Core/Editor/CoreEditorDrawers.cs


namespace UnityEditor.Experimental.Rendering
{
public static class CoreEditorDrawer<TUIState, TData>
{
public interface IDrawer
{
void Draw(TUIState s, TData p, Editor owner);
}
public delegate void ActionDrawer(TUIState s, TData p, Editor owner);
public delegate float FloatGetter(TUIState s, TData p, Editor owner, int i);
public delegate SerializedProperty SerializedPropertyGetter(TUIState s, TData p, Editor o);
public static IDrawer Action(params ActionDrawer[] drawers)
{
return new ActionDrawerInternal(drawers);
}
public static IDrawer FadeGroup(FloatGetter fadeGetter, params IDrawer[] groupDrawers)
{
return new FadeGroupsDrawerInternal(fadeGetter, groupDrawers);
}
public static IDrawer FoldoutGroup(string title, SerializedPropertyGetter root, params IDrawer[] bodies)
{
return new FoldoutDrawerInternal(title, root, bodies);
}
class ActionDrawerInternal : IDrawer
{
ActionDrawer[] actionDrawers { get; set; }
public ActionDrawerInternal(params ActionDrawer[] actionDrawers)
{
this.actionDrawers = actionDrawers;
}
void IDrawer.Draw(TUIState s, TData p, Editor owner)
{
for (var i = 0; i < actionDrawers.Length; i++)
actionDrawers[i](s, p, owner);
}
}
class FadeGroupsDrawerInternal : IDrawer
{
IDrawer[] groupDrawers;
FloatGetter getter;
public FadeGroupsDrawerInternal(FloatGetter getter, params IDrawer[] groupDrawers)
{
this.groupDrawers = groupDrawers;
this.getter = getter;
}
void IDrawer.Draw(TUIState s, TData p, Editor owner)
{
for (var i = 0; i < groupDrawers.Length; ++i)
{
if (EditorGUILayout.BeginFadeGroup(getter(s, p, owner, i)))
{
++EditorGUI.indentLevel;
groupDrawers[i].Draw(s, p, owner);
--EditorGUI.indentLevel;
}
EditorGUILayout.EndFadeGroup();
}
}
}
class FoldoutDrawerInternal : IDrawer
{
IDrawer[] bodies;
SerializedPropertyGetter root;
string title;
public FoldoutDrawerInternal(string title, SerializedPropertyGetter root, params IDrawer[] bodies)
{
this.title = title;
this.root = root;
this.bodies = bodies;
}
public void Draw(TUIState s, TData p, Editor owner)
{
var r = root(s, p, owner);
CoreEditorUtils.DrawSplitter();
r.isExpanded = CoreEditorUtils.DrawHeaderFoldout(title, r.isExpanded);
if (r.isExpanded)
{
++EditorGUI.indentLevel;
for (var i = 0; i < bodies.Length; i++)
bodies[i].Draw(s, p, owner);
--EditorGUI.indentLevel;
}
}
}
}
}

11
ScriptableRenderPipeline/Core/Editor/CoreEditorDrawers.cs.meta


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