forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cs
More file actions
57 lines (48 loc) · 1.47 KB
/
Timer.cs
File metadata and controls
57 lines (48 loc) · 1.47 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
namespace HoloToolkit.Unity
{
/// <summary>
/// Structure that defines a timer. A timer can be scheduled through the TimerScheduler.
/// </summary>
public struct Timer
{
public int Id;
public static Timer Invalid = new Timer(0);
public Timer(int id)
{
Id = id;
}
public bool IsActive
{
get
{
return (Id != Invalid.Id) && TimerScheduler.Instance.IsTimerActive(this);
}
}
public static Timer Start(float timeSeconds, TimerScheduler.Callback callback, bool loop = false)
{
if (TimerScheduler.IsInitialized)
{
return TimerScheduler.Instance.StartTimer(timeSeconds, callback, loop);
}
return Invalid;
}
public static Timer StartNextFrame(TimerScheduler.Callback callback)
{
if (TimerScheduler.IsInitialized)
{
return TimerScheduler.Instance.StartTimer(0.0f, callback, false, true);
}
return Invalid;
}
public void Stop()
{
if (TimerScheduler.IsInitialized)
{
TimerScheduler.Instance.StopTimer(this);
Id = Invalid.Id;
}
}
}
}