|
1 | | -using System.Text; |
2 | | -using GBG.PlayableGraphMonitor.Editor.GraphView; |
| 1 | +using GBG.PlayableGraphMonitor.Editor.GraphView; |
3 | 2 | using GBG.PlayableGraphMonitor.Editor.Utility; |
| 3 | +using System.Text; |
4 | 4 | using UnityEditor.UIElements; |
5 | 5 | using UnityEngine; |
6 | 6 | using UnityEngine.Animations; |
@@ -56,34 +56,47 @@ protected override void OnUpdate(PlayableGraphViewUpdateContext updateContext, b |
56 | 56 | if (updateContext.ShowClipProgressBar) |
57 | 57 | { |
58 | 58 | _progressBar.style.display = DisplayStyle.Flex; |
| 59 | + |
| 60 | + var rawProgress01 = 0.0; |
| 61 | + double progress01; |
59 | 62 | if (clip) |
60 | 63 | { |
| 64 | + var time = Playable.GetTime(); |
| 65 | + rawProgress01 = time / clip.length; |
| 66 | + |
61 | 67 | if (clip.isLooping) |
62 | 68 | { |
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); |
67 | 70 | } |
68 | 71 | else |
69 | 72 | { |
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 | + } |
75 | 86 | } |
76 | 87 | } |
77 | 88 | else |
78 | 89 | { |
79 | | - // Expensive operations |
80 | | - _progressBar.SetValueWithoutNotify(0); |
| 90 | + progress01 = 0; |
81 | 91 | } |
82 | 92 |
|
| 93 | + // Expensive operations |
| 94 | + _progressBar.SetValueWithoutNotify((float)progress01 * 100); |
| 95 | + |
83 | 96 | #if UNITY_2021_1_OR_NEWER |
84 | 97 | // Expensive operations |
85 | 98 | _progressBar.title = updateContext.ShowClipProgressBarTitle |
86 | | - ? $"{_progressBar.value:F2}%" |
| 99 | + ? (rawProgress01 * 100).ToString("F2"); |
87 | 100 | : null; |
88 | 101 | #endif |
89 | 102 | } |
|
0 commit comments