Skip to content

DisplayInfo attribute. #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public VolumeComponentEditorAttribute(Type componentType)
}

/// <summary>
/// A custom editor class that draws a <see cref="VolumeComponent"/> in the Inspector. If you do not
/// A custom editor class that draws a <see cref="VolumeComponent"/> in the Inspector. If you do not
/// provide a custom editor for a <see cref="VolumeComponent"/>, Unity uses the default one.
/// You must use a <see cref="VolumeComponentEditorAttribute"/> to let the editor know which
/// component this drawer is for.
Expand All @@ -43,7 +43,7 @@ public VolumeComponentEditorAttribute(Type componentType)
/// Below is an example of a custom <see cref="VolumeComponent"/>:
/// <code>
/// using UnityEngine.Rendering;
///
///
/// [Serializable, VolumeComponentMenu("Custom/Example Component")]
/// public class ExampleComponent : VolumeComponent
/// {
Expand All @@ -53,18 +53,18 @@ public VolumeComponentEditorAttribute(Type componentType)
/// And its associated editor:
/// <code>
/// using UnityEditor.Rendering;
///
///
/// [VolumeComponentEditor(typeof(ExampleComponent))]
/// class ExampleComponentEditor : VolumeComponentEditor
/// {
/// SerializedDataParameter m_Intensity;
///
///
/// public override void OnEnable()
/// {
/// var o = new PropertyFetcher&lt;ExampleComponent&gt;(serializedObject);
/// m_Intensity = Unpack(o.Find(x => x.intensity));
/// }
///
///
/// public override void OnInspectorGUI()
/// {
/// PropertyField(m_Intensity);
Expand Down Expand Up @@ -125,7 +125,7 @@ internal set
/// </summary>
protected Editor m_Inspector;

List<SerializedDataParameter> m_Parameters;
List<(GUIContent displayName, int displayOrder, SerializedDataParameter param)> m_Parameters;

static Dictionary<Type, VolumeParameterDrawer> s_ParameterDrawers;

Expand Down Expand Up @@ -179,6 +179,20 @@ internal void Init(VolumeComponent target, Editor inspector)
OnEnable();
}


class ParameterSorter : Comparer<(GUIContent displayName, int displayOrder, SerializedDataParameter param)>
{
public override int Compare((GUIContent displayName, int displayOrder, SerializedDataParameter param) x, (GUIContent displayName, int displayOrder, SerializedDataParameter param) y)
{
if (x.displayOrder < y.displayOrder)
return -1;
else if (x.displayOrder == y.displayOrder)
return 0;
else
return 1;
}
}

/// <summary>
/// Unity calls this method when the object loads.
/// </summary>
Expand All @@ -188,7 +202,7 @@ internal void Init(VolumeComponent target, Editor inspector)
/// </remarks>
public virtual void OnEnable()
{
m_Parameters = new List<SerializedDataParameter>();
m_Parameters = new List<(GUIContent, int, SerializedDataParameter)>();

// Grab all valid serializable field on the VolumeComponent
// TODO: Should only be done when needed / on demand as this can potentially be wasted CPU when a custom editor is in use
Expand All @@ -206,9 +220,19 @@ public virtual void OnEnable()
foreach (var field in fields)
{
var property = serializedObject.FindProperty(field.Name);
var name = "";
var order = 0;
var attr = (DisplayInfoAttribute[])field.GetCustomAttributes(typeof(DisplayInfoAttribute), true);
if (attr.Length != 0)
{
name = attr[0].name;
order = attr[0].order;
}

var parameter = new SerializedDataParameter(property);
m_Parameters.Add(parameter);
m_Parameters.Add((new GUIContent(name), order, parameter));
}
m_Parameters.Sort(new ParameterSorter());
}

/// <summary>
Expand Down Expand Up @@ -239,7 +263,12 @@ public virtual void OnInspectorGUI()
{
// Display every field as-is
foreach (var parameter in m_Parameters)
PropertyField(parameter);
{
if (parameter.displayName.text != "")
PropertyField(parameter.param, parameter.displayName);
else
PropertyField(parameter.param);
}
}

/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions com.unity.render-pipelines.core/Runtime/Common/CoreAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace UnityEngine.Rendering
{
/// <summary>
/// Attribute used to customize UI display.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class DisplayInfoAttribute : Attribute
{
/// <summary>Display name used in UI.</summary>
public string name;
/// <summary>Display order used in UI.</summary>
public int order;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added scenes for hair and fabric and decals with material samples
- Added fabric materials and textures
- Added information for fabric materials in fabric scene
- Added a DisplayInfo attribute to specify a name override and a display order for Volume Component fields (used only in default inspector for now).

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,20 @@ DebugUI.Widget makeWidget(string name, VolumeParameter param)
// One row per parameter
foreach (var f in fields)
{
var fieldName = f.Name;
var attr = (DisplayInfoAttribute[])f.GetCustomAttributes(typeof(DisplayInfoAttribute), true);
if (attr.Length != 0)
fieldName = attr[0].name;
#if UNITY_EDITOR
// Would be nice to have the equivalent for the runtime debug.
else
fieldName = UnityEditor.ObjectNames.NicifyVariableName(fieldName);
#endif


row = new DebugUI.Table.Row()
{
displayName = f.Name,
displayName = fieldName,
children = { makeWidget("Interpolated Value", data.volumeDebugSettings.GetParameter(f)) }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ public class Fog : VolumeComponent
{
/// <summary>Enable fog.</summary>
[Tooltip("Enables the fog.")]
public BoolParameter enabled = new BoolParameter(false);
public BoolParameter enabled = new BoolParameter(false);

/// <summary>Fog color mode.</summary>
public FogColorParameter colorMode = new FogColorParameter(FogColorMode.SkyColor);
public FogColorParameter colorMode = new FogColorParameter(FogColorMode.SkyColor);
/// <summary>Fog color.</summary>
[Tooltip("Specifies the constant color of the fog.")]
public ColorParameter color = new ColorParameter(Color.grey, hdr: true, showAlpha: false, showEyeDropper: true);
public ColorParameter color = new ColorParameter(Color.grey, hdr: true, showAlpha: false, showEyeDropper: true);
/// <summary>Specifies the tint of the fog when using Sky Color.</summary>
[Tooltip("Specifies the tint of the fog.")]
public ColorParameter tint = new ColorParameter(Color.white, hdr: true, showAlpha: false, showEyeDropper: true);
public ColorParameter tint = new ColorParameter(Color.white, hdr: true, showAlpha: false, showEyeDropper: true);
/// <summary>Maximum fog distance.</summary>
[Tooltip("Sets the maximum fog distance HDRP uses when it shades the skybox or the Far Clipping Plane of the Camera.")]
public MinFloatParameter maxFogDistance = new MinFloatParameter(5000.0f, 0.0f);
public MinFloatParameter maxFogDistance = new MinFloatParameter(5000.0f, 0.0f);
/// <summary>Controls the maximum mip map HDRP uses for mip fog (0 is the lowest mip and 1 is the highest mip).</summary>
[Tooltip("Controls the maximum mip map HDRP uses for mip fog (0 is the lowest mip and 1 is the highest mip).")]
public ClampedFloatParameter mipFogMaxMip = new ClampedFloatParameter(0.5f, 0.0f, 1.0f);
/// <summary>Sets the distance at which HDRP uses the minimum mip image of the blurred sky texture as the fog color.</summary>
[Tooltip("Sets the distance at which HDRP uses the minimum mip image of the blurred sky texture as the fog color.")]
public MinFloatParameter mipFogNear = new MinFloatParameter(0.0f, 0.0f);
public MinFloatParameter mipFogNear = new MinFloatParameter(0.0f, 0.0f);
/// <summary>Sets the distance at which HDRP uses the maximum mip image of the blurred sky texture as the fog color.</summary>
[Tooltip("Sets the distance at which HDRP uses the maximum mip image of the blurred sky texture as the fog color.")]
public MinFloatParameter mipFogFar = new MinFloatParameter(1000.0f, 0.0f);
public MinFloatParameter mipFogFar = new MinFloatParameter(1000.0f, 0.0f);

// Height Fog
/// <summary>Height fog base height.</summary>
Expand All @@ -44,14 +44,17 @@ public class Fog : VolumeComponent
/// <summary>Fog albedo.</summary>
public ColorParameter albedo = new ColorParameter(Color.white);
/// <summary>Fog mean free path.</summary>
[DisplayInfo(name = "Fog Attenuation Distance")]
public MinFloatParameter meanFreePath = new MinFloatParameter(400.0f, 1.0f);

// Optional Volumetric Fog
/// <summary>Enable volumetric fog.</summary>
[DisplayInfo(name = "Volumetric Fog")]
public BoolParameter enableVolumetricFog = new BoolParameter(false);
/// <summary>Volumetric fog anisotropy.</summary>
public ClampedFloatParameter anisotropy = new ClampedFloatParameter(0.0f, -1.0f, 1.0f);
/// <summary>Multiplier for ambient probe contribution.</summary>
[DisplayInfo(name = "Ambient Light Probe Dimmer")]
public ClampedFloatParameter globalLightProbeDimmer = new ClampedFloatParameter(1.0f, 0.0f, 1.0f);

/// <summary>Sets the distance (in meters) from the Camera's Near Clipping Plane to the back of the Camera's volumetric lighting buffer.</summary>
Expand Down