Skip to content

Commit 39c59f9

Browse files
Update Tracker.cs
1 parent 62bb584 commit 39c59f9

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

Assets/UXF/Scripts/Etc/Tracker.cs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
namespace UXF
88
{
99
/// <summary>
10-
/// Create a new class that inherits from this component to create custom tracking behaviour on a frame-by-frame basis.
10+
/// Create a new class that inherits from this component to create custom tracking behaviour
11+
/// on a frame-by-frame basis.
1112
/// </summary>
1213
public abstract class Tracker : MonoBehaviour
1314
{
14-
private bool recording = false;
1515
private static string[] baseHeaders = new string[] { "time" };
16-
private TrackerState currentState = TrackerState.Uninitialised;
16+
private TrackerState currentState = TrackerState.Stopped;
1717

1818
/// <summary>
1919
/// Name of the object used in saving
@@ -37,12 +37,13 @@ public string DataName
3737
{
3838
get
3939
{
40-
Debug.AssertFormat(MeasurementDescriptor.Length > 0, "No measurement descriptor has been specified for this Tracker!");
40+
Debug.AssertFormat(MeasurementDescriptor.Length > 0,
41+
"No measurement descriptor has been specified for this Tracker!");
4142
return string.Join("_", new string[]{ objectName, MeasurementDescriptor });
4243
}
4344
}
4445

45-
public bool Recording { get { return recording; } }
46+
public bool Recording { get { return currentState == TrackerState.Recording; } }
4647

4748
public UXFDataTable Data { get; private set; } = new UXFDataTable();
4849

@@ -54,7 +55,9 @@ public string DataName
5455
/// <summary>
5556
/// When the tracker should take measurements.
5657
/// </summary>
57-
[Tooltip("When the measurements should be taken.\n\nManual should only be selected if the user is calling the RecordRow method either from another script or a custom Tracker class.")]
58+
[Tooltip("When the measurements should be taken." +
59+
"\n\nManual should only be selected if the user is calling the RecordRow method" +
60+
" either from another script or a custom Tracker class.")]
5861
public TrackerUpdateType updateType = TrackerUpdateType.LateUpdate;
5962

6063
// called when component is added
@@ -66,21 +69,22 @@ void Reset()
6669
// called by unity just before rendering the frame
6770
void LateUpdate()
6871
{
69-
if (recording && updateType == TrackerUpdateType.LateUpdate) RecordRow();
72+
if (Recording && updateType == TrackerUpdateType.LateUpdate) RecordRow();
7073
}
7174

7275
// called by unity when physics simulations are run
7376
void FixedUpdate()
7477
{
75-
if (recording && updateType == TrackerUpdateType.FixedUpdate) RecordRow();
78+
if (Recording && updateType == TrackerUpdateType.FixedUpdate) RecordRow();
7679
}
7780

7881
/// <summary>
7982
/// Records a new row of data at current time.
8083
/// </summary>
8184
public void RecordRow()
8285
{
83-
if (!recording) throw new System.InvalidOperationException("Tracker measurements cannot be taken when not recording!");
86+
if (!Recording) throw new System.InvalidOperationException(
87+
"Tracker measurements cannot be taken when not recording!");
8488

8589
UXFDataRow newRow = GetCurrentValues();
8690
newRow.Add(("time", Time.time));
@@ -92,43 +96,40 @@ public void RecordRow()
9296
/// </summary>
9397
public void StartRecording()
9498
{
95-
if (currentState == TrackerState.On)
99+
if (currentState == TrackerState.Recording)
96100
{
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.");
101+
Utilities.UXFDebugLogWarning($"Start command received for tracker in state: '{TrackerState.Recording}'." +
102+
" This will dump exisiting data! " +
103+
$"If you want to restart a paused tracker, use '{nameof(ResumeRecording)}()' instead.");
100104
}
101105
var header = baseHeaders.Concat(CustomHeader);
102106
Data = new UXFDataTable(header.ToArray());
103-
recording = true;
104-
currentState = TrackerState.On;
107+
currentState = TrackerState.Recording;
105108
}
106109

107110
/// <summary>
108111
/// Stops recording.
109112
/// </summary>
110113
public void StopRecording()
111114
{
112-
if (currentState != TrackerState.On)
115+
if (currentState != TrackerState.Recording)
113116
{
114-
Debug.LogWarning($"Stop command received for tracker in state: '{currentState}'." +
115-
$" This should only be called when tracker is in state '{TrackerState.On}'");
117+
Utilities.UXFDebugLogWarning($"Stop command received for tracker in state: '{currentState}'." +
118+
$" This should only be called when tracker is in state '{TrackerState.Recording}'");
116119
}
117-
recording = false;
118-
currentState = TrackerState.Off;
120+
currentState = TrackerState.Stopped;
119121
}
120122

121123
/// <summary>
122124
/// Pauses recording.
123125
/// </summary>
124126
public void PauseRecording()
125127
{
126-
if (currentState != TrackerState.On)
128+
if (currentState != TrackerState.Recording)
127129
{
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+
Utilities.UXFDebugLogWarning($"Pause command received for tracker in state: '{currentState}'." +
131+
$"This should only be called when tracker is in state '{TrackerState.Recording}'");
130132
}
131-
recording = false;
132133
currentState = TrackerState.Paused;
133134
}
134135

@@ -139,11 +140,10 @@ public void ResumeRecording()
139140
{
140141
if (currentState != TrackerState.Paused)
141142
{
142-
Debug.LogWarning($"Resume command received for tracker in state: '{currentState}'." +
143+
Utilities.UXFDebugLogWarning($"Resume command received for tracker in state: '{currentState}'." +
143144
$"This should only be called when tracker is in state '{TrackerState.Paused}'");
144145
}
145-
recording = true;
146-
currentState = TrackerState.On;
146+
currentState = TrackerState.Recording;
147147
}
148148

149149
/// <summary>
@@ -155,7 +155,9 @@ public void ResumeRecording()
155155
}
156156

157157
/// <summary>
158-
/// When the tracker should collect new measurements. Manual should only be selected if the user is calling the RecordRow method either from another script or a custom Tracker class.
158+
/// When the tracker should collect new measurements.
159+
/// Manual should only be selected if the user is calling the RecordRow method
160+
/// either from another script or a custom Tracker class.
159161
/// </summary>
160162
public enum TrackerUpdateType
161163
{
@@ -167,6 +169,6 @@ public enum TrackerUpdateType
167169
/// </summary>
168170
public enum TrackerState
169171
{
170-
On, Off, Paused, Uninitialised
172+
Recording, Paused, Stopped
171173
}
172174
}

0 commit comments

Comments
 (0)