Skip to content

Add toolbar search field for nodes, small fixes when "refreshing" #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2020
Merged
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
23 changes: 23 additions & 0 deletions AssetDependencyGraph/Editor/AssetDependencyGraph.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -332,6 +353,8 @@ private void ClearGraph()

private void UpdateDependencyNodePlacement(GeometryChangedEvent e)
{
(e.target as VisualElement).UnregisterCallback<GeometryChangedEvent>(UpdateDependencyNodePlacement);

// The current y offset in per depth
var depthYOffset = new Dictionary<int, float>();

Expand Down