Skip to content

Commit 8bfea8b

Browse files
authored
feat: Improve UI
1 parent aae7ee0 commit 8bfea8b

6 files changed

Lines changed: 44 additions & 15 deletions

File tree

Editor/Scripts/GraphView/PlayableGraphView.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class PlayableGraphViewUpdateContext
3131
[SerializeField]
3232
public bool ShowClipProgressBar = true;
3333

34+
[SerializeField]
35+
public bool ShowClipProgressBarTitle;
36+
3437
[NonSerialized]
3538
public IReadOnlyDictionary<PlayableHandle, string> NodeExtraLabelTable;
3639
}

Editor/Scripts/Node/AnimationClipPlayableNode.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,21 @@ protected override void OnUpdate(PlayableGraphViewUpdateContext updateContext, b
5151
var clip = clipPlayable.GetAnimationClip();
5252
_clipField.SetValueWithoutNotify(clip);
5353

54+
// MEMO KEYWORD: CLIP_PROGRESS
5455
if (updateContext.ShowClipProgressBar)
5556
{
5657
_progressBar.style.display = DisplayStyle.Flex;
5758
if (clip)
5859
{
5960
if (clip.isLooping)
6061
{
61-
var progress = (float)(Playable.GetTime() / clip.length) % 1.0f * 100;
62+
var progress = (float)(Playable.GetTime() / clip.length % 1.0f * 100);
6263
// Expensive operations
6364
_progressBar.SetValueWithoutNotify(progress);
6465
}
6566
else
6667
{
67-
var progress = (float)(Playable.GetTime() / clip.length) * 100;
68+
var progress = (float)(Playable.GetTime() / clip.length * 100);
6869
progress = Mathf.Clamp(progress, 0, 100);
6970
// Expensive operations
7071
_progressBar.SetValueWithoutNotify(progress);
@@ -75,6 +76,13 @@ protected override void OnUpdate(PlayableGraphViewUpdateContext updateContext, b
7576
// Expensive operations
7677
_progressBar.SetValueWithoutNotify(0);
7778
}
79+
80+
#if UNITY_2021_1_OR_NEWER
81+
// Expensive operations
82+
_progressBar.title = updateContext.ShowClipProgressBarTitle
83+
? $"{_progressBar.value:F2}%"
84+
: null;
85+
#endif
7886
}
7987
else
8088
{

Editor/Scripts/Node/AudioClipPlayableNode.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ protected override void OnUpdate(PlayableGraphViewUpdateContext updateContext, b
5050
var clip = clipPlayable.GetClip();
5151
_clipField.SetValueWithoutNotify(clip);
5252

53+
// MEMO KEYWORD: CLIP_PROGRESS
5354
if (updateContext.ShowClipProgressBar)
5455
{
5556
_progressBar.style.display = DisplayStyle.Flex;
5657
if (clip)
5758
{
5859
if (clipPlayable.GetLooped())
5960
{
60-
var progress = (float)(Playable.GetTime() / clip.length) % 1.0f * 100;
61+
var progress = (float)(Playable.GetTime() / clip.length % 1.0f * 100);
6162
// Expensive operations
6263
_progressBar.SetValueWithoutNotify(progress);
6364
}
6465
else
6566
{
66-
var progress = (float)(Playable.GetTime() / clip.length) * 100;
67+
var progress = (float)(Playable.GetTime() / clip.length * 100);
6768
progress = Mathf.Clamp(progress, 0, 100);
6869
// Expensive operations
6970
_progressBar.SetValueWithoutNotify(progress);
@@ -74,6 +75,13 @@ protected override void OnUpdate(PlayableGraphViewUpdateContext updateContext, b
7475
// Expensive operations
7576
_progressBar.SetValueWithoutNotify(0);
7677
}
78+
79+
#if UNITY_2021_1_OR_NEWER
80+
// Expensive operations
81+
_progressBar.title = updateContext.ShowClipProgressBarTitle
82+
? $"{_progressBar.value:F2}%"
83+
: null;
84+
#endif
7785
}
7886
else
7987
{

Editor/Scripts/Window/PlayableGraphMonitorWindow.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
31
using GBG.PlayableGraphMonitor.Editor.GraphView;
42
using GBG.PlayableGraphMonitor.Editor.Utility;
3+
using System.Collections.Generic;
54
using UnityEditor;
65
using UnityEngine;
76
using UnityEngine.Playables;
@@ -127,12 +126,13 @@ private void OnDisable()
127126

128127
private void Update()
129128
{
130-
UpdateGraphView();
129+
// TODO FIXME CLIP_PROGRESS: If I reverse the order of these two method calls, the progress bar on the Clip node will become inaccurate. Why???
131130
DrawInspector();
131+
UpdateGraphView();
132132

133133
if (_updateNodesMovability)
134134
{
135-
_graphView.SetNodesMovability(_refreshRate == RefreshRate.Manual);
135+
_graphView.SetNodesMovability(!_autoLayoutToggle.value);
136136
}
137137
}
138138

@@ -220,10 +220,20 @@ private void OnDestroyingGraph(PlayableGraph graph)
220220

221221
void IHasCustomMenu.AddItemsToMenu(GenericMenu menu)
222222
{
223-
menu.AddItem(new GUIContent("Keep updating edges when mouse leave GraphView(will degrade performance)"),
223+
#if UNITY_2021_1_OR_NEWER
224+
menu.AddItem(new GUIContent("Show clip progress bar title (will degrade performance)"),
225+
_viewUpdateContext.ShowClipProgressBarTitle, OnToggleShowClipProgressBarTitle);
226+
#endif
227+
228+
menu.AddItem(new GUIContent("Keep updating edges when mouse leave GraphView (will degrade performance)"),
224229
_viewUpdateContext.KeepUpdatingEdges, OnToggleKeepUpdatingEdges);
225230
}
226231

232+
private void OnToggleShowClipProgressBarTitle()
233+
{
234+
_viewUpdateContext.ShowClipProgressBarTitle = !_viewUpdateContext.ShowClipProgressBarTitle;
235+
}
236+
227237
private void OnToggleKeepUpdatingEdges()
228238
{
229239
_viewUpdateContext.KeepUpdatingEdges = !_viewUpdateContext.KeepUpdatingEdges;

Editor/Scripts/Window/PlayableGraphMonitorWindow_Toolbar.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public enum RefreshRate
1818
[InspectorName("Max FPS")]
1919
Fps_Max = 0,
2020

21-
[InspectorName("50 FPS")]
22-
Fps_50 = 20,
21+
[InspectorName("30 FPS")]
22+
Fps_50 = 33,
2323

2424
[InspectorName("20 FPS")]
2525
Fps_20 = 50,
@@ -116,10 +116,10 @@ private void CreateToolbar()
116116
_autoLayoutToggle.RegisterValueChangedCallback(ToggleAutoLayout);
117117
_autoLayoutLabel = _autoLayoutToggle.Q<TextElement>(className: "unity-text-element");
118118
_autoLayoutLabel.style.color = _viewUpdateContext.AutoLayout ? NormalTextColor : NotableTextColor;
119+
_updateNodesMovability = true;
119120
_toolbar.Add(_autoLayoutToggle);
120121

121122
// Refresh rate popup
122-
_updateNodesMovability = _refreshRate == RefreshRate.Manual;
123123
_refreshRateField = new EnumField(_refreshRate)
124124
{
125125
tooltip = "Max refresh rate.",
@@ -216,6 +216,8 @@ private void ToggleAutoLayout(ChangeEvent<bool> evt)
216216
_autoLayoutLabel.style.color = _viewUpdateContext.AutoLayout
217217
? NormalTextColor
218218
: NotableTextColor;
219+
220+
_updateNodesMovability = true;
219221
}
220222

221223
private void OnRefreshRateChanged(ChangeEvent<Enum> evt)
@@ -229,8 +231,6 @@ private void OnRefreshRateChanged(ChangeEvent<Enum> evt)
229231
_refreshRateLabel.style.color = _refreshRate == RefreshRate.Manual
230232
? NotableTextColor
231233
: NormalTextColor;
232-
233-
_updateNodesMovability = true;
234234
}
235235

236236
private void OnManualUpdateButtonClicked()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.greenbamboogames.playablegraphmonitor",
3-
"version": "2.5.1",
3+
"version": "2.5.2",
44
"displayName": "PlayableGraph Monitor!",
55
"description": "PlayableGraph monitor.",
66
"unity": "2019.4",

0 commit comments

Comments
 (0)