Skip to content

Commit 67d0c0e

Browse files
committed
feat: Improve the progress bar UI of the animation and audio clip node
1 parent c0b7015 commit 67d0c0e

3 files changed

Lines changed: 55 additions & 29 deletions

File tree

Editor/Scripts/Node/AnimationClipPlayableNode.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Text;
2-
using GBG.PlayableGraphMonitor.Editor.GraphView;
1+
using GBG.PlayableGraphMonitor.Editor.GraphView;
32
using GBG.PlayableGraphMonitor.Editor.Utility;
3+
using System.Text;
44
using UnityEditor.UIElements;
55
using UnityEngine;
66
using UnityEngine.Animations;
@@ -56,34 +56,47 @@ protected override void OnUpdate(PlayableGraphViewUpdateContext updateContext, b
5656
if (updateContext.ShowClipProgressBar)
5757
{
5858
_progressBar.style.display = DisplayStyle.Flex;
59+
60+
var rawProgress01 = 0.0;
61+
double progress01;
5962
if (clip)
6063
{
64+
var time = Playable.GetTime();
65+
rawProgress01 = time / clip.length;
66+
6167
if (clip.isLooping)
6268
{
63-
var progress = Playable.GetTime() / clip.length;
64-
progress = GraphTool.Wrap01(progress) * 100;
65-
// Expensive operations
66-
_progressBar.SetValueWithoutNotify((float)progress);
69+
progress01 = GraphTool.Wrap01(rawProgress01);
6770
}
6871
else
6972
{
70-
var progress = Playable.GetTime() / clip.length;
71-
progress = Mathf.Clamp((float)progress, -1, 1);
72-
progress = GraphTool.Wrap01(progress) * 100;
73-
// Expensive operations
74-
_progressBar.SetValueWithoutNotify((float)progress);
73+
var speed = Playable.GetSpeed();
74+
if (speed > 0 && time >= clip.length)
75+
{
76+
progress01 = 1;
77+
}
78+
else if (speed < 0 && time <= 0)
79+
{
80+
progress01 = 0;
81+
}
82+
else
83+
{
84+
progress01 = GraphTool.Wrap01(rawProgress01);
85+
}
7586
}
7687
}
7788
else
7889
{
79-
// Expensive operations
80-
_progressBar.SetValueWithoutNotify(0);
90+
progress01 = 0;
8191
}
8292

93+
// Expensive operations
94+
_progressBar.SetValueWithoutNotify((float)progress01 * 100);
95+
8396
#if UNITY_2021_1_OR_NEWER
8497
// Expensive operations
8598
_progressBar.title = updateContext.ShowClipProgressBarTitle
86-
? $"{_progressBar.value:F2}%"
99+
? (rawProgress01 * 100).ToString("F2");
87100
: null;
88101
#endif
89102
}

Editor/Scripts/Node/AudioClipPlayableNode.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Text;
2-
using GBG.PlayableGraphMonitor.Editor.GraphView;
1+
using GBG.PlayableGraphMonitor.Editor.GraphView;
32
using GBG.PlayableGraphMonitor.Editor.Utility;
3+
using System.Text;
44
using UnityEditor.UIElements;
55
using UnityEngine;
66
using UnityEngine.Audio;
@@ -55,34 +55,47 @@ protected override void OnUpdate(PlayableGraphViewUpdateContext updateContext, b
5555
if (updateContext.ShowClipProgressBar)
5656
{
5757
_progressBar.style.display = DisplayStyle.Flex;
58+
59+
var rawProgress01 = 0.0;
60+
double progress01;
5861
if (clip)
5962
{
63+
var time = Playable.GetTime();
64+
rawProgress01 = time / clip.length;
65+
6066
if (clipPlayable.GetLooped())
6167
{
62-
var progress = Playable.GetTime() / clip.length;
63-
progress = GraphTool.Wrap01(progress) * 100;
64-
// Expensive operations
65-
_progressBar.SetValueWithoutNotify((float)progress);
68+
progress01 = GraphTool.Wrap01(rawProgress01);
6669
}
6770
else
6871
{
69-
var progress = Playable.GetTime() / clip.length;
70-
progress = Mathf.Clamp((float)progress, -1, 1);
71-
progress = GraphTool.Wrap01(progress) * 100;
72-
// Expensive operations
73-
_progressBar.SetValueWithoutNotify((float)progress);
72+
var speed = Playable.GetSpeed();
73+
if (speed > 0 && time >= clip.length)
74+
{
75+
progress01 = 1;
76+
}
77+
else if (speed < 0 && time <= 0)
78+
{
79+
progress01 = 0;
80+
}
81+
else
82+
{
83+
progress01 = GraphTool.Wrap01(rawProgress01);
84+
}
7485
}
7586
}
7687
else
7788
{
78-
// Expensive operations
79-
_progressBar.SetValueWithoutNotify(0);
89+
progress01 = 0;
8090
}
8191

92+
// Expensive operations
93+
_progressBar.SetValueWithoutNotify((float)progress01 * 100);
94+
8295
#if UNITY_2021_1_OR_NEWER
8396
// Expensive operations
8497
_progressBar.title = updateContext.ShowClipProgressBarTitle
85-
? $"{_progressBar.value:F2}%"
98+
? (rawProgress01 * 100).ToString("F2");
8699
: null;
87100
#endif
88101
}

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.2",
3+
"version": "2.5.3",
44
"displayName": "PlayableGraph Monitor!",
55
"description": "PlayableGraph monitor.",
66
"unity": "2019.4",

0 commit comments

Comments
 (0)