@@ -13,6 +13,7 @@ public abstract class Tracker : MonoBehaviour
13
13
{
14
14
private bool recording = false ;
15
15
private static string [ ] baseHeaders = new string [ ] { "time" } ;
16
+ private TrackerState currentState = TrackerState . Uninitialised ;
16
17
17
18
/// <summary>
18
19
/// Name of the object used in saving
@@ -44,7 +45,11 @@ public string DataName
44
45
public bool Recording { get { return recording ; } }
45
46
46
47
public UXFDataTable Data { get ; private set ; } = new UXFDataTable ( ) ;
47
-
48
+
49
+ /// <summary>
50
+ /// The current state of the tracker.
51
+ /// </summary>
52
+ public TrackerState CurrentState { get => currentState ; }
48
53
49
54
/// <summary>
50
55
/// When the tracker should take measurements.
@@ -87,17 +92,58 @@ public void RecordRow()
87
92
/// </summary>
88
93
public void StartRecording ( )
89
94
{
95
+ if ( currentState == TrackerState . On )
96
+ {
97
+ Debug . LogWarning ( $ "Start command received for tracker in state: '{ TrackerState . On } '." +
98
+ $ " This will dump exisiting data! " +
99
+ "If you want to restart a paused tracker, use 'ResumeRecording()' instead." ) ;
100
+ }
90
101
var header = baseHeaders . Concat ( CustomHeader ) ;
91
102
Data = new UXFDataTable ( header . ToArray ( ) ) ;
92
103
recording = true ;
104
+ currentState = TrackerState . On ;
93
105
}
94
106
95
107
/// <summary>
96
108
/// Stops recording.
97
109
/// </summary>
98
110
public void StopRecording ( )
99
111
{
112
+ if ( currentState != TrackerState . On )
113
+ {
114
+ Debug . LogWarning ( $ "Stop command received for tracker in state: '{ currentState } '." +
115
+ $ " This should only be called when tracker is in state '{ TrackerState . On } '") ;
116
+ }
117
+ recording = false ;
118
+ currentState = TrackerState . Off ;
119
+ }
120
+
121
+ /// <summary>
122
+ /// Pauses recording.
123
+ /// </summary>
124
+ public void PauseRecording ( )
125
+ {
126
+ if ( currentState != TrackerState . On )
127
+ {
128
+ Debug . LogWarning ( $ "Pause command received for tracker in state: '{ currentState } '." +
129
+ $ "This should only be called when tracker is in state '{ TrackerState . On } '") ;
130
+ }
100
131
recording = false ;
132
+ currentState = TrackerState . Paused ;
133
+ }
134
+
135
+ /// <summary>
136
+ /// Resumes recording.
137
+ /// </summary>
138
+ public void ResumeRecording ( )
139
+ {
140
+ if ( currentState != TrackerState . Paused )
141
+ {
142
+ Debug . LogWarning ( $ "Resume command received for tracker in state: '{ currentState } '." +
143
+ $ "This should only be called when tracker is in state '{ TrackerState . Paused } '") ;
144
+ }
145
+ recording = true ;
146
+ currentState = TrackerState . On ;
101
147
}
102
148
103
149
/// <summary>
@@ -115,4 +161,12 @@ public enum TrackerUpdateType
115
161
{
116
162
LateUpdate , FixedUpdate , Manual
117
163
}
164
+
165
+ /// <summary>
166
+ /// The possible states a tracker can be in.
167
+ /// </summary>
168
+ public enum TrackerState
169
+ {
170
+ On , Off , Paused , Uninitialised
171
+ }
118
172
}
0 commit comments