Coroutine_Tips.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. local util = require 'xlua.util'
  2. local coroutineRunner = CS.Main.instance
  3. ---@class Coroutine
  4. Coroutine = {}
  5. ---@return UnityEngine.Coroutine
  6. function Coroutine.Start(...)
  7. if DebugFlag.Coroutine then
  8. if DebugFlag.LogEnable then
  9. log('Coroutine.Start')
  10. end
  11. end
  12. return coroutineRunner:StartCoroutine(util.cs_generator(DebugFlag.CoroutineDebugStack,...))
  13. end
  14. function Coroutine.Stop(c)
  15. if DebugFlag.Coroutine then
  16. if DebugFlag.LogEnable then
  17. log('Coroutine.Stop')
  18. end
  19. end
  20. if c == nil then
  21. return
  22. end
  23. coroutineRunner:StopCoroutine(c)
  24. end
  25. function Coroutine.StopAll()
  26. if DebugFlag.Coroutine then
  27. if DebugFlag.LogEnable then
  28. log('Coroutine.StopAll')
  29. end
  30. end
  31. coroutineRunner:StopAllCoroutines()
  32. end
  33. function Coroutine.Yield(enumerator)
  34. if DebugFlag.Coroutine then
  35. if DebugFlag.LogEnable then
  36. log('Coroutine.Yield')
  37. end
  38. end
  39. coroutine.yield(enumerator)
  40. end
  41. function Coroutine.Wait(time)
  42. if DebugFlag.Coroutine then
  43. if DebugFlag.LogEnable then
  44. log('Coroutine.Wait')
  45. end
  46. end
  47. coroutine.yield(CS.UnityEngine.WaitForSeconds(time))
  48. end
  49. --local waitForEndOfFrame = CS.UnityEngine.WaitForEndOfFrame()
  50. --local waitForEndOfFrame = CS.UnityEngine.WaitForSeconds(Time.deltaTime)
  51. function Coroutine.WaitForEndOfFrame()
  52. if DebugFlag.Coroutine then
  53. if DebugFlag.LogEnable then
  54. log('Coroutine.WaitForEndOfFrame')
  55. end
  56. end
  57. coroutine.yield(nil)
  58. --coroutine.yield(waitForEndOfFrame)
  59. end
  60. function Coroutine.Break()
  61. if DebugFlag.Coroutine then
  62. if DebugFlag.LogEnable then
  63. log('Coroutine.Break')
  64. end
  65. end
  66. coroutine.yield(util.move_end)
  67. end