From 2d42d51dc624d52a398f92b33b67e2220736f8e1 Mon Sep 17 00:00:00 2001 From: via57 <65577279+via5@users.noreply.github.com> Date: Fri, 12 Mar 2021 13:10:30 -0500 Subject: [PATCH] added time remaining storable --- src/AtomAnimations/AtomAnimation.cs | 20 ++++++++++++++++++++ src/AtomPlugin.cs | 7 +++++++ src/Common/StorableNames.cs | 1 + 3 files changed, 28 insertions(+) diff --git a/src/AtomAnimations/AtomAnimation.cs b/src/AtomAnimations/AtomAnimation.cs index 99d06919..41473ff3 100644 --- a/src/AtomAnimations/AtomAnimation.cs +++ b/src/AtomAnimations/AtomAnimation.cs @@ -69,6 +69,26 @@ public float playTime } } + public float timeRemaining + { + get + { + for (var i = 0; i < clips.Count; ++i) + { + var clip = clips[i]; + + if (clip.playbackEnabled) + { + var length = clip.animationLength; + var time = clip.clipTime; + return length - time; + } + } + + return 0; + } + } + private float _speed = 1f; public float speed { diff --git a/src/AtomPlugin.cs b/src/AtomPlugin.cs index 8dccb8fe..5540e799 100644 --- a/src/AtomPlugin.cs +++ b/src/AtomPlugin.cs @@ -41,6 +41,7 @@ public class AtomPlugin : MVRScript, IAtomPlugin public JSONStorableFloat speedJSON { get; private set; } public JSONStorableBool lockedJSON { get; private set; } public JSONStorableBool pausedJSON { get; private set; } + public JSONStorableFloat timeRemainingJSON { get; private set; } private JSONStorableFloat _scrubberAnalogControlJSON; private bool _scrubbing = false; @@ -135,6 +136,7 @@ public void Update() { scrubberJSON.valNoCallback = animationEditContext.clipTime; timeJSON.valNoCallback = animation.playTime; + timeRemainingJSON.valNoCallback = animation.timeRemaining; } if (_scrubberAnalogControlJSON.val != 0) @@ -304,6 +306,10 @@ public void InitStorables() }; RegisterBool(isPlayingJSON); + + timeRemainingJSON = new JSONStorableFloat(StorableNames.TimeRemaining, 0f, 0f, float.MaxValue); + RegisterFloat(timeRemainingJSON); + stopJSON = new JSONStorableAction(StorableNames.Stop, () => { if (animation == null) return; @@ -703,6 +709,7 @@ private void OnEditorSettingsChanged(string propertyName) private void OnIsPlayingChanged(AtomAnimationClip clip) { isPlayingJSON.valNoCallback = animation.isPlaying; + timeRemainingJSON.valNoCallback = animation.isPlaying ? animation.timeRemaining : 0; _freeControllerHook.enabled = !animation.isPlaying; peers.SendPlaybackState(clip); } diff --git a/src/Common/StorableNames.cs b/src/Common/StorableNames.cs index cc34357b..b2205b4b 100644 --- a/src/Common/StorableNames.cs +++ b/src/Common/StorableNames.cs @@ -10,6 +10,7 @@ public static class StorableNames public const string Play = "Play"; public const string PlayIfNotPlaying = "Play If Not Playing"; public const string IsPlaying = "Is Playing"; + public const string TimeRemaining = "Time Remaining"; public const string Stop = "Stop"; public const string StopIfPlaying = "Stop If Playing"; public const string StopAndReset = "Stop And Reset";