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