From c96ef3c491d1cf6fe027738949d78926f2c3fe13 Mon Sep 17 00:00:00 2001 From: Felix Herbst Date: Wed, 5 Aug 2020 11:48:27 +0200 Subject: [PATCH 1/2] add toolbar search field for nodes, prevent multiple invocations of DependencyNodePlacement --- .../Editor/AssetDependencyGraph.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/AssetDependencyGraph/Editor/AssetDependencyGraph.cs b/AssetDependencyGraph/Editor/AssetDependencyGraph.cs index fa55c4d..bc0fcb4 100644 --- a/AssetDependencyGraph/Editor/AssetDependencyGraph.cs +++ b/AssetDependencyGraph/Editor/AssetDependencyGraph.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using UnityEditor; +using UnityEditor.UIElements; #if UNITY_2019_1_OR_NEWER using UnityEditor.Experimental.GraphView; using UnityEngine.UIElements; @@ -87,6 +88,25 @@ public void OnEnable() { text = "Clear" }); + + var ts = new ToolbarSearchField(); + ts.RegisterValueChangedCallback(x => { + if (string.IsNullOrEmpty(x.newValue)) { + m_GraphView.FrameAll(); + return; + } + + m_GraphView.ClearSelection(); + // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337 + m_GraphView.graphElements.ToList().ForEach(y => { + if (y is Node node && y.title.Contains(x.newValue)) { + m_GraphView.AddToSelection(node); + } + }); + + m_GraphView.FrameSelection(); + }); + toolbar.Add(ts); #if !UNITY_2019_1_OR_NEWER rootVisualElement = this.GetRootVisualContainer(); @@ -118,6 +138,7 @@ private void ExploreAsset() bool hasDependencies = dependencies.Length > 0; Node mainNode = CreateNode(mainObject, assetPath, true, hasDependencies); + mainNode.userData = 0; mainNode.SetPosition(new Rect(0, 0, 0, 0)); m_GraphView.AddElement(groupNode); @@ -332,6 +353,8 @@ private void ClearGraph() private void UpdateDependencyNodePlacement(GeometryChangedEvent e) { + (e.target as VisualElement).UnregisterCallback(UpdateDependencyNodePlacement); + // The current y offset in per depth var depthYOffset = new Dictionary(); From b370d8e1bedd1854f30306b0745fc42a18f77373 Mon Sep 17 00:00:00 2001 From: hybridherbst Date: Fri, 28 Aug 2020 22:04:00 +0200 Subject: [PATCH 2/2] ignore search case Co-authored-by: Harry Rose <36076169+Unity-Harry@users.noreply.github.com> --- AssetDependencyGraph/Editor/AssetDependencyGraph.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AssetDependencyGraph/Editor/AssetDependencyGraph.cs b/AssetDependencyGraph/Editor/AssetDependencyGraph.cs index bc0fcb4..5ac5055 100644 --- a/AssetDependencyGraph/Editor/AssetDependencyGraph.cs +++ b/AssetDependencyGraph/Editor/AssetDependencyGraph.cs @@ -99,7 +99,7 @@ public void OnEnable() m_GraphView.ClearSelection(); // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337 m_GraphView.graphElements.ToList().ForEach(y => { - if (y is Node node && y.title.Contains(x.newValue)) { + if (y is Node node && y.title.IndexOf(x.newValue, StringComparison.OrdinalIgnoreCase) >= 0) { m_GraphView.AddToSelection(node); } });