Skip to content
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
1 change: 1 addition & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- Fixed missing warning UI about Projector component being unsupported (case 1300327).
- Fixed the display name of a Volume Parameter when is defined the attribute InspectorName

### Added
- Support for the PlayStation 5 platform has been added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Rendering;
using UnityEditor.AnimatedValues;

namespace UnityEditor.Rendering
{
Expand Down Expand Up @@ -350,7 +350,7 @@ public virtual void OnInspectorGUI()
// Display every field as-is
foreach (var parameter in m_Parameters)
{
if (parameter.displayName.text != "")
if (!string.IsNullOrEmpty(parameter.displayName.text))
PropertyField(parameter.param, parameter.displayName);
else
PropertyField(parameter.param);
Expand Down Expand Up @@ -457,36 +457,50 @@ protected void PropertyField(SerializedDataParameter property)
}

/// <summary>
/// Draws a given <see cref="SerializedDataParameter"/> in the editor using a custom label
/// and tooltip.
/// Handles unity built-in decorators (Space, Header, Tooltips, ...) from <see cref="SerializedDataParameter"/> attributes
/// </summary>
/// <param name="property">The property to draw in the editor.</param>
/// <param name="title">A custom label and/or tooltip.</param>
protected void PropertyField(SerializedDataParameter property, GUIContent title)
/// <param name="property">The property to obtain the attributes and handle the decorators</param>
/// <param name="title">A custom label and/or tooltip that might be updated by <see cref="TooltipAttribute"/> and/or by <see cref="InspectorNameAttribute"/></param>
void HandleDecorators(SerializedDataParameter property, GUIContent title)
{
// Handle unity built-in decorators (Space, Header, Tooltip etc)
foreach (var attr in property.attributes)
{
if (attr is PropertyAttribute)
if (!(attr is PropertyAttribute))
continue;

switch (attr)
{
if (attr is SpaceAttribute)
{
EditorGUILayout.GetControlRect(false, (attr as SpaceAttribute).height);
}
else if (attr is HeaderAttribute)
case SpaceAttribute spaceAttribute:
EditorGUILayout.GetControlRect(false, spaceAttribute.height);
break;
case HeaderAttribute headerAttribute:
{
var rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
rect.y += 0f;
rect = EditorGUI.IndentedRect(rect);
EditorGUI.LabelField(rect, (attr as HeaderAttribute).header, EditorStyles.miniLabel);
var rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight));
EditorGUI.LabelField(rect, headerAttribute.header, EditorStyles.miniLabel);
break;
}
else if (attr is TooltipAttribute)
case TooltipAttribute tooltipAttribute:
{
if (string.IsNullOrEmpty(title.tooltip))
title.tooltip = (attr as TooltipAttribute).tooltip;
title.tooltip = tooltipAttribute.tooltip;
break;
}
case InspectorNameAttribute inspectorNameAttribute:
title.text = inspectorNameAttribute.displayName;
break;
}
}
}

/// <summary>
/// Draws a given <see cref="SerializedDataParameter"/> in the editor using a custom label
/// and tooltip.
/// </summary>
/// <param name="property">The property to draw in the editor.</param>
/// <param name="title">A custom label and/or tooltip.</param>
protected void PropertyField(SerializedDataParameter property, GUIContent title)
{
HandleDecorators(property, title);

// Custom parameter drawer
VolumeParameterDrawer drawer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,55 @@ public string[] AdditionalProperties(Type volumeComponentType)

return fields;
}

#region Decorators Handling Test

class VolumeComponentDecorators : VolumeComponent
{
[Tooltip("Increase to make the noise texture appear bigger and less")]
public FloatParameter _NoiseTileSize = new FloatParameter(25.0f);

[InspectorName("Color")]
public ColorParameter _FogColor = new ColorParameter(Color.grey);

[InspectorName("Size and occurrence"), Tooltip("Increase to make patches SMALLER, and frequent")]
public ClampedFloatParameter _HighNoiseSpaceFreq = new ClampedFloatParameter(0.1f, 0.1f, 1f);
}

readonly (string displayName, string tooltip)[] k_ExpectedResults =
{
(string.Empty, "Increase to make the noise texture appear bigger and less"),
("Color", string.Empty),
("Size and occurrence", "Increase to make patches SMALLER, and frequent")
};

[Test]
public void TestHandleParameterDecorators()
{
var component = ScriptableObject.CreateInstance<VolumeComponentDecorators>();
var editor = (VolumeComponentEditor)Activator.CreateInstance(typeof(VolumeComponentEditor));
editor.Invoke("Init", component, null);

var parameters =
editor.GetField("m_Parameters") as List<(GUIContent displayName, int displayOrder,
SerializedDataParameter param)>;

Assert.True(parameters != null && parameters.Count() == k_ExpectedResults.Count());

for (int i = 0; i < k_ExpectedResults.Count(); ++i)
{
var property = parameters[i].param;
var title = new GUIContent(parameters[i].displayName);

editor.Invoke("HandleDecorators", property, title);

Assert.True(k_ExpectedResults[i].displayName == title.text);
Assert.True(k_ExpectedResults[i].tooltip == title.tooltip);
}

ScriptableObject.DestroyImmediate(component);
}

#endregion
}
}