UnityTimer
UnityTimer copied to clipboard
Is this compatible with editor scripts?
Hey there, I have been trying to find something to give me some easy numeric incrementation in editor scripts and it seemed like this might just do the trick, but I am having a bit of an issue. My designated callback doesn't seem to actually get called when the timer is supposedly completed.
I was trying to test it out by having the following:
private Timer displayTimer;
private void OnInspectorUpdate()
{
if (displayTimer == null || displayTimer.isCompleted) return;
Debug.Log(string.Format("Percentage completed: {0:F4}%", displayTimer.GetRatioComplete() * 100));
Debug.Log(string.Format("Percentage remaining: {0:F4}%", displayTimer.GetRatioRemaining() * 100));
}
void BeginDisplayMsg()
{
displayTimer = Timer.Register(2, BeginFadeOut,
secondsElapsed => { Debug.Log($"Timer ran update callback: {secondsElapsed:F2} seconds"); },
false, true);
}
It seems to run through the timer as it should based on these percentage complete messages and hits 100% but then sits there continually saying its at 100% instead of setting .isComplete or calling my callback.
Percentage completed: 91.2354%
Percentage remaining: 8.7402%
Percentage completed: 98.9746%
Percentage remaining: 1.0010%
(29) Percentage completed: 100.0000%
(29) Percentage remaining: 0.0000%
Is there something I am missing in order to use this in an editor window, or is there any sort of known compatibility issue that I missed? I tried to see if there was any mention of usage in the editor, but I didn't see any.
Thanks, -MH