Skip to content

Commit be35fe5

Browse files
committed
Better nodes info display
* Display +/-Inf for node time * Display content more information for some Playables: - AnimationClipPlayable - AnimationLayerMixerPlayable
1 parent 609c653 commit be35fe5

12 files changed

+258
-150
lines changed

Editor/PlayableGraphVisualizer.cs

Lines changed: 8 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
1+
using System.Collections.Generic;
2+
using UnityEngine.Animations;
43
using UnityEngine.Playables;
54

65
namespace GraphVisualizer
76
{
8-
public class SharedPlayableNode : Node
9-
{
10-
public SharedPlayableNode(object content, float weight = 1, bool active = false)
11-
: base(content, weight, active)
12-
{
13-
}
14-
15-
protected static string InfoString(string key, double value)
16-
{
17-
return String.Format(
18-
((Math.Abs(value) < 100000.0) ? "<b>{0}:</b> {1:#.###}" : "<b>{0}:</b> {1:E4}"), key, value);
19-
}
20-
21-
protected static string InfoString(string key, int value)
22-
{
23-
return String.Format("<b>{0}:</b> {1:D}", key, value);
24-
}
25-
26-
protected static string InfoString(string key, object value)
27-
{
28-
return "<b>" + key + ":</b> " + (value ?? "(none)");
29-
}
30-
31-
protected static string RemoveFromEnd(string str, string suffix)
32-
{
33-
if (str.EndsWith(suffix))
34-
{
35-
return str.Substring(0, str.Length - suffix.Length);
36-
}
37-
return str;
38-
}
39-
}
40-
41-
public class PlayableNode : SharedPlayableNode
42-
{
43-
public PlayableNode(Playable content, float weight = 1, bool active = false)
44-
: base(content, weight, active)
45-
{
46-
}
47-
48-
public override Type GetContentType()
49-
{
50-
Playable p = Playable.Null;
51-
try
52-
{
53-
p = (Playable) content;
54-
}
55-
catch
56-
{
57-
// Ignore.
58-
}
59-
return p.IsValid() ? p.GetPlayableType() : null;
60-
}
61-
62-
public override string GetContentTypeShortName()
63-
{
64-
// Remove the extra Playable at the end of the Playable types.
65-
string shortName = base.GetContentTypeShortName();
66-
string cleanName = RemoveFromEnd(shortName, "Playable");
67-
return string.IsNullOrEmpty(cleanName) ? shortName : cleanName;
68-
}
69-
70-
public override string ToString()
71-
{
72-
var sb = new StringBuilder();
73-
74-
sb.AppendLine(InfoString("Handle", GetContentTypeShortName()));
75-
76-
var p = (Playable) content;
77-
sb.AppendLine(InfoString("IsValid", p.IsValid()));
78-
if (p.IsValid())
79-
{
80-
sb.AppendLine(InfoString("IsDone", p.IsDone()));
81-
sb.AppendLine(InfoString("InputCount", p.GetInputCount()));
82-
sb.AppendLine(InfoString("OutputCount", p.GetOutputCount()));
83-
sb.AppendLine(InfoString("PlayState", p.GetPlayState()));
84-
sb.AppendLine(InfoString("Speed", p.GetSpeed()));
85-
sb.AppendLine(InfoString("Duration", p.GetDuration()));
86-
sb.AppendLine(InfoString("Time", p.GetTime()));
87-
//sb.AppendLine(InfoString("Animation", p.animatedProperties));
88-
}
89-
90-
return sb.ToString();
91-
}
92-
}
93-
94-
public class PlayableOutputNode : SharedPlayableNode
95-
{
96-
public PlayableOutputNode(PlayableOutput content)
97-
: base(content, content.GetWeight(), true)
98-
{
99-
}
100-
101-
public override Type GetContentType()
102-
{
103-
PlayableOutput po = PlayableOutput.Null;
104-
try
105-
{
106-
po = (PlayableOutput) content;
107-
}
108-
catch
109-
{
110-
// Ignore.
111-
}
112-
return po.IsOutputValid() ? po.GetPlayableOutputType() : null;
113-
}
114-
115-
public override string GetContentTypeShortName()
116-
{
117-
// Remove the extra Playable at the end of the Playable types.
118-
string shortName = base.GetContentTypeShortName();
119-
string cleanName = RemoveFromEnd(shortName, "PlayableOutput") + "Output";
120-
return string.IsNullOrEmpty(cleanName) ? shortName : cleanName;
121-
}
122-
123-
public override string ToString()
124-
{
125-
var sb = new StringBuilder();
126-
127-
sb.AppendLine(InfoString("Handle", GetContentTypeShortName()));
128-
129-
var po = (PlayableOutput) content;
130-
if (po.IsOutputValid())
131-
{
132-
sb.AppendLine(InfoString("IsValid", po.IsOutputValid()));
133-
sb.AppendLine(InfoString("Weight", po.GetWeight()));
134-
sb.AppendLine(InfoString("SourceOutputPort", po.GetSourceOutputPort()));
135-
}
136-
137-
return sb.ToString();
138-
}
139-
}
140-
1417
public class PlayableGraphVisualizer : Graph
1428
{
1439
private PlayableGraph m_PlayableGraph;
@@ -210,25 +76,17 @@ private List<Node> GetInputsFromPlayableOutputNode(PlayableOutput h)
21076

21177
private PlayableNode CreateNodeFromPlayable(Playable h, float weight)
21278
{
213-
return new PlayableNode(h, weight, h.GetPlayState() == PlayState.Playing);
79+
var type = h.GetPlayableType();
80+
if (type == typeof(AnimationClipPlayable))
81+
return new AnimationClipPlayableNode(h, weight);
82+
if (type == typeof(AnimationLayerMixerPlayable))
83+
return new AnimationLayerMixerPlayableNode(h, weight);
84+
return new PlayableNode(h, weight);
21485
}
21586

21687
private PlayableOutputNode CreateNodeFromPlayableOutput(PlayableOutput h)
21788
{
21889
return new PlayableOutputNode(h);
21990
}
220-
221-
private static bool HasValidOuputs(Playable h)
222-
{
223-
for (int port = 0; port < h.GetOutputCount(); ++port)
224-
{
225-
Playable playable = h.GetOutput(port);
226-
if (playable.IsValid())
227-
{
228-
return true;
229-
}
230-
}
231-
return false;
232-
}
23391
}
23492
}

Editor/PlayableNodes.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Text;
2+
using UnityEngine.Animations;
3+
using UnityEngine.Playables;
4+
5+
namespace GraphVisualizer
6+
{
7+
public class AnimationClipPlayableNode : PlayableNode
8+
{
9+
public AnimationClipPlayableNode(Playable content, float weight = 1.0f)
10+
: base(content, weight)
11+
{
12+
}
13+
14+
public override string ToString()
15+
{
16+
var sb = new StringBuilder();
17+
18+
sb.AppendLine(base.ToString());
19+
20+
var p = (Playable) content;
21+
if (p.IsValid())
22+
{
23+
var acp = (AnimationClipPlayable) p;
24+
var clip = acp.GetAnimationClip();
25+
sb.AppendLine(InfoString("Clip", clip ? clip.name : "(none)"));
26+
if (clip)
27+
{
28+
sb.AppendLine(InfoString("ClipLength", clip.length));
29+
}
30+
sb.AppendLine(InfoString("ApplyFootIK", acp.GetApplyFootIK()));
31+
sb.AppendLine(InfoString("ApplyPlayableIK", acp.GetApplyPlayableIK()));
32+
}
33+
34+
return sb.ToString();
35+
}
36+
}
37+
}

Editor/PlayableNodes/AnimationClipPlayableNode.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Text;
2+
using UnityEngine.Animations;
3+
using UnityEngine.Playables;
4+
5+
namespace GraphVisualizer
6+
{
7+
public class AnimationLayerMixerPlayableNode : PlayableNode
8+
{
9+
public AnimationLayerMixerPlayableNode(Playable content, float weight = 1.0f)
10+
: base(content, weight)
11+
{
12+
}
13+
14+
public override string ToString()
15+
{
16+
var sb = new StringBuilder();
17+
18+
sb.AppendLine(base.ToString());
19+
20+
var p = (Playable) content;
21+
if (p.IsValid())
22+
{
23+
var almp = (AnimationLayerMixerPlayable) p;
24+
for (uint i = 0; i < almp.GetInputCount(); ++i)
25+
sb.AppendLine(InfoString(string.Format("IsLayerAdditive #{0}", i + 1), almp.IsLayerAdditive(i)));
26+
}
27+
28+
return sb.ToString();
29+
}
30+
}
31+
}

Editor/PlayableNodes/AnimationLayerMixerPlayableNode.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/PlayableNodes/PlayableNode.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Text;
3+
using UnityEngine.Playables;
4+
5+
namespace GraphVisualizer
6+
{
7+
public class PlayableNode : SharedPlayableNode
8+
{
9+
public PlayableNode(Playable content, float weight = 1.0f)
10+
: base(content, weight, content.GetPlayState() == PlayState.Playing)
11+
{
12+
}
13+
14+
public override Type GetContentType()
15+
{
16+
Playable p = Playable.Null;
17+
try
18+
{
19+
p = (Playable) content;
20+
}
21+
catch
22+
{
23+
// Ignore.
24+
}
25+
26+
return p.IsValid() ? p.GetPlayableType() : null;
27+
}
28+
29+
public override string GetContentTypeShortName()
30+
{
31+
// Remove the extra Playable at the end of the Playable types.
32+
string shortName = base.GetContentTypeShortName();
33+
string cleanName = RemoveFromEnd(shortName, "Playable");
34+
return string.IsNullOrEmpty(cleanName) ? shortName : cleanName;
35+
}
36+
37+
public override string ToString()
38+
{
39+
var sb = new StringBuilder();
40+
41+
sb.AppendLine(InfoString("Handle", GetContentTypeShortName()));
42+
43+
var p = (Playable) content;
44+
sb.AppendLine(InfoString("IsValid", p.IsValid()));
45+
if (p.IsValid())
46+
{
47+
sb.AppendLine(InfoString("IsDone", p.IsDone()));
48+
sb.AppendLine(InfoString("InputCount", p.GetInputCount()));
49+
sb.AppendLine(InfoString("OutputCount", p.GetOutputCount()));
50+
sb.AppendLine(InfoString("PlayState", p.GetPlayState()));
51+
sb.AppendLine(InfoString("Speed", p.GetSpeed()));
52+
sb.AppendLine(InfoString("Duration", p.GetDuration()));
53+
sb.AppendLine(InfoString("Time", p.GetTime()));
54+
}
55+
56+
return sb.ToString();
57+
}
58+
}
59+
}

Editor/PlayableNodes/PlayableNode.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Text;
3+
using UnityEngine.Playables;
4+
5+
namespace GraphVisualizer
6+
{
7+
public class PlayableOutputNode : SharedPlayableNode
8+
{
9+
public PlayableOutputNode(PlayableOutput content)
10+
: base(content, content.GetWeight(), true)
11+
{
12+
}
13+
14+
public override Type GetContentType()
15+
{
16+
PlayableOutput po = PlayableOutput.Null;
17+
try
18+
{
19+
po = (PlayableOutput) content;
20+
}
21+
catch
22+
{
23+
// Ignore.
24+
}
25+
26+
return po.IsOutputValid() ? po.GetPlayableOutputType() : null;
27+
}
28+
29+
public override string GetContentTypeShortName()
30+
{
31+
// Remove the extra Playable at the end of the Playable types.
32+
string shortName = base.GetContentTypeShortName();
33+
string cleanName = RemoveFromEnd(shortName, "PlayableOutput") + "Output";
34+
return string.IsNullOrEmpty(cleanName) ? shortName : cleanName;
35+
}
36+
37+
public override string ToString()
38+
{
39+
var sb = new StringBuilder();
40+
41+
sb.AppendLine(InfoString("Handle", GetContentTypeShortName()));
42+
43+
var po = (PlayableOutput) content;
44+
if (po.IsOutputValid())
45+
{
46+
sb.AppendLine(InfoString("IsValid", po.IsOutputValid()));
47+
sb.AppendLine(InfoString("Weight", po.GetWeight()));
48+
sb.AppendLine(InfoString("SourceOutputPort", po.GetSourceOutputPort()));
49+
}
50+
51+
return sb.ToString();
52+
}
53+
}
54+
}

Editor/PlayableNodes/PlayableOutputNode.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)