-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathTimeSync.cs
More file actions
71 lines (60 loc) · 2.02 KB
/
TimeSync.cs
File metadata and controls
71 lines (60 loc) · 2.02 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
using UnityEngine;
namespace LSL4Unity.Utils
{
/// <summary>
/// A singleton to provide a dedicated timestamp for each update call: FixedUpdate, Update and LateUpdate.
/// Each sample provide by a Unity app should have the same timestamp.
/// </summary>
/// <remarks>
/// Important! Make sure that the Update methods within the class are called before the default execution order!
/// The ScriptOrder attribute takes care of that for the user.
/// </remarks>
[ScriptOrder(-1000)]
public sealed class TimeSync : MonoBehaviour
{
[Tooltip("Flag for making the script not destroyable on load.")] [SerializeField]
private bool dontDestroyOnLoad = false;
/// <summary>
/// Singleton instance of TimeSync class
/// </summary>
public static TimeSync Instance { get; private set; }
/// <summary>
/// Timestamp at FixedUpdate
/// </summary>
public double FixedUpdateTimestamp { get; private set; }
/// <summary>
/// Timestamp at Update
/// </summary>
public double UpdateTimestamp { get; private set; }
/// <summary>
/// Timestamp at LateUpdate
/// </summary>
public double LateUpdateTimestamp { get; private set; }
private void Awake()
{
// Create Singleton or destroy if an instance already exists
if (Instance && Instance != this)
{
Destroy(this);
}
else
{
Instance = this;
// Set don't destroy on load based on flag
if (dontDestroyOnLoad) DontDestroyOnLoad(this);
}
}
private void FixedUpdate()
{
FixedUpdateTimestamp = LSL.LSL.local_clock();
}
private void Update()
{
UpdateTimestamp = LSL.LSL.local_clock();
}
private void LateUpdate()
{
LateUpdateTimestamp = LSL.LSL.local_clock();
}
}
}