Skip to content

Commit ef27859

Browse files
committed
Roll back to version that works with current release
Rolling back to 234ba59
1 parent b631c0f commit ef27859

File tree

3 files changed

+95
-89
lines changed

3 files changed

+95
-89
lines changed

Assets/GraphVisualizer/Clients/GraphVisualizerClient.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class GraphVisualizerClient
99
{
1010
private static GraphVisualizerClient s_Instance;
11-
private List<PlayableGraph> m_Graphs = new List<PlayableGraph>();
11+
private Dictionary<PlayableGraph, string> m_Graphs = new Dictionary<PlayableGraph, string>();
1212

1313
public static GraphVisualizerClient instance
1414
{
@@ -19,29 +19,26 @@ public static GraphVisualizerClient instance
1919
return s_Instance;
2020
}
2121
}
22-
2322
~GraphVisualizerClient()
2423
{
2524
m_Graphs.Clear();
2625
}
27-
28-
public static void Show(PlayableGraph graph)
26+
public static void Show(PlayableGraph graph, string name)
2927
{
30-
if (!instance.m_Graphs.Contains(graph))
28+
if (!instance.m_Graphs.ContainsKey(graph))
3129
{
32-
instance.m_Graphs.Add(graph);
30+
instance.m_Graphs.Add(graph, name);
3331
}
3432
}
35-
3633
public static void Hide(PlayableGraph graph)
3734
{
38-
if (instance.m_Graphs.Contains(graph))
35+
if (instance.m_Graphs.ContainsKey(graph))
3936
{
4037
instance.m_Graphs.Remove(graph);
4138
}
4239
}
4340

44-
public static IEnumerable<PlayableGraph> GetGraphs()
41+
public static IEnumerable<KeyValuePair<PlayableGraph, string>> GetGraphs()
4542
{
4643
return instance.m_Graphs;
4744
}

Assets/GraphVisualizer/Editor/PlayableGraphVisualizerWindow.cs

Lines changed: 77 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,63 @@
88

99
public class PlayableGraphVisualizerWindow : EditorWindow, IHasCustomMenu
1010
{
11+
private struct PlayableGraphInfo
12+
{
13+
public PlayableGraph graph;
14+
public string name;
15+
}
16+
1117
private IGraphRenderer m_Renderer;
1218
private IGraphLayout m_Layout;
1319

14-
private List<PlayableGraph> m_Graphs;
15-
private PlayableGraph m_CurrentGraph;
20+
private PlayableGraphInfo m_CurrentGraphInfo;
1621
private GraphSettings m_GraphSettings;
22+
private bool m_AutoScanScene = true;
1723

18-
#region Configuration
24+
#region Configuration
1925

2026
private static readonly float s_ToolbarHeight = 17f;
2127
private static readonly float s_DefaultMaximumNormalizedNodeSize = 0.8f;
2228
private static readonly float s_DefaultMaximumNodeSizeInPixels = 100.0f;
2329
private static readonly float s_DefaultAspectRatio = 1.5f;
2430

25-
#endregion
26-
31+
#endregion
2732
private PlayableGraphVisualizerWindow()
2833
{
2934
m_GraphSettings.maximumNormalizedNodeSize = s_DefaultMaximumNormalizedNodeSize;
3035
m_GraphSettings.maximumNodeSizeInPixels = s_DefaultMaximumNodeSizeInPixels;
3136
m_GraphSettings.aspectRatio = s_DefaultAspectRatio;
3237
m_GraphSettings.showLegend = true;
38+
m_AutoScanScene = true;
3339
}
3440

3541
[MenuItem("Window/PlayableGraph Visualizer")]
3642
public static void ShowWindow()
3743
{
38-
GetWindow<PlayableGraphVisualizerWindow>("PlayableGraph Visualizer");
44+
GetWindow<PlayableGraphVisualizerWindow>("Playable Graph Visualizer");
3945
}
4046

41-
private PlayableGraph GetSelectedGraphInToolBar(List<PlayableGraph> graphs, PlayableGraph currentGraph)
47+
private PlayableGraphInfo GetSelectedGraphInToolBar(IList<PlayableGraphInfo> graphs, PlayableGraphInfo currentGraph)
4248
{
4349
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Width(position.width));
4450

45-
List<string> options = new List<string>(graphs.Count);
46-
foreach (var graph in graphs)
51+
List<string> options = new List<string>(graphs.Count);// = graphs.Select(d => d.ToString()).ToArray();
52+
foreach (var g in graphs)
4753
{
48-
string name = graph.GetEditorName();
49-
options.Add(name.Length != 0 ? name : "[Unnamed]");
54+
options.Add(g.name);
5055
}
5156

5257
int currentSelection = graphs.IndexOf(currentGraph);
5358
int newSelection = EditorGUILayout.Popup(currentSelection != -1 ? currentSelection : 0, options.ToArray(), GUILayout.Width(200));
5459

55-
PlayableGraph selectedGraph = new PlayableGraph();
60+
PlayableGraphInfo selectedDirector = new PlayableGraphInfo();
5661
if (newSelection != -1)
57-
selectedGraph = graphs[newSelection];
62+
selectedDirector = graphs[newSelection];
5863

5964
GUILayout.FlexibleSpace();
6065
EditorGUILayout.EndHorizontal();
6166

62-
return selectedGraph;
67+
return selectedDirector;
6368
}
6469

6570
private static void ShowMessage(string msg)
@@ -93,52 +98,78 @@ void OnInspectorUpdate()
9398
Repaint();
9499
}
95100

96-
void OnEnable()
101+
void OnGUI()
97102
{
98-
m_Graphs = new List<PlayableGraph>(UnityEditor.Playables.Utility.GetAllGraphs());
103+
// Create a list of all the playable graphs extracted.
104+
IList<PlayableGraphInfo> graphInfos = new List<PlayableGraphInfo>();
99105

100-
UnityEditor.Playables.Utility.graphCreated += OnGraphCreated;
101-
UnityEditor.Playables.Utility.destroyingGraph += OnDestroyingGraph;
102-
}
106+
PlayableGraphInfo info;
103107

104-
void OnGraphCreated(PlayableGraph graph)
105-
{
106-
if (!m_Graphs.Contains(graph))
107-
m_Graphs.Add(graph);
108-
}
109-
110-
void OnDestroyingGraph(PlayableGraph graph)
111-
{
112-
m_Graphs.Remove(graph);
113-
}
108+
// If we requested, we extract automatically the PlayableGraphs from all the components
109+
// that are in the current scene.
110+
if (m_AutoScanScene)
111+
{
112+
// This code could be generalized, maybe if we added a IHasPlayableGraph Interface.
113+
IList<PlayableDirector> directors = FindObjectsOfType<PlayableDirector>();
114+
if (directors != null)
115+
{
116+
foreach (var director in directors)
117+
{
118+
if (director.playableGraph.IsValid())
119+
{
120+
info.name = director.name;
121+
info.graph = director.playableGraph;
122+
graphInfos.Add(info);
123+
}
124+
}
125+
}
126+
127+
IList<Animator> animators = FindObjectsOfType<Animator>();
128+
if (animators != null)
129+
{
130+
foreach (var animator in animators)
131+
{
132+
if (animator.playableGraph.IsValid())
133+
{
134+
info.name = animator.name;
135+
info.graph = animator.playableGraph;
136+
graphInfos.Add(info);
137+
}
138+
}
139+
}
140+
}
114141

115-
void OnDisable()
116-
{
117-
UnityEditor.Playables.Utility.graphCreated -= OnGraphCreated;
118-
UnityEditor.Playables.Utility.destroyingGraph -= OnDestroyingGraph;
119-
}
142+
if (GraphVisualizerClient.GetGraphs() != null)
143+
{
144+
foreach (var clientGraph in GraphVisualizerClient.GetGraphs())
145+
{
146+
if (clientGraph.Key.IsValid())
147+
{
148+
info.name = clientGraph.Value;
149+
info.graph = clientGraph.Key;
150+
graphInfos.Add(info);
151+
}
152+
}
153+
}
120154

121-
void OnGUI()
122-
{
123155
// Early out if there is no graphs.
124-
var selectedGraphs = GetGraphList();
125-
if (selectedGraphs.Count == 0)
156+
if (graphInfos.Count == 0)
126157
{
127158
ShowMessage("No PlayableGraph in the scene");
128159
return;
129160
}
130161

131162
GUILayout.BeginVertical();
132-
m_CurrentGraph = GetSelectedGraphInToolBar(selectedGraphs, m_CurrentGraph);
163+
m_CurrentGraphInfo = GetSelectedGraphInToolBar(graphInfos, m_CurrentGraphInfo);
133164
GUILayout.EndVertical();
134165

135-
if (!m_CurrentGraph.IsValid())
166+
if (!m_CurrentGraphInfo.graph.IsValid())
136167
{
137168
ShowMessage("Selected PlayableGraph is invalid");
138169
return;
139170
}
140171

141-
var graph = new PlayableGraphVisualizer(m_CurrentGraph);
172+
var graph = new PlayableGraphVisualizer(m_CurrentGraphInfo.graph);
142173
graph.Refresh();
143174

144175
if (graph.IsEmpty())
@@ -160,32 +191,21 @@ void OnGUI()
160191
m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings);
161192
}
162193

163-
private List<PlayableGraph> GetGraphList()
164-
{
165-
var selectedGraphs = new List<PlayableGraph>();
166-
foreach (var clientGraph in GraphVisualizerClient.GetGraphs())
167-
{
168-
if (clientGraph.IsValid())
169-
selectedGraphs.Add(clientGraph);
170-
}
171-
172-
if (selectedGraphs.Count == 0)
173-
selectedGraphs = m_Graphs.ToList();
174-
175-
return selectedGraphs;
176-
}
177-
178194
#region Custom_Menu
179195

180196
public virtual void AddItemsToMenu(GenericMenu menu)
181197
{
182198
menu.AddItem(new GUIContent("Legend"), m_GraphSettings.showLegend, ToggleLegend);
199+
menu.AddItem(new GUIContent("Auto Scan Scene"), m_AutoScanScene, ToggleAutoScanScene);
183200
}
184-
185201
void ToggleLegend()
186202
{
187203
m_GraphSettings.showLegend = !m_GraphSettings.showLegend;
188204
}
205+
void ToggleAutoScanScene()
206+
{
207+
m_AutoScanScene = !m_AutoScanScene;
208+
}
189209

190210
#endregion
191211
}

README.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
# PlayableGraph Visualizer
2-
3-
## Introduction
4-
5-
The PlayableGraph Visualizer window can be used to display any `PlayableGraph`.
1+
# PlayableGraph Visualizer #
2+
## Introduction ##
3+
The PlayableGraph Visualizer window can be used to display any *PlayableGraph*.
64
The tool can be used in both Play and Edit mode and will always reflect the current state of the graph.
75
Playable Handles in the graph are represented by colored nodes, varying according to their type. Wire color intensity indicates the local weight of the blending.
8-
9-
## Setup
10-
6+
## Setup ##
117
- Download the release that matches your current Unity version, or the latest if there your Unity version is more recent than the latest release.
128
- Copy the content of this repos Asset folder into a the Asset folder of an Unity Project. You will need to do this for every project.
13-
14-
## Window
15-
9+
## Window ##
1610
- You can open the Timeline Visualizer in **Window > PlayableGraph Visualizer**.
17-
18-
## Usage
19-
20-
- Open any scene that contains at least one `PlayableGraph`.
21-
- By default, all the `PlayableGraph`s of your scene will be listed in the editor's top-left list.
22-
- You can show just your `PlayableGraph` using `GraphVisualizerClient.Show(PlayableGraph)`.
23-
- Select the `PlayableGraph` to display in the top-left list.
11+
## Usage ##
12+
- Open any scene that contains at least one *PlayableGraph*.
13+
- Register your *PlayableGraph* with the method GraphVisualizerClient.Show(PlayableGraph, string).
14+
- Select the *PlayableGraph* to display in the top-left combo box.
2415
- Click on a Node to display more information about the associated Playable Handle.
25-
26-
## Notes
27-
28-
- This tool was previously named Timeline Visualizer, but was renamed as we are refactoring it to support `PlayableGraph` stored in different types of component.
29-
- If your `PlayableGraph` is only available in Play mode, you will not be able to see it in Edit mode.
16+
## Notes ##
17+
- This tool was previously named Timeline Visualizer, but was renamed as we are refactoring it to support *PlayableGraph* stored in different types of component.
18+
- If your *PlayableGraph* is only available in Play mode, you will not be able to see it in Edit mode.

0 commit comments

Comments
 (0)