Skip to content

Commit 83b1bd6

Browse files
author
Chafik Achache
authored
Merge pull request #3 from UnityTech/2017.1
Merging 2017.1 into master
2 parents 3e63f71 + 3edc010 commit 83b1bd6

File tree

5 files changed

+153
-59
lines changed

5 files changed

+153
-59
lines changed

Assets/Clients/GraphVisualizerClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using UnityEngine;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using UnityEngine.Experimental.Director;
4+
using UnityEngine.Playables;
55

66
// Bridge between runtime and editor code: the graph created in runtime code can call GraphVisualizerClient.Show(...)
77
// and the EditorWindow will register itself with the client to display any available graph.

Assets/Editor/GraphVisualizer/Graph/Renderer/DefaultGraphRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Linq;
66
using System.Text.RegularExpressions;
77
using GraphVisualizer;
8-
using UnityEngine.Experimental.Director;
8+
using UnityEngine.Playables;
99

1010
public class DefaultGraphRenderer : IGraphRenderer
1111
{

Assets/Editor/GraphVisualizer/PlayableGraphVisualizer.cs

Lines changed: 130 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,60 @@
22
using System.Collections.Generic;
33
using System.Text;
44
using GraphVisualizer;
5-
using UnityEngine.Experimental.Director;
5+
using UnityEngine.Playables;
66

7-
public class PlayableGraphNode : Node
7+
public class SharedPlayableNode : Node
88
{
9-
public PlayableGraphNode(PlayableHandle content, float weight = 1, bool active = false)
9+
public SharedPlayableNode(object content, float weight = 1, bool active = false)
10+
: base(content, weight, active)
11+
{
12+
}
13+
14+
protected static string InfoString(string key, double value)
15+
{
16+
return String.Format(
17+
((Math.Abs(value) < 100000.0) ? "<b>{0}:</b> {1:#.###}" : "<b>{0}:</b> {1:E4}"), key, value);
18+
}
19+
20+
protected static string InfoString(string key, int value)
21+
{
22+
return String.Format("<b>{0}:</b> {1:D}", key, value);
23+
}
24+
25+
protected static string InfoString(string key, object value)
26+
{
27+
return "<b>" + key + ":</b> " + (value ?? "(none)");
28+
}
29+
30+
protected static string RemoveFromEnd(string str, string suffix)
31+
{
32+
if (str.EndsWith(suffix))
33+
{
34+
return str.Substring(0, str.Length - suffix.Length);
35+
}
36+
return str;
37+
}
38+
}
39+
40+
public class PlayableNode : SharedPlayableNode
41+
{
42+
public PlayableNode(Playable content, float weight = 1, bool active = false)
1043
: base(content, weight, active)
1144
{
1245
}
1346

1447
public override Type GetContentType()
1548
{
16-
Playable p = null;
49+
Playable p = Playable.Null;
1750
try
1851
{
19-
p = ((PlayableHandle)content).GetObject<Playable>();
52+
p = ((Playable)content);
2053
}
2154
catch
2255
{
2356
// Ignore.
2457
}
25-
return p == null ? null : p.GetType();
58+
return !p.IsValid() ? null : p.GetPlayableType();
2659
}
2760

2861
public override string GetContentTypeShortName()
@@ -39,48 +72,66 @@ public override string ToString()
3972

4073
sb.AppendLine(InfoString("Handle", GetContentTypeShortName()));
4174

42-
var h = (PlayableHandle)content;
75+
var h = (Playable)content;
4376

4477
sb.AppendLine(InfoString("IsValid", h.IsValid()));
4578

4679
if (h.IsValid())
4780
{
48-
sb.AppendLine(InfoString("IsDone", h.isDone));
49-
sb.AppendLine(InfoString("InputCount", h.inputCount));
50-
sb.AppendLine(InfoString("OutputCount", h.outputCount));
51-
sb.AppendLine(InfoString("PlayState", h.playState));
52-
sb.AppendLine(InfoString("Speed", h.speed));
53-
sb.AppendLine(InfoString("Duration", h.duration));
54-
sb.AppendLine(InfoString("Time", h.time));
81+
sb.AppendLine(InfoString("IsDone", h.IsDone()));
82+
sb.AppendLine(InfoString("InputCount", h.GetInputCount()));
83+
sb.AppendLine(InfoString("OutputCount", h.GetOutputCount()));
84+
sb.AppendLine(InfoString("PlayState", h.GetPlayState()));
85+
sb.AppendLine(InfoString("Speed", h.GetSpeed()));
86+
sb.AppendLine(InfoString("Duration", h.GetDuration()));
87+
sb.AppendLine(InfoString("Time", h.GetTime()));
5588
// sb.AppendLine(InfoString("Animation", h.animatedProperties));
5689
}
5790

5891
return sb.ToString();
5992
}
93+
}
6094

61-
private static string InfoString(string key, double value)
95+
public class PlayableOutputNode : SharedPlayableNode
96+
{
97+
public PlayableOutputNode(PlayableOutput content)
98+
: base(content, content.GetWeight(), true)
6299
{
63-
return String.Format(
64-
((Math.Abs(value) < 100000.0) ? "<b>{0}:</b> {1:#.###}" : "<b>{0}:</b> {1:E4}") , key, value);
65100
}
66101

67-
private static string InfoString(string key, int value)
102+
public override Type GetContentType()
68103
{
69-
return String.Format("<b>{0}:</b> {1:D}", key, value);
104+
PlayableOutput p = PlayableOutput.Null;
105+
try
106+
{
107+
p = ((PlayableOutput)content);
108+
}
109+
catch
110+
{
111+
// Ignore.
112+
}
113+
return !p.IsOutputValid() ? null : p.GetPlayableOutputType();
70114
}
71115

72-
private static string InfoString(string key, object value)
116+
public override string GetContentTypeShortName()
73117
{
74-
return "<b>" + key + ":</b> " + (value ?? "(none)");
118+
// Remove the extra Playable at the end of the Playable types.
119+
string shortName = base.GetContentTypeShortName();
120+
string cleanName = RemoveFromEnd(shortName, "PlayableOutput") + "Output";
121+
return string.IsNullOrEmpty(cleanName) ? shortName : cleanName;
75122
}
76123

77-
private static string RemoveFromEnd(string str, string suffix)
124+
public override string ToString()
78125
{
79-
if (str.EndsWith(suffix))
80-
{
81-
return str.Substring(0, str.Length - suffix.Length);
82-
}
83-
return str;
126+
var sb = new StringBuilder();
127+
128+
sb.AppendLine(InfoString("Handle", GetContentTypeShortName()));
129+
130+
var h = (PlayableOutput)content;
131+
132+
sb.AppendLine(InfoString("IsValid", h.IsOutputValid()));
133+
134+
return sb.ToString();
84135
}
85136
}
86137

@@ -95,47 +146,81 @@ public PlayableGraphVisualizer(PlayableGraph playableGraph)
95146

96147
protected override void Populate()
97148
{
98-
if (!m_PlayableGraph.IsValid()) return;
99-
int roots = m_PlayableGraph.rootPlayableCount;
100-
for (int i = 0; i < roots; i++)
149+
if (!m_PlayableGraph.IsValid())
150+
return;
151+
152+
int outputs = m_PlayableGraph.GetOutputCount();
153+
for (int i = 0; i < outputs; i++)
101154
{
102-
AddNodeHierarchy(CreateNodeFromPlayableHandle(m_PlayableGraph.GetRootPlayable(i), 1.0f));
155+
var output = m_PlayableGraph.GetOutput(i);
156+
if(output.IsOutputValid())
157+
{
158+
AddNodeHierarchy(CreateNodeFromPlayableOutput(output));
159+
}
103160
}
104161
}
105162

106163
protected override IEnumerable<Node> GetChildren(Node node)
107164
{
108-
// Children are the PlayableHandle Inputs.
109-
return GetInputsNode((PlayableHandle)node.content);
165+
// Children are the Playable Inputs.
166+
if(node is PlayableNode)
167+
return GetInputsFromPlayableNode((Playable)node.content);
168+
else if(node is PlayableOutputNode)
169+
return GetInputsFromPlayableOutputNode((PlayableOutput)node.content);
170+
171+
return new List<Node>();
110172
}
111173

112-
private List<Node> GetInputsNode(PlayableHandle h)
174+
private List<Node> GetInputsFromPlayableNode(Playable h)
113175
{
114176
var inputs = new List<Node>();
115-
for (int port = 0; port < h.inputCount; ++port)
177+
if (h.IsValid())
116178
{
117-
PlayableHandle playableHandle = h.GetInput(port);
118-
if (playableHandle.IsValid())
179+
for (int port = 0; port < h.GetInputCount(); ++port)
180+
{
181+
Playable playable = h.GetInput(port);
182+
if (playable.IsValid())
183+
{
184+
float weight = h.GetInputWeight(port);
185+
Node node = CreateNodeFromPlayable(playable, weight);
186+
inputs.Add(node);
187+
}
188+
}
189+
}
190+
return inputs;
191+
}
192+
193+
private List<Node> GetInputsFromPlayableOutputNode(PlayableOutput h)
194+
{
195+
var inputs = new List<Node>();
196+
if (h.IsOutputValid())
197+
{
198+
Playable playable = h.GetSourcePlayable();
199+
if (playable.IsValid())
119200
{
120-
float weight = h.GetInputWeight(port);
121-
Node node = CreateNodeFromPlayableHandle(playableHandle, weight);
201+
Node node = CreateNodeFromPlayable(playable, 1);
122202
inputs.Add(node);
123203
}
124204
}
125205
return inputs;
126206
}
127207

128-
private PlayableGraphNode CreateNodeFromPlayableHandle(PlayableHandle h, float weight)
208+
private PlayableNode CreateNodeFromPlayable(Playable h, float weight)
209+
{
210+
return new PlayableNode(h, weight, h.GetPlayState() == PlayState.Playing);
211+
}
212+
213+
private PlayableOutputNode CreateNodeFromPlayableOutput(PlayableOutput h)
129214
{
130-
return new PlayableGraphNode(h, weight, h.playState == PlayState.Playing);
215+
return new PlayableOutputNode(h);
131216
}
132217

133-
private static bool HasValidOuputs(PlayableHandle h)
218+
private static bool HasValidOuputs(Playable h)
134219
{
135-
for (int port = 0; port < h.outputCount; ++port)
220+
for (int port = 0; port < h.GetOutputCount(); ++port)
136221
{
137-
PlayableHandle playableHandle = h.GetOutput(port);
138-
if (playableHandle.IsValid())
222+
Playable playable = h.GetOutput(port);
223+
if (playable.IsValid())
139224
{
140225
return true;
141226
}

Assets/Editor/GraphVisualizer/PlayableGraphVisualizerWindow.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using GraphVisualizer;
6-
using UnityEngine.Experimental.Director;
6+
using UnityEngine.Playables;
77
using UnityEditor.Animations;
88

99
public class PlayableGraphVisualizerWindow : EditorWindow, IHasCustomMenu
@@ -67,12 +67,21 @@ private PlayableGraphInfo GetSelectedGraphInToolBar(IList<PlayableGraphInfo> gra
6767
return selectedDirector;
6868
}
6969

70-
private void ShowMessage(string msg)
70+
private static void ShowMessage(string msg)
7171
{
72-
GUIStyle centeredStyle = GUI.skin.GetStyle("Label");
73-
centeredStyle.alignment = TextAnchor.UpperCenter;
74-
int width = 15 * msg.Length;
75-
GUI.Label(new Rect(0.5f * (Screen.width - width), 0.5f * (Screen.height - 50), width, 50), msg, centeredStyle);
72+
GUILayout.BeginVertical();
73+
GUILayout.FlexibleSpace();
74+
75+
GUILayout.BeginHorizontal();
76+
GUILayout.FlexibleSpace();
77+
78+
GUILayout.Label(msg);
79+
80+
GUILayout.FlexibleSpace();
81+
GUILayout.EndHorizontal();
82+
83+
GUILayout.FlexibleSpace();
84+
GUILayout.EndVertical();
7685
}
7786

7887
void Update()
@@ -100,7 +109,6 @@ void OnGUI()
100109
// that are in the current scene.
101110
if (m_AutoScanScene)
102111
{
103-
#if PLAYABLE_DIRECTOR
104112
// This code could be generalized, maybe if we added a IHasPlayableGraph Interface.
105113
IList<PlayableDirector> directors = FindObjectsOfType<PlayableDirector>();
106114
if (directors != null)
@@ -115,8 +123,7 @@ void OnGUI()
115123
}
116124
}
117125
}
118-
#endif
119-
#if ANIMATOR_5_6
126+
120127
IList<Animator> animators = FindObjectsOfType<Animator>();
121128
if (animators != null)
122129
{
@@ -130,7 +137,6 @@ void OnGUI()
130137
}
131138
}
132139
}
133-
#endif
134140
}
135141

136142
if (GraphVisualizerClient.GetGraphs() != null)

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
The PlayableGraph Visualizer window can be used to display any *PlayableGraph*.
44
The tool can be used in both Play and Edit mode and will always reflect the current state of the graph.
55
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.
6+
## Setup ##
7+
- Download the release that matches your current Unity version, or the latest if there your Unity version is more recent than the latest release.
8+
- 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.
9+
## Window ##
10+
- You can open the Timeline Visualizer in **Window > PlayableGraph Visualizer**.
611
## Usage ##
7-
- Copy the content of this repos into a Unity Project.
812
- Open any scene that contains at least one *PlayableGraph*.
913
- Register your *PlayableGraph* with the method GraphVisualizerClient.Show(PlayableGraph, string).
10-
- Open the Timeline Visualizer in **Window > PlayableGraph Visualizer**.
1114
- Select the *PlayableGraph* to display in the top-left combo box.
1215
- Click on a Node to display more information about the associated Playable Handle.
1316
## Notes ##

0 commit comments

Comments
 (0)