Skip to content
Closed
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
124 changes: 113 additions & 11 deletions com.unity.render-pipelines.core/Editor/CoreEditorDrawers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,11 @@ class FoldoutGroupDrawerInternal<TEnum, TState> : IDrawer
readonly Enabler m_Enabler;
readonly SwitchEnabler m_SwitchEnabler;

readonly Action<Vector2> m_contextAction;
readonly Action<GenericMenu> m_additionalMenuAction;

public FoldoutGroupDrawerInternal(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state,
Enabler enabler, SwitchEnabler switchEnabler, FoldoutOption options = FoldoutOption.None, params ActionDrawer[] actionDrawers)
Enabler enabler, SwitchEnabler switchEnabler, FoldoutOption options = FoldoutOption.None, Action<Vector2> contextAction = null, Action<GenericMenu> additionalMenuAction = null, params ActionDrawer[] actionDrawers)
{
m_IsBoxed = (options & FoldoutOption.Boxed) != 0;
m_IsIndented = (options & FoldoutOption.Indent) != 0;
Expand All @@ -439,6 +442,9 @@ public FoldoutGroupDrawerInternal(GUIContent title, TEnum mask, ExpandedState<TE

m_Enabler = enabler;
m_SwitchEnabler = switchEnabler;

m_contextAction = contextAction;
m_additionalMenuAction = additionalMenuAction;
}

void IDrawer.Draw(TData data, Editor owner)
Expand All @@ -458,7 +464,9 @@ void IDrawer.Draw(TData data, Editor owner)
m_IsBoxed,
m_Enabler == null ? (Func<bool>)null : () => m_Enabler(data, owner),
m_SwitchEnabler == null ? (Action)null : () => m_SwitchEnabler(data, owner),
m_HelpUrl);
m_HelpUrl,
m_contextAction,
m_additionalMenuAction);
}
if (newExpended ^ expended)
m_State[m_Mask] = newExpended;
Expand Down Expand Up @@ -594,7 +602,39 @@ public static IDrawer FoldoutGroup<TEnum, TState>(string title, TEnum mask, Expa
public static IDrawer FoldoutGroup<TEnum, TState>(string title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, params ActionDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(EditorGUIUtility.TrTextContent(title), mask, state, options, contentDrawers);
return FoldoutGroup(EditorGUIUtility.TrTextContent(title), mask, state, options, null, contentDrawers);
}

/// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
/// <typeparam name="TEnum">Type of the mask used</typeparam>
/// <typeparam name="TState">Type of the persistent state</typeparam>
/// <param name="title">Title wanted for this foldout header</param>
/// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
/// <param name="state">The ExpandedState describing the component</param>
/// <param name="options">Drawing options</param>
/// <param name="contextAction">The delegate of the fouldout header's burger menu</param>
/// <param name="contentDrawers">The content of the foldout header</param>
/// <returns>A IDrawer object</returns>
public static IDrawer FoldoutGroup<TEnum, TState>(string title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, Action<Vector2> contextAction, params IDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(title, mask, state, options, contextAction, contentDrawers.Draw);
}

/// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
/// <typeparam name="TEnum">Type of the mask used</typeparam>
/// <typeparam name="TState">Type of the persistent state</typeparam>
/// <param name="title">Title wanted for this foldout header</param>
/// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
/// <param name="state">The ExpandedState describing the component</param>
/// <param name="options">Drawing options</param>
/// <param name="contextAction">The delegate of the fouldout header's burger menu</param>
/// <param name="contentDrawers">The content of the foldout header</param>
/// <returns>A IDrawer object</returns>
public static IDrawer FoldoutGroup<TEnum, TState>(string title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, Action<Vector2> contextAction, params ActionDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(EditorGUIUtility.TrTextContent(title), mask, state, options, contextAction, contentDrawers);
}

/// <summary>
Expand Down Expand Up @@ -628,7 +668,7 @@ public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask,
public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state, params ActionDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(title, mask, state, FoldoutOption.Indent, contentDrawers);
return FoldoutGroup(title, mask, state, FoldoutOption.Indent, null, contentDrawers);
}

/// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
Expand All @@ -643,7 +683,7 @@ public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask,
public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, params IDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(title, mask, state, options, contentDrawers.Draw);
return FoldoutGroup(title, mask, state, options, (Action<Vector2>)null, contentDrawers.Draw);
}

/// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
Expand All @@ -653,19 +693,53 @@ public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask,
/// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
/// <param name="state">The ExpandedState describing the component</param>
/// <param name="options">Drawing options</param>
/// <param name="contextAction">The delegate of the fouldout header's burger menu</param>
/// <param name="contentDrawers">The content of the foldout header</param>
/// <returns>A IDrawer object</returns>
public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, params ActionDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(title, mask, state, options, null, null, contentDrawers);
return FoldoutGroup(title, mask, state, options, null, null, null, null, contentDrawers);
}

/// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
/// <typeparam name="TEnum">Type of the mask used</typeparam>
/// <typeparam name="TState">Type of the persistent state</typeparam>
/// <param name="title">Title wanted for this foldout header</param>
/// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
/// <param name="state">The ExpandedState describing the component</param>
/// <param name="options">Drawing options</param>
/// <param name="contextAction">The delegate of the fouldout header's burger menu</param>
/// <param name="contentDrawers">The content of the foldout header</param>
/// <returns>A IDrawer object</returns>
public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, Action<Vector2> contextAction, params IDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(title, mask, state, options, contextAction, contentDrawers.Draw);
}

/// <summary> Create an IDrawer foldout header using an ExpandedState </summary>
/// <typeparam name="TEnum">Type of the mask used</typeparam>
/// <typeparam name="TState">Type of the persistent state</typeparam>
/// <param name="title">Title wanted for this foldout header</param>
/// <param name="mask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
/// <param name="state">The ExpandedState describing the component</param>
/// <param name="options">Drawing options</param>
/// <param name="contextAction">The delegate of the fouldout header's burger menu</param>
/// <param name="contentDrawers">The content of the foldout header</param>
/// <returns>A IDrawer object</returns>
public static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, Action<Vector2> contextAction, params ActionDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return FoldoutGroup(title, mask, state, options, null, null, contextAction, null, contentDrawers);
}

// This one is private as we do not want to have unhandled advanced switch. Change it if necessary.
static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, Enabler showAdditionalProperties, SwitchEnabler switchAdditionalProperties, params ActionDrawer[] contentDrawers)
static IDrawer FoldoutGroup<TEnum, TState>(GUIContent title, TEnum mask, ExpandedState<TEnum, TState> state, FoldoutOption options, Enabler showAdditionalProperties,
SwitchEnabler switchAdditionalProperties, Action<Vector2> contextAction, Action<GenericMenu> additionalMenuAction, params ActionDrawer[] contentDrawers)
where TEnum : struct, IConvertible
{
return new FoldoutGroupDrawerInternal<TEnum, TState>(title, mask, state, showAdditionalProperties, switchAdditionalProperties, options, contentDrawers);
return new FoldoutGroupDrawerInternal<TEnum, TState>(title, mask, state, showAdditionalProperties, switchAdditionalProperties, options, contextAction, additionalMenuAction, contentDrawers);
}

/// <summary> Helper to draw a foldout with an advanced switch on it. </summary>
Expand Down Expand Up @@ -741,7 +815,7 @@ public static IDrawer AdvancedFoldoutGroup<TEnum, TState>(GUIContent foldoutTitl
public static IDrawer AdvancedFoldoutGroup<TEnum, TState>(GUIContent foldoutTitle, TEnum foldoutMask, ExpandedState<TEnum, TState> foldoutState, Enabler isAdvanced, SwitchEnabler switchAdvanced, ActionDrawer normalContent, ActionDrawer advancedContent, FoldoutOption options = FoldoutOption.Indent)
where TEnum : struct, IConvertible
{
return FoldoutGroup(foldoutTitle, foldoutMask, foldoutState, options, isAdvanced, switchAdvanced, normalContent,
return FoldoutGroup(foldoutTitle, foldoutMask, foldoutState, options, isAdvanced, switchAdvanced, null, null, normalContent,
Conditional((serialized, owner) => isAdvanced(serialized, owner) && foldoutState[foldoutMask], advancedContent).Draw);
}

Expand Down Expand Up @@ -837,6 +911,32 @@ public static IDrawer AdditionalPropertiesFoldoutGroup<TEnum, TState, TAPEnum, T
TAPEnum additionalPropertiesMask, AdditionalPropertiesState<TAPEnum, TAPState> additionalPropertiesState, ActionDrawer normalContent, ActionDrawer additionalContent, FoldoutOption options = FoldoutOption.Indent)
where TEnum : struct, IConvertible
where TAPEnum : struct, IConvertible
{
return AdditionalPropertiesFoldoutGroup(foldoutTitle, foldoutMask, foldoutState, additionalPropertiesMask, additionalPropertiesState, normalContent, additionalContent, null, options);
}

/// <summary>
/// Helper to draw a foldout with additional properties.
/// </summary>
/// <typeparam name="TEnum">Type of the foldout mask used.</typeparam>
/// <typeparam name="TState">Type of the persistent foldout state.</typeparam>
/// <typeparam name="TAPEnum">Type of the additional properties mask used.</typeparam>
/// <typeparam name="TAPState">Type of the persistent additional properties state.</typeparam>
/// <param name="foldoutTitle">Title wanted for this foldout header</param>
/// <param name="foldoutMask">Bit mask (enum) used to define the boolean saving the state in ExpandedState</param>
/// <param name="foldoutState">The ExpandedState describing the component</param>
/// <param name="additionalPropertiesMask">Bit mask (enum) used to define the boolean saving the state in AdditionalPropertiesState</param>
/// <param name="additionalPropertiesState">The AdditionalPropertiesState describing the component</param>
/// <param name="normalContent"> The content of the foldout header always visible if expended. </param>
/// <param name="additionalContent">The content of the foldout header only visible if additional properties are shown and if foldout is expanded.</param>
/// <param name="additionalMenuAction">The adding content to the foldout header burger menu while maintaining the additional properties functionallity.</param>
/// <param name="options">Drawing options</param>
/// <returns>A IDrawer object</returns>
public static IDrawer AdditionalPropertiesFoldoutGroup<TEnum, TState, TAPEnum, TAPState>(GUIContent foldoutTitle, TEnum foldoutMask, ExpandedState<TEnum, TState> foldoutState,
TAPEnum additionalPropertiesMask, AdditionalPropertiesState<TAPEnum, TAPState> additionalPropertiesState, ActionDrawer normalContent, ActionDrawer additionalContent,
Action<GenericMenu> additionalMenuAction, FoldoutOption options = FoldoutOption.Indent)
where TEnum : struct, IConvertible
where TAPEnum : struct, IConvertible
{
bool Enabler(TData data, Editor owner)
{
Expand All @@ -848,11 +948,13 @@ void SwitchEnabler(TData data, Editor owner)
additionalPropertiesState[additionalPropertiesMask] = !additionalPropertiesState[additionalPropertiesMask];
}

return FoldoutGroup(foldoutTitle, foldoutMask, foldoutState, options, Enabler, SwitchEnabler,
return FoldoutGroup(foldoutTitle, foldoutMask, foldoutState, options, Enabler, SwitchEnabler, null, additionalMenuAction,
normalContent,
ConditionalWithAdditionalProperties((serialized, owner) => additionalPropertiesState[additionalPropertiesMask] && foldoutState[foldoutMask], additionalPropertiesState.GetAnimation(additionalPropertiesMask), additionalContent).Draw
ConditionalWithAdditionalProperties((serialized, owner) => additionalPropertiesState[additionalPropertiesMask] && foldoutState[foldoutMask],
additionalPropertiesState.GetAnimation(additionalPropertiesMask), additionalContent).Draw
);
}

}

/// <summary>CoreEditorDrawer extensions</summary>
Expand Down
19 changes: 12 additions & 7 deletions com.unity.render-pipelines.core/Editor/CoreEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public static void DrawHeader(GUIContent title)
/// <summary> Draw a foldout header </summary>
/// <param name="title"> The title of the header </param>
/// <param name="state"> The state of the header </param>
/// <param name="isBoxed"> [optional] is the eader contained in a box style ? </param>
/// <param name="isBoxed"> [optional] is the header contained in a box style ? </param>
/// <param name="hasMoreOptions"> [optional] Delegate used to draw the right state of the advanced button. If null, no button drawn. </param>
/// <param name="toggleMoreOption"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param>
/// <returns>return the state of the foldout header</returns>
Expand All @@ -421,8 +421,9 @@ public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = fa
/// <param name="toggleMoreOptions"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param>
/// <param name="documentationURL">[optional] The URL that the Unity Editor opens when the user presses the help button on the header.</param>
/// <param name="contextAction">[optional] The callback that the Unity Editor executes when the user presses the burger menu on the header.</param>
/// <param name="additionalMenuAction">[optional] The callback to add to the additional properties callback burger menu.</param>
/// <returns>return the state of the foldout header</returns>
public static bool DrawHeaderFoldout(GUIContent title, bool state, bool isBoxed = false, Func<bool> hasMoreOptions = null, Action toggleMoreOptions = null, string documentationURL = "", Action<Vector2> contextAction = null)
public static bool DrawHeaderFoldout(GUIContent title, bool state, bool isBoxed = false, Func<bool> hasMoreOptions = null, Action toggleMoreOptions = null, string documentationURL = "", Action<Vector2> contextAction = null, Action<GenericMenu> additionalMenuAction = null)
{
const float height = 17f;
var backgroundRect = GUILayoutUtility.GetRect(1f, height);
Expand Down Expand Up @@ -467,7 +468,7 @@ public static bool DrawHeaderFoldout(GUIContent title, bool state, bool isBoxed
// Add context menu for "Additional Properties"
if (contextAction == null && hasMoreOptions != null)
{
contextAction = pos => OnContextClick(pos, hasMoreOptions, toggleMoreOptions);
contextAction = pos => OnContextClick(pos, hasMoreOptions, toggleMoreOptions, additionalMenuAction);
}

if (contextAction != null)
Expand Down Expand Up @@ -673,7 +674,7 @@ public static bool DrawHeaderToggle(GUIContent title, SerializedProperty group,
if (contextAction == null && hasMoreOptions != null)
{
// If no contextual menu add one for the additional properties.
contextAction = pos => OnContextClick(pos, hasMoreOptions, toggleMoreOptions);
contextAction = pos => OnContextClick(pos, hasMoreOptions, toggleMoreOptions, null);
}

if (contextAction != null)
Expand Down Expand Up @@ -748,7 +749,7 @@ public static void DrawSectionHeader(GUIContent title, string documentationURL =
}
}

static void ShowHelpButton(Rect contextMenuRect, string documentationURL, GUIContent title)
public static void ShowHelpButton(Rect contextMenuRect, string documentationURL, GUIContent title)
{
if (string.IsNullOrEmpty(documentationURL))
return;
Expand All @@ -762,10 +763,14 @@ static void ShowHelpButton(Rect contextMenuRect, string documentationURL, GUICon
Help.BrowseURL(documentationURL);
}

static void OnContextClick(Vector2 position, Func<bool> hasMoreOptions, Action toggleMoreOptions)
static void OnContextClick(Vector2 position, Func<bool> hasMoreOptions, Action toggleMoreOptions, Action<GenericMenu> additionalMenuAction)
{
var menu = new GenericMenu();

if (additionalMenuAction != null)
{
additionalMenuAction(menu);
menu.AddSeparator("");
}
menu.AddItem(EditorGUIUtility.TrTextContent("Show Additional Properties"), hasMoreOptions.Invoke(), () => toggleMoreOptions.Invoke());
menu.AddItem(EditorGUIUtility.TrTextContent("Show All Additional Properties..."), false, () => CoreRenderPipelinePreferences.Open());

Expand Down
Loading