Cronometer.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace KairoEngine.Core
  5. {
  6. public class Cronometer
  7. {
  8. private float startTime;
  9. private float stopTime;
  10. private float totalTime;
  11. private bool running = false;
  12. public Cronometer()
  13. {
  14. startTime = Time.realtimeSinceStartup;
  15. running = true;
  16. }
  17. public void Start()
  18. {
  19. if(!running)
  20. {
  21. running = true;
  22. startTime = Time.realtimeSinceStartup;
  23. }
  24. }
  25. public Cronometer Stop()
  26. {
  27. if(running)
  28. {
  29. stopTime = Time.realtimeSinceStartup;
  30. totalTime += stopTime - startTime;
  31. running = false;
  32. startTime = 0f;
  33. stopTime = 0f;
  34. }
  35. return this;
  36. }
  37. public void Continue() => Start();
  38. public float value => totalTime;
  39. public string Print() => Utilities.TimeToString(value);
  40. }
  41. }