Skip to content

Commit cd36712

Browse files
committed
feat: Improve UI
1 parent b4af02e commit cd36712

6 files changed

Lines changed: 84 additions & 49 deletions

File tree

Editor/Scripts/Node/AnimationClipPlayableNode.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,39 @@
33
using UnityEngine.Playables;
44
#if UNITY_2021_1_OR_NEWER
55
using UnityEngine.UIElements;
6+
67
#else
78
using UnityEditor.UIElements;
89
#endif
910

1011
namespace GBG.PlayableGraphMonitor.Editor.Node
1112
{
12-
public class AnimationClipPlayableNode : PlayableNode
13+
public sealed class AnimationClipPlayableNode : PlayableNode
1314
{
15+
public override string title
16+
{
17+
get => _mainTitle;
18+
set
19+
{
20+
_mainTitle = value;
21+
var clipPlayable = (AnimationClipPlayable)Playable;
22+
var clip = clipPlayable.GetAnimationClip();
23+
var clipName = clip ? clip.name : "None";
24+
base.title = $"{_mainTitle}\n({clipName})";
25+
}
26+
}
27+
28+
private string _mainTitle;
29+
1430
private readonly ProgressBar _progressBar;
1531

1632

1733
public AnimationClipPlayableNode(Playable playable) : base(playable)
1834
{
35+
title = Playable.GetPlayableType().Name;
36+
var titleLabel = titleContainer.Q<Label>(name: "title-label");
37+
titleLabel.style.maxWidth = 220;
38+
1939
_progressBar = new ProgressBar();
2040
// insert between title and port container
2141
titleContainer.parent.Insert(1, _progressBar);
@@ -58,4 +78,4 @@ protected override void AppendStateDescriptions(StringBuilder descBuilder)
5878
}
5979
}
6080
}
61-
}
81+
}

Editor/Scripts/Node/GraphViewNode.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ protected GraphViewNode()
6161
{
6262
capabilities &= ~Capabilities.Movable;
6363
capabilities &= ~Capabilities.Deletable;
64+
65+
// Hide collapse button
66+
titleButtonContainer.Clear();
67+
var titleLabel = titleContainer.Q<Label>(name: "title-label");
68+
titleLabel.style.marginRight = 6;
6469
}
6570

6671
public virtual void Update()
@@ -139,7 +144,7 @@ protected Port InstantiatePort<TPort>(Direction direction)
139144

140145
public const int HORIZONTAL_SPACE = 80;
141146

142-
public const int VERTICAL_SPACE = 80;
147+
public const int VERTICAL_SPACE = 60;
143148

144149
public static readonly Vector2 StandardNodeSize = new Vector2(400, 150);
145150

Editor/Scripts/Node/PlayableNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override void Update()
5151
continue;
5252
}
5353

54-
// FIXME: A Playable may has multi output ports,
54+
// TODO FIXME: A Playable may has multi output ports,
5555
// and if all these output ports connected to same input port,
5656
// 'i' will be greater than InternalInputs.Count, so there is a check.
5757
if (i < InternalInputs.Count)

Editor/Scripts/Node/PlayableNodeFactory.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ namespace GBG.PlayableGraphMonitor.Editor.Node
66
{
77
public static class PlayableNodeFactory
88
{
9-
public const string PLAYABLE_HEADER = "Playable";
10-
119
public static PlayableNode CreateNode(Playable playable)
1210
{
13-
var playableType = playable.GetPlayableType();
14-
var playableTypeName = playableType.Name;
15-
var playableTypeSortName = playableTypeName
16-
.Remove(playableTypeName.Length - PLAYABLE_HEADER.Length);
17-
var nodeTitle = $"{PLAYABLE_HEADER}\n{playableTypeSortName}";
18-
1911
// create node by playable type
2012
PlayableNode playableNode;
13+
var playableType = playable.GetPlayableType();
2114
if (playableType == typeof(AnimationClipPlayable))
2215
{
2316
playableNode = new AnimationClipPlayableNode(playable);
@@ -32,7 +25,7 @@ public static PlayableNode CreateNode(Playable playable)
3225
playableNode = new PlayableNode(playable);
3326
}
3427

35-
playableNode.title = nodeTitle;
28+
playableNode.title = playableType.Name;
3629
playableNode.SetNodeStyle(playable.GetPlayableNodeColor());
3730

3831
return playableNode;

Editor/Scripts/Node/PlayableOutputNodeFactory.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,15 @@ namespace GBG.PlayableGraphMonitor.Editor.Node
66
{
77
public static class PlayableOutputNodeFactory
88
{
9-
public const string PLAYABLE_OUTPUT_HEADER = "PlayableOutput";
10-
119
public static PlayableOutputNode CreateNode(PlayableOutput playableOutput)
1210
{
13-
var playableOutputType = playableOutput.GetPlayableOutputType();
14-
var playableOutputTypeName = playableOutputType.Name;
15-
var playableOutputTypeSortName = playableOutputTypeName
16-
.Remove(playableOutputTypeName.Length - PLAYABLE_OUTPUT_HEADER.Length);
11+
var playableOutputTypeName = playableOutput.GetPlayableOutputType().Name;
1712
var playableOutputEditorName = playableOutput.GetEditorName();
18-
var nodeTitle = $"{PLAYABLE_OUTPUT_HEADER}\n" +
19-
$"{playableOutputTypeSortName} ({playableOutputEditorName})";
2013

2114
// default node
2215
var playableOutputNode = new PlayableOutputNode(playableOutput)
2316
{
24-
title = nodeTitle,
17+
title = $"{playableOutputTypeName}\n({playableOutputEditorName})",
2518
};
2619
playableOutputNode.SetNodeStyle(playableOutput.GetPlayableOutputNodeColor());
2720

Editor/Scripts/Utility/GraphTool.cs

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using GBG.PlayableGraphMonitor.Editor.Node;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
3+
using GBG.PlayableGraphMonitor.Editor.Node;
44
using UnityEditor;
55
using UnityEngine;
66
using UnityEngine.Animations;
7+
using UnityEngine.Audio;
78
using UnityEngine.Playables;
89
using UnityEngine.UIElements;
910
using URandom = UnityEngine.Random;
@@ -65,26 +66,27 @@ public static Color GetPortColor(float weight)
6566
#endregion
6667

6768

68-
6969
public static Color GetButtonBackgroundColor(bool isChecked)
7070
{
7171
if (isChecked)
7272
{
73-
return EditorGUIUtility.isProSkin ?
74-
new Color32(70, 96, 124, 255) : // dark
73+
return EditorGUIUtility.isProSkin
74+
? new Color32(70, 96, 124, 255)
75+
: // dark
7576
new Color32(150, 195, 251, 255); // light
76-
7777
}
7878

79-
return EditorGUIUtility.isProSkin ?
80-
new Color32(88, 88, 88, 255) : // dark
79+
return EditorGUIUtility.isProSkin
80+
? new Color32(88, 88, 88, 255)
81+
: // dark
8182
new Color32(228, 228, 228, 255); // light
8283
}
8384

8485
public static Color GetNodeInspectorBackgroundColor()
8586
{
86-
return EditorGUIUtility.isProSkin ?
87-
new Color32(50, 50, 50, 255) : // dark
87+
return EditorGUIUtility.isProSkin
88+
? new Color32(50, 50, 50, 255)
89+
: // dark
8890
new Color32(175, 175, 175, 255); // light
8991
}
9092

@@ -93,8 +95,9 @@ public static Color GetNodeInspectorBackgroundColor()
9395

9496
public static Color GetNodeInspectorTextColor()
9597
{
96-
return EditorGUIUtility.isProSkin ?
97-
new Color32(255, 255, 255, 255) : // dark
98+
return EditorGUIUtility.isProSkin
99+
? new Color32(255, 255, 255, 255)
100+
: // dark
98101
new Color32(0, 0, 0, 255); // light
99102
}
100103

@@ -108,14 +111,18 @@ public static Color GetPlayableOutputNodeColor(this ref PlayableOutput playableO
108111
{
109112
if (playableOutput.IsPlayableOutputOfType<AnimationPlayableOutput>())
110113
{
111-
return new Color32(0, 255, 255, 255);
114+
return new Color32(0, 240, 255, 255);
112115
}
113116

114-
if (playableOutput.IsPlayableOutputOfType<ScriptPlayableOutput>())
117+
if (playableOutput.IsPlayableOutputOfType<AudioPlayableOutput>())
115118
{
116-
return new Color32(0, 204, 255, 255);
119+
return new Color32(0, 190, 255, 255);
117120
}
118121

122+
if (playableOutput.IsPlayableOutputOfType<ScriptPlayableOutput>())
123+
{
124+
return new Color32(0, 140, 255, 255);
125+
}
119126

120127
return GetRandomColorForType(playableOutput.GetPlayableOutputType());
121128
}
@@ -125,22 +132,39 @@ public static Color GetPlayableNodeColor(this ref Playable playable)
125132
{
126133
if (playable.IsPlayableOfType<AnimationClipPlayable>())
127134
{
128-
return new Color32(0, 255, 51, 255);
135+
return new Color32(0, 255, 25, 255);
136+
}
137+
138+
// Audio
139+
if (playable.IsPlayableOfType<AudioClipPlayable>())
140+
{
141+
return new Color32(0, 255, 60, 255);
129142
}
130143

131144
if (playable.IsPlayableOfType<AnimationMixerPlayable>())
132145
{
133-
return new Color32(0, 255, 102, 255);
146+
return new Color32(0, 255, 95, 255);
147+
}
148+
149+
// Audio
150+
if (playable.IsPlayableOfType<AudioMixerPlayable>())
151+
{
152+
return new Color32(0, 255, 130, 255);
134153
}
135154

136155
if (playable.IsPlayableOfType<AnimationLayerMixerPlayable>())
137156
{
138-
return new Color32(0, 255, 153, 255);
157+
return new Color32(0, 255, 165, 255);
139158
}
140159

141160
if (playable.IsPlayableOfType<AnimationScriptPlayable>())
142161
{
143-
return new Color32(0, 255, 204, 255);
162+
return new Color32(0, 255, 200, 255);
163+
}
164+
165+
if (playable.IsPlayableOfType<AnimatorControllerPlayable>())
166+
{
167+
return new Color32(0, 255, 235, 255);
144168
}
145169

146170
return GetRandomColorForType(playable.GetPlayableType());
@@ -153,13 +177,13 @@ public static Color GetPlayableNodeColor(this ref Playable playable)
153177
// reserve (0, 255, ?, 255) for Playable nodes
154178
public static readonly IReadOnlyList<Color32> ColorPool = new Color32[]
155179
{
156-
new Color32(255,0,255,255), new Color32(255,0,153,255),
157-
new Color32(153,255,0,255), new Color32(204,255,0,255),
158-
new Color32(255,255,0,255), new Color32(255,204,0,255),
159-
new Color32(255,153,0,255), new Color32(255,102,0,255),
160-
new Color32(153,204,255,255), new Color32(153,255,102,255),
161-
new Color32(153,255,153,255), new Color32(153,255,204,255),
162-
new Color32(204,255,102,255), new Color32(204,255,255,255),
180+
new Color32(255, 0, 255, 255), new Color32(255, 0, 153, 255),
181+
new Color32(153, 255, 0, 255), new Color32(204, 255, 0, 255),
182+
new Color32(255, 255, 0, 255), new Color32(255, 204, 0, 255),
183+
new Color32(255, 153, 0, 255), new Color32(255, 102, 0, 255),
184+
new Color32(153, 204, 255, 255), new Color32(153, 255, 102, 255),
185+
new Color32(153, 255, 153, 255), new Color32(153, 255, 204, 255),
186+
new Color32(204, 255, 102, 255), new Color32(204, 255, 255, 255),
163187
};
164188

165189
private static readonly Dictionary<Type, Color32> _colorCache = new Dictionary<Type, Color32>();
@@ -183,4 +207,4 @@ public static void ClearGlobalCache()
183207
_colorCache.Clear();
184208
}
185209
}
186-
}
210+
}

0 commit comments

Comments
 (0)