StansAssets / com.stansassets.foundation

Collection of utility methods, design patterns, and extensions for Unity.
https://stansassets.com/
MIT License
129 stars 12 forks source link

TimeUtility relies on DateTime #99

Open soraphis opened 2 years ago

soraphis commented 2 years ago

https://github.com/StansAssets/com.stansassets.foundation/blob/b3332055c35bb65162e22570b14c06d59ff4155e/Runtime/Utilities/TimeUtility.cs#L20

the TimeUtility class is based on DateTime, which means it breaks when pausing the play mode in the editor (timers should not proceed while paused).

Relying on Time.time OR Time.unscaledTime would pause if the game is paused in the editor (or even paused via timeScale in game, for Time.time)

Also the class is missing a "RuntimeInitializeOnLoad" to clear the static dictionary, which means timers would survive the playmode if the faster-playmode-options are used (https://blog.unity.com/technology/enter-play-mode-faster-in-unity-2019-3)

pavlo-klymentenko commented 1 year ago
  1. I think that we don't need to replace current implementation with something that pays attention to Editor.pause. But I'm sure that we have to extend current impl with version that you have requested. It sounds like a good idea for me, thank you.
  2. [RuntimeInitializeOnLoad]. Absolutely agree, should be fixed. Otherwise it might become Editor only timer-tool.