CustomTimer.cs 683 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. namespace Mono.UI.Core
  3. {
  4. public class CustomTimer
  5. {
  6. public float TargetTime;
  7. public float CurTime;
  8. public Action Action;
  9. public bool IsOver;
  10. public void Update(float time)
  11. {
  12. CurTime += time;
  13. if (CurTime >= TargetTime)
  14. {
  15. IsOver = true;
  16. Action?.Invoke();
  17. TimeComponent.Instance.Rec(this);
  18. }
  19. }
  20. public void CustomInit(float targetTime, Action action)
  21. {
  22. CurTime = 0;
  23. TargetTime = targetTime;
  24. Action = action;
  25. IsOver = false;
  26. }
  27. }
  28. }