Skip to content

Commit 05868b5

Browse files
committed
feat: add node inspector & improve toolbar
1 parent 1a7393a commit 05868b5

11 files changed

Lines changed: 327 additions & 27 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Text;
2+
using UnityEngine.Animations;
3+
using UnityEngine.Playables;
4+
5+
namespace GBG.PlayableGraphMonitor.Editor.Node
6+
{
7+
public class AnimationClipPlayableNode : PlayableNode
8+
{
9+
public AnimationClipPlayableNode(Playable playable) : base(playable)
10+
{
11+
}
12+
13+
14+
protected override void AppendStateDescriptions(StringBuilder descBuilder)
15+
{
16+
base.AppendStateDescriptions(descBuilder);
17+
18+
if (Playable.IsValid())
19+
{
20+
var clipPlayable = (AnimationClipPlayable)Playable;
21+
descBuilder.Append("ApplyFootIK: ").AppendLine(clipPlayable.GetApplyFootIK().ToString())
22+
.Append("ApplyPlayableIK: ").AppendLine(clipPlayable.GetApplyPlayableIK().ToString())
23+
.AppendLine();
24+
25+
var clip = clipPlayable.GetAnimationClip();
26+
descBuilder.Append("Clip: ").AppendLine(clip ? clip.name : "None");
27+
if (clip)
28+
{
29+
descBuilder.Append("IsLooping: ").AppendLine(clip.isLooping.ToString())
30+
.Append("Length: ").Append(clip.length.ToString("F3")).AppendLine("(s)");
31+
}
32+
}
33+
}
34+
}
35+
}

Editor/Scripts/Node/AnimationClipPlayableNode.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.
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 GBG.PlayableGraphMonitor.Editor.Node
6+
{
7+
public class AnimationLayerMixerPlayableNode : PlayableNode
8+
{
9+
public AnimationLayerMixerPlayableNode(Playable playable) : base(playable)
10+
{
11+
}
12+
13+
14+
protected override void AppendStateDescriptions(StringBuilder descBuilder)
15+
{
16+
base.AppendStateDescriptions(descBuilder);
17+
18+
if (Playable.IsValid())
19+
{
20+
descBuilder.AppendLine();
21+
22+
var layerMixer = (AnimationLayerMixerPlayable)Playable;
23+
for (uint i = 0; i < layerMixer.GetInputCount(); i++)
24+
{
25+
descBuilder.Append("#").Append(i.ToString()).Append(" IsLayerAdditive: ")
26+
.AppendLine(layerMixer.IsLayerAdditive(i).ToString());
27+
}
28+
}
29+
}
30+
}
31+
}

Editor/Scripts/Node/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/Scripts/Node/GraphViewNode.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Text;
23
using UnityEditor.Experimental.GraphView;
34
using UnityEngine;
45
using UEdge = UnityEditor.Experimental.GraphView.Edge;
@@ -57,6 +58,30 @@ public abstract class GraphViewNode : UNode
5758

5859
public virtual void Update() { }
5960

61+
#region Description
62+
63+
private StringBuilder _descBuilder;
64+
65+
66+
public string GetStateDescription()
67+
{
68+
if (_descBuilder == null)
69+
{
70+
_descBuilder = new StringBuilder();
71+
}
72+
73+
_descBuilder.Clear();
74+
AppendStateDescriptions(_descBuilder);
75+
76+
return _descBuilder.ToString();
77+
}
78+
79+
80+
protected abstract void AppendStateDescriptions(StringBuilder descBuilder);
81+
82+
83+
#endregion
84+
6085

6186
#region Hierarchy
6287

Editor/Scripts/Node/PlayableNode.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GBG.PlayableGraphMonitor.Editor.Utility;
22
using System;
3+
using System.Text;
34
using UnityEditor.Experimental.GraphView;
45
using UnityEngine.Playables;
56

@@ -135,5 +136,30 @@ private void CreatePorts()
135136
InternalOutputPorts.Add(outputPort);
136137
}
137138
}
139+
140+
141+
#region Description
142+
143+
protected override void AppendStateDescriptions(StringBuilder descBuilder)
144+
{
145+
descBuilder.Append("Type: ").AppendLine(PlayableType.Name)
146+
.Append("IsValid: ").AppendLine(Playable.IsValid().ToString());
147+
if (Playable.IsValid())
148+
{
149+
descBuilder.Append("IsDone: ").AppendLine(Playable.IsDone().ToString())
150+
.Append("PlayState: ").AppendLine(Playable.GetPlayState().ToString())
151+
.Append("Speed: ").Append(Playable.GetSpeed().ToString("F3")).AppendLine("x")
152+
.Append("Duration: ").Append(Playable.DurationToString()).AppendLine("(s)")
153+
.Append("Time: ").Append(Playable.GetTime().ToString("F3")).AppendLine("(s)");
154+
for (int i = 0; i < Playable.GetInputCount(); i++)
155+
{
156+
descBuilder.Append("#").Append(i.ToString()).Append(" InputWeight: ")
157+
.AppendLine(Playable.GetInputWeight(i).ToString("F3"));
158+
}
159+
descBuilder.Append("OutputCount: ").AppendLine(Playable.GetOutputCount().ToString());
160+
}
161+
}
162+
163+
#endregion
138164
}
139-
}
165+
}

Editor/Scripts/Node/PlayableNodeFactory.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,22 @@ public static PlayableNode CreateNode(Playable playable)
1616
.Remove(playableTypeName.Length - PlayableHeader.Length);
1717
var nodeTitle = $"{PlayableHeader}\n{playableTypeSortName}";
1818

19+
// create node by playable type
1920
PlayableNode playableNode;
20-
21-
// todo create node by playable type
22-
2321
if (playableType == typeof(AnimationClipPlayable))
2422
{
25-
//goto SET_NODE_TITLE;
23+
playableNode = new AnimationClipPlayableNode(playable);
2624
}
27-
28-
if (playableType == typeof(AnimationMixerPlayable))
25+
else if (playableType == typeof(AnimationLayerMixerPlayable))
2926
{
30-
27+
playableNode = new AnimationLayerMixerPlayableNode(playable);
3128
}
32-
33-
if (playableType == typeof(AnimationLayerMixerPlayable))
29+
else
3430
{
35-
31+
// default node
32+
playableNode = new PlayableNode(playable);
3633
}
3734

38-
// ...
39-
40-
// default node
41-
playableNode = new PlayableNode(playable);
42-
43-
SET_NODE_TITLE:
4435
playableNode.title = nodeTitle;
4536
playableNode.SetNodeStyle(playable.GetPlayableNodeColor());
4637

Editor/Scripts/Node/PlayableOutputNode.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using GBG.PlayableGraphMonitor.Editor.Utility;
1+
using System.Text;
22
using UnityEditor.Experimental.GraphView;
3+
using UnityEditor.Playables;
34
using UnityEngine;
45
using UnityEngine.Playables;
56

@@ -101,5 +102,24 @@ private void CreatePorts()
101102
inputContainer.Add(inputPort);
102103
InternalInputPorts.Add(inputPort);
103104
}
105+
106+
107+
#region Description
108+
109+
protected override void AppendStateDescriptions(StringBuilder descBuilder)
110+
{
111+
descBuilder.Append("Type: ").AppendLine(PlayableOutput.GetPlayableOutputType().Name)
112+
.Append("IsValid: ").AppendLine(PlayableOutput.IsOutputValid().ToString());
113+
if (PlayableOutput.IsOutputValid())
114+
{
115+
descBuilder.Append("Name: ").AppendLine(PlayableOutput.GetEditorName())
116+
.Append("Weight: ").AppendLine(PlayableOutput.GetWeight().ToString("F3"))
117+
.Append("ReferenceObject: ").AppendLine(PlayableOutput.GetReferenceObject()?.name ?? "Null")
118+
.Append("UserData: ").AppendLine(PlayableOutput.GetUserData()?.name ?? "Null")
119+
.Append("SourceOutputPort: ").AppendLine(PlayableOutput.GetSourceOutputPort().ToString());
120+
}
121+
}
122+
123+
#endregion
104124
}
105125
}

Editor/Scripts/Node/PlayableOutputNodeFactory.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ public static PlayableOutputNode CreateNode(PlayableOutput playableOutput)
1919
var nodeTitle = $"{PlayableOutputHeader}\n" +
2020
$"{playableOutputTypeSortName} ({playableOutputEditorName})";
2121

22-
if (playableOutputType == typeof(AnimationPlayableOutput))
23-
{
24-
25-
}
26-
27-
// todo create node by playable output type
28-
2922
// default node
3023
var playableOutputNode = new PlayableOutputNode(playableOutput)
3124
{

Editor/Scripts/Utility/GraphTool.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GBG.PlayableGraphMonitor.Editor.Node;
22
using System;
33
using System.Collections.Generic;
4+
using UnityEditor;
45
using UnityEngine;
56
using UnityEngine.Animations;
67
using UnityEngine.Playables;
@@ -29,6 +30,14 @@ public static bool IsEqual(ref PlayableGraph a, ref PlayableGraph b)
2930
return nameA.Equals(nameB);
3031
}
3132

33+
public static string DurationToString(this Playable playable, string format = "F3")
34+
{
35+
var duration = playable.GetDuration();
36+
var durationStr = duration > float.MaxValue ? "+Inf" : duration.ToString(format);
37+
38+
return durationStr;
39+
}
40+
3241

3342
public static void SetNodeStyle(this GraphViewNode node, Color nodeColor,
3443
float titleFontSize = 15, Color? titleColor = null)
@@ -46,6 +55,35 @@ public static void SetNodeStyle(this GraphViewNode node, Color nodeColor,
4655
public const float ColorAlphaFactor = 1f / 9;
4756

4857

58+
public static Color GetButtonBackgroundColor(bool isChecked)
59+
{
60+
if (isChecked)
61+
{
62+
return EditorGUIUtility.isProSkin ?
63+
new Color32(70, 96, 124, 255) : // dark
64+
new Color32(150, 195, 251, 255); // light
65+
66+
}
67+
68+
return EditorGUIUtility.isProSkin ?
69+
new Color32(88, 88, 88, 255) : // dark
70+
new Color32(228, 228, 228, 255); // light
71+
}
72+
73+
public static Color GetNodeInspectorBackgroundColor()
74+
{
75+
return EditorGUIUtility.isProSkin ?
76+
new Color32(50, 50, 50, 255) : // dark
77+
new Color32(175, 175, 175, 255); // light
78+
}
79+
80+
public static Color GetNodeInspectorTextColor()
81+
{
82+
return EditorGUIUtility.isProSkin ?
83+
new Color32(255, 255, 255, 255) : // dark
84+
new Color32(0, 0, 0, 255); // light
85+
}
86+
4987
public static Color GetPortColor(float weight)
5088
{
5189
var alpha = (weight + ColorAlphaFactor) / (1 + ColorAlphaFactor);

0 commit comments

Comments
 (0)