Skip to content

Commit 9145509

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.3] Improve VolumeProfile inspector performance
1 parent 72cf15a commit 9145509

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

Packages/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentEditor.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,24 +428,27 @@ public override void OnInspectorGUI()
428428
}
429429
}
430430

431+
GUIContent m_DisplayTitle;
431432
/// <summary>
432433
/// Sets the label for the component header. Override this method to provide
433434
/// a custom label. If you don't, Unity automatically obtains one from the class name.
434435
/// </summary>
435436
/// <returns>A label to display in the component header.</returns>
436437
public virtual GUIContent GetDisplayTitle()
437438
{
439+
if (m_DisplayTitle != null) return m_DisplayTitle;
440+
438441
var volumeComponentType = volumeComponent.GetType();
439442
var displayInfo = volumeComponentType.GetCustomAttribute<DisplayInfoAttribute>();
440443
if (displayInfo != null && !string.IsNullOrWhiteSpace(displayInfo.name))
441-
return EditorGUIUtility.TrTextContent(displayInfo.name, string.Empty);
444+
return m_DisplayTitle = EditorGUIUtility.TrTextContent(displayInfo.name, string.Empty);
442445

443446
#pragma warning disable CS0618
444447
if (!string.IsNullOrWhiteSpace(volumeComponent.displayName))
445-
return EditorGUIUtility.TrTextContent(volumeComponent.displayName, string.Empty);
448+
return m_DisplayTitle = EditorGUIUtility.TrTextContent(volumeComponent.displayName, string.Empty);
446449
#pragma warning restore CS0618
447450

448-
return EditorGUIUtility.TrTextContent(ObjectNames.NicifyVariableName(volumeComponentType.Name) , string.Empty);
451+
return m_DisplayTitle = EditorGUIUtility.TrTextContent(ObjectNames.NicifyVariableName(volumeComponentType.Name), string.Empty);
449452
}
450453

451454
void AddToggleState(GUIContent content, bool state)

Packages/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentListEditor.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ void CreateEditor(VolumeComponent component, SerializedProperty property, int in
155155
else
156156
m_Editors[index] = editor;
157157

158+
FilterEditorsBySearch();
159+
158160
DocumentationUtils.TryGetHelpURL(component.GetType(), out string helpUrl);
159161
helpUrl ??= string.Empty;
160162
m_VolumeComponentHelpUrls[editor] = helpUrl;
@@ -222,9 +224,22 @@ public void Clear()
222224
asset = null;
223225
}
224226

227+
readonly HashSet<VolumeComponentEditor> m_CurrentSearchFilteredEditors = new();
228+
void FilterEditorsBySearch()
229+
{
230+
m_CurrentSearchFilteredEditors.Clear();
231+
if (string.IsNullOrEmpty(m_SearchString)) return;
232+
233+
foreach (var editor in m_Editors)
234+
{
235+
if (MatchesSearchString(editor.GetDisplayTitle().text))
236+
m_CurrentSearchFilteredEditors.Add(editor);
237+
}
238+
}
239+
bool EditorIsIncludedInCurrentSearch(VolumeComponentEditor editor) => string.IsNullOrEmpty(m_SearchString) || m_CurrentSearchFilteredEditors.Contains(editor);
225240
bool MatchesSearchString(string title)
226241
{
227-
return m_SearchString.Length == 0 || title.Contains(m_SearchString, StringComparison.OrdinalIgnoreCase);
242+
return string.IsNullOrEmpty(m_SearchString) || title.Contains(m_SearchString, StringComparison.OrdinalIgnoreCase);
228243
}
229244

230245
/// <summary>
@@ -263,7 +278,7 @@ bool ShouldDrawEditor(VolumeComponentEditor editor)
263278
{
264279
if (!editor.visible)
265280
return false;
266-
return MatchesSearchString(editor.GetDisplayTitle().text);
281+
return EditorIsIncludedInCurrentSearch(editor);
267282
}
268283

269284
void DrawEditor(VolumeComponentEditor editor, int index = -1)
@@ -310,7 +325,11 @@ void DrawEditor(VolumeComponentEditor editor, int index = -1)
310325
{
311326
Rect searchRect = GUILayoutUtility.GetRect(50, EditorGUIUtility.singleLineHeight);
312327
searchRect.width -= 2;
313-
m_SearchString = m_SearchField.OnGUI(searchRect, m_SearchString);
328+
using (var check = new EditorGUI.ChangeCheckScope())
329+
{
330+
m_SearchString = m_SearchField.OnGUI(searchRect, m_SearchString);
331+
if (check.changed) FilterEditorsBySearch();
332+
}
314333
GUILayout.Space(2);
315334

316335
EditorGUILayout.HelpBox(
@@ -346,7 +365,6 @@ void DrawEditor(VolumeComponentEditor editor, int index = -1)
346365

347366
for (int i = 0; i < editors.Count; i++)
348367
DrawEditor(editors[i]);
349-
350368
GUILayout.Space(8);
351369
}
352370
}

0 commit comments

Comments
 (0)