diff --git a/AssetDependencyGraph/Editor/AssetDependencyGraph.cs b/AssetDependencyGraph/Editor/AssetDependencyGraph.cs index fa55c4d..5ac5055 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.IndexOf(x.newValue, StringComparison.OrdinalIgnoreCase) >= 0) { + 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();