当前位置:   article > 正文

unity下携程延时器_unity 延迟器

unity 延迟器
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class ScheduleOnce : UnitySingleton<ScheduleOnce>
  6. {
  7. int id = 0;
  8. Dictionary<int, Coroutine> dic = new Dictionary<int, Coroutine>();
  9. public int AddSchedule(float time, Action<object> action,params object[] arr)
  10. {
  11. int name = id++;
  12. Coroutine coroutine = StartCoroutine(DelayFun(name, time, action,arr));
  13. dic.Add(name, coroutine);
  14. return id;
  15. }
  16. //携程函數
  17. IEnumerator DelayFun(int name, float time, Action<object> action, params object[] arr)
  18. {
  19. yield return new WaitForSeconds(time);
  20. action(arr);
  21. StopSchedule(name);
  22. }
  23. public int AddSchedule(float time, Action action)
  24. {
  25. int name = id++;
  26. Coroutine coroutine = StartCoroutine(DelayFun( name, time, action));
  27. dic.Add(name, coroutine);
  28. return id;
  29. }
  30. //携程函數
  31. IEnumerator DelayFun(int name, float time, Action action)
  32. {
  33. yield return new WaitForSeconds(time);
  34. action();
  35. StopSchedule(name);
  36. }
  37. public void StopSchedule(int name)
  38. {
  39. if (dic.ContainsKey(name))
  40. {
  41. StopCoroutine(dic[name]);
  42. dic.Remove(name);
  43. }
  44. }
  45. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/94445
推荐阅读
相关标签
  

闽ICP备14008679号