Skip to content

Commit 0997806

Browse files
authored
Merge pull request #8 from prefrontalcortex/add-toolbar-search
Add toolbar search field for nodes, small fixes when "refreshing"
2 parents 5efdd15 + b370d8e commit 0997806

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

AssetDependencyGraph/Editor/AssetDependencyGraph.cs

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using UnityEditor;
3+
using UnityEditor.UIElements;
34
#if UNITY_2019_1_OR_NEWER
45
using UnityEditor.Experimental.GraphView;
56
using UnityEngine.UIElements;
@@ -87,6 +88,25 @@ public void OnEnable()
8788
{
8889
text = "Clear"
8990
});
91+
92+
var ts = new ToolbarSearchField();
93+
ts.RegisterValueChangedCallback(x => {
94+
if (string.IsNullOrEmpty(x.newValue)) {
95+
m_GraphView.FrameAll();
96+
return;
97+
}
98+
99+
m_GraphView.ClearSelection();
100+
// m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337
101+
m_GraphView.graphElements.ToList().ForEach(y => {
102+
if (y is Node node && y.title.IndexOf(x.newValue, StringComparison.OrdinalIgnoreCase) >= 0) {
103+
m_GraphView.AddToSelection(node);
104+
}
105+
});
106+
107+
m_GraphView.FrameSelection();
108+
});
109+
toolbar.Add(ts);
90110

91111
#if !UNITY_2019_1_OR_NEWER
92112
rootVisualElement = this.GetRootVisualContainer();
@@ -118,6 +138,7 @@ private void ExploreAsset()
118138
bool hasDependencies = dependencies.Length > 0;
119139

120140
Node mainNode = CreateNode(mainObject, assetPath, true, hasDependencies);
141+
mainNode.userData = 0;
121142

122143
mainNode.SetPosition(new Rect(0, 0, 0, 0));
123144
m_GraphView.AddElement(groupNode);
@@ -332,6 +353,8 @@ private void ClearGraph()
332353

333354
private void UpdateDependencyNodePlacement(GeometryChangedEvent e)
334355
{
356+
(e.target as VisualElement).UnregisterCallback<GeometryChangedEvent>(UpdateDependencyNodePlacement);
357+
335358
// The current y offset in per depth
336359
var depthYOffset = new Dictionary<int, float>();
337360

0 commit comments

Comments
 (0)