暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UnityThreadWaiter.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using Codice.Client.Common.Threading;
  3. namespace Unity.PlasticSCM.Editor.UI
  4. {
  5. internal class UnityThreadWaiterBuilder : IThreadWaiterBuilder
  6. {
  7. IThreadWaiter IThreadWaiterBuilder.GetWaiter()
  8. {
  9. return new UnityThreadWaiter(mPlasticTimerBuilder, false);
  10. }
  11. IThreadWaiter IThreadWaiterBuilder.GetWaiter(int timerIntervalMilliseconds)
  12. {
  13. return new UnityThreadWaiter(mPlasticTimerBuilder, false, timerIntervalMilliseconds);
  14. }
  15. IThreadWaiter IThreadWaiterBuilder.GetModalWaiter()
  16. {
  17. return new UnityThreadWaiter(mPlasticTimerBuilder, true);
  18. }
  19. IThreadWaiter IThreadWaiterBuilder.GetModalWaiter(int timerIntervalMilliseconds)
  20. {
  21. return new UnityThreadWaiter(mPlasticTimerBuilder, true, timerIntervalMilliseconds);
  22. }
  23. IPlasticTimer IThreadWaiterBuilder.GetTimer(
  24. int timerIntervalMilliseconds, ThreadWaiter.TimerTick timerTickDelegate)
  25. {
  26. return mPlasticTimerBuilder.Get(false, timerIntervalMilliseconds, timerTickDelegate);
  27. }
  28. static IPlasticTimerBuilder mPlasticTimerBuilder = new UnityPlasticTimerBuilder();
  29. }
  30. internal class UnityThreadWaiter : IThreadWaiter
  31. {
  32. Exception IThreadWaiter.Exception { get { return mThreadOperation.Exception; } }
  33. internal UnityThreadWaiter(
  34. IPlasticTimerBuilder timerBuilder, bool bModalMode)
  35. {
  36. mPlasticTimer = timerBuilder.Get(bModalMode, OnTimerTick);
  37. }
  38. internal UnityThreadWaiter(
  39. IPlasticTimerBuilder timerBuilder,
  40. bool bModalMode,
  41. int timerIntervalMilliseconds)
  42. {
  43. mPlasticTimer = timerBuilder.Get(bModalMode, timerIntervalMilliseconds, OnTimerTick);
  44. }
  45. void IThreadWaiter.Execute(
  46. PlasticThread.Operation threadOperationDelegate,
  47. PlasticThread.Operation afterOperationDelegate)
  48. {
  49. ((IThreadWaiter)(this)).Execute(threadOperationDelegate, afterOperationDelegate, null);
  50. }
  51. void IThreadWaiter.Execute(
  52. PlasticThread.Operation threadOperationDelegate,
  53. PlasticThread.Operation afterOperationDelegate,
  54. PlasticThread.Operation timerTickDelegate)
  55. {
  56. mThreadOperation = new PlasticThread(threadOperationDelegate);
  57. mAfterOperationDelegate = afterOperationDelegate;
  58. mTimerTickDelegate = timerTickDelegate;
  59. mPlasticTimer.Start();
  60. mThreadOperation.Execute();
  61. }
  62. void IThreadWaiter.Cancel()
  63. {
  64. mbCancelled = true;
  65. }
  66. void OnTimerTick()
  67. {
  68. if (mThreadOperation.IsRunning)
  69. {
  70. if (mTimerTickDelegate != null)
  71. EditorDispatcher.Dispatch(() => mTimerTickDelegate());
  72. return;
  73. }
  74. mPlasticTimer.Stop();
  75. if (mbCancelled)
  76. return;
  77. EditorDispatcher.Dispatch(() => mAfterOperationDelegate());
  78. }
  79. bool mbCancelled = false;
  80. IPlasticTimer mPlasticTimer;
  81. PlasticThread mThreadOperation;
  82. PlasticThread.Operation mTimerTickDelegate;
  83. PlasticThread.Operation mAfterOperationDelegate;
  84. }
  85. }