From 9815139fdd730c4ff18d248919c3ff78677bddc8 Mon Sep 17 00:00:00 2001 From: Baste Nesse Buanes Date: Mon, 29 Jul 2019 16:25:46 +0200 Subject: [PATCH 1/2] Added support for setting the display name of playable graphs when calling GraphVisualizerClient.Show --- Editor/PlayableGraphVisualizerWindow.cs | 6 +++++- Runtime/GraphVisualizerClient.cs | 26 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Editor/PlayableGraphVisualizerWindow.cs b/Editor/PlayableGraphVisualizerWindow.cs index c9c3560..faa75fe 100644 --- a/Editor/PlayableGraphVisualizerWindow.cs +++ b/Editor/PlayableGraphVisualizerWindow.cs @@ -46,7 +46,11 @@ private PlayableGraph GetSelectedGraphInToolBar(List graphs, Play List options = new List(graphs.Count); foreach (var graph in graphs) { - string name = graph.GetEditorName(); + string name = GraphVisualizerClient.GetName(graph); + if (name == null) + { + name = graph.GetEditorName(); + } options.Add(name.Length != 0 ? name : "[Unnamed]"); } diff --git a/Runtime/GraphVisualizerClient.cs b/Runtime/GraphVisualizerClient.cs index 728f26e..b7f0cc5 100644 --- a/Runtime/GraphVisualizerClient.cs +++ b/Runtime/GraphVisualizerClient.cs @@ -7,6 +7,7 @@ public class GraphVisualizerClient { private static GraphVisualizerClient s_Instance; private List m_Graphs = new List(); + private Dictionary m_GraphNames = new Dictionary(); public static GraphVisualizerClient instance { @@ -24,19 +25,27 @@ public static GraphVisualizerClient instance } public static void Show(PlayableGraph graph) + { +#if UNITY_EDITOR + Show(graph, graph.GetEditorName()); +#else + Show(graph, null); +#endif + } + + public static void Show(PlayableGraph graph, string name) { if (!instance.m_Graphs.Contains(graph)) { instance.m_Graphs.Add(graph); } + instance.m_GraphNames[graph] = name; } public static void Hide(PlayableGraph graph) { - if (instance.m_Graphs.Contains(graph)) - { - instance.m_Graphs.Remove(graph); - } + instance.m_Graphs.Remove(graph); + instance.m_GraphNames.Remove(graph); } public static void ClearGraphs() @@ -48,4 +57,13 @@ public static IEnumerable GetGraphs() { return instance.m_Graphs; } + + public static string GetName(PlayableGraph graph) + { + if (instance.m_GraphNames.TryGetValue(graph, out var name)) + { + return name; + } + return null; + } } From 51f211a2e1adb14677e7d72189e6b2e0eef7c2b4 Mon Sep 17 00:00:00 2001 From: Baste Nesse Buanes Date: Mon, 29 Jul 2019 16:54:31 +0200 Subject: [PATCH 2/2] Made the list of playable graphs be sorted. --- Editor/PlayableGraphVisualizerWindow.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Editor/PlayableGraphVisualizerWindow.cs b/Editor/PlayableGraphVisualizerWindow.cs index faa75fe..82aff10 100644 --- a/Editor/PlayableGraphVisualizerWindow.cs +++ b/Editor/PlayableGraphVisualizerWindow.cs @@ -54,6 +54,8 @@ private PlayableGraph GetSelectedGraphInToolBar(List graphs, Play options.Add(name.Length != 0 ? name : "[Unnamed]"); } + options.Sort(); + int currentSelection = graphs.IndexOf(currentGraph); int newSelection = EditorGUILayout.Popup(currentSelection != -1 ? currentSelection : 0, options.ToArray(), GUILayout.Width(200));