Skip to content

Commit 9de251d

Browse files
committed
update Tracker system
1 parent 864d31d commit 9de251d

File tree

8 files changed

+53
-104
lines changed

8 files changed

+53
-104
lines changed

Assets/UXF/Scripts/Etc/Editor/TrackerEditor.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
namespace UXF.EditorUtils
66
{
7-
[CustomEditor(typeof(UXF.Tracker), true)]
7+
[CustomEditor(typeof(Tracker), true)]
88
[CanEditMultipleObjects]
99
public class TrackerEditor : Editor
1010
{
11-
SerializedProperty customHeader, measurementDescriptor;
11+
GUIStyle smallText = new GUIStyle();
12+
Tracker thisTracker;
1213

1314
void OnEnable()
1415
{
15-
customHeader = serializedObject.FindProperty("customHeader");
16-
measurementDescriptor = serializedObject.FindProperty("measurementDescriptor");
16+
smallText.font = EditorStyles.miniFont;
17+
smallText.fontSize = 9;
18+
thisTracker = (Tracker)serializedObject.targetObject;
1719
}
1820

1921
public override void OnInspectorGUI()
@@ -31,34 +33,38 @@ public override void OnInspectorGUI()
3133
{
3234
if (field.IsPublic || field.GetCustomAttribute(typeof(SerializeField)) != null)
3335
{
34-
if (field.Name != measurementDescriptor.name && field.Name != customHeader.name)
35-
{
36-
var prop = serializedObject.FindProperty(field.Name);
37-
EditorGUILayout.PropertyField(prop);
38-
}
36+
var prop = serializedObject.FindProperty(field.Name);
37+
EditorGUILayout.PropertyField(prop);
3938
}
4039
}
4140

4241
EditorGUILayout.Space();
43-
GUI.enabled = false;
4442

45-
EditorGUILayout.LabelField(customHeader.displayName);
43+
EditorGUILayout.LabelField("Custom Header");
44+
EditorGUILayout.TextField("(\"time\" is added automatically)", smallText);
4645
EditorGUI.indentLevel += 1;
47-
48-
foreach (SerializedProperty element in customHeader)
49-
{
50-
EditorGUILayout.TextField(element.stringValue);
51-
}
46+
GUI.enabled = false;
47+
EditorGUILayout.TextField(string.Join(", ", thisTracker.CustomHeader));
48+
GUI.enabled = true;
5249
EditorGUI.indentLevel -= 1;
5350

5451
EditorGUILayout.Space();
5552

56-
EditorGUILayout.LabelField(measurementDescriptor.displayName);
53+
EditorGUILayout.LabelField("Measurement Descriptor");
5754
EditorGUI.indentLevel += 1;
58-
EditorGUILayout.TextField(measurementDescriptor.stringValue);
55+
GUI.enabled = false;
56+
EditorGUILayout.TextField(thisTracker.MeasurementDescriptor);
57+
GUI.enabled = true;
5958
EditorGUI.indentLevel -= 1;
6059

60+
EditorGUILayout.Space();
61+
EditorGUILayout.LabelField("Example Filename");
62+
EditorGUI.indentLevel += 1;
63+
GUI.enabled = false;
64+
EditorGUILayout.TextField(string.Format("{0}_T001.csv", thisTracker.DataName));
6165
GUI.enabled = true;
66+
EditorGUI.indentLevel -= 1;
67+
6268
serializedObject.ApplyModifiedProperties();
6369
}
6470
}

Assets/UXF/Scripts/Etc/Tracker.cs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.IO;
44
using System.Collections.Generic;
5+
using System.Linq;
56

67
namespace UXF
78
{
@@ -10,6 +11,9 @@ namespace UXF
1011
/// </summary>
1112
public abstract class Tracker : MonoBehaviour
1213
{
14+
private bool recording = false;
15+
private static string[] baseHeaders = new string[] { "time" };
16+
1317
/// <summary>
1418
/// Name of the object used in saving
1519
/// </summary>
@@ -18,47 +22,29 @@ public abstract class Tracker : MonoBehaviour
1822
/// <summary>
1923
/// Description of the type of measurement this tracker will perform.
2024
/// </summary>
21-
[Tooltip("Description of the type of measurement this tracker will perform.")]
22-
public string measurementDescriptor;
25+
public abstract string MeasurementDescriptor { get; }
2326

2427
/// <summary>
25-
/// Custom column headers for tracked objects. Time is added automatically
28+
/// Custom column headers for tracked objects.
2629
/// </summary>
27-
[Tooltip("Custom column headers for each measurement.")]
28-
public string[] customHeader = new string[] { };
30+
public abstract IEnumerable<string> CustomHeader { get; }
2931

3032
/// <summary>
3133
/// A name used when saving the data from this tracker.
3234
/// </summary>
33-
public string dataName
35+
public string DataName
3436
{
3537
get
3638
{
37-
Debug.AssertFormat(measurementDescriptor.Length > 0, "No measurement descriptor has been specified for this Tracker!");
38-
return string.Join("_", new string[]{ objectName, measurementDescriptor });
39+
Debug.AssertFormat(MeasurementDescriptor.Length > 0, "No measurement descriptor has been specified for this Tracker!");
40+
return string.Join("_", new string[]{ objectName, MeasurementDescriptor });
3941
}
4042
}
4143

42-
private bool recording;
43-
4444
public bool Recording { get { return recording; } }
4545

46-
public UXFDataTable data { get; private set; } = new UXFDataTable();
46+
public UXFDataTable Data { get; private set; } = new UXFDataTable();
4747

48-
/// <summary>
49-
/// The header that will go at the top of the output file associated with this tracker
50-
/// </summary>
51-
/// <returns></returns>
52-
public string[] header
53-
{
54-
get
55-
{
56-
var newHeader = new string[customHeader.Length + 1];
57-
newHeader[0] = "time";
58-
customHeader.CopyTo(newHeader, 1);
59-
return newHeader;
60-
}
61-
}
6248

6349
/// <summary>
6450
/// When the tracker should take measurements.
@@ -70,7 +56,6 @@ public string[] header
7056
void Reset()
7157
{
7258
objectName = gameObject.name.Replace(" ", "_").ToLower();
73-
SetupDescriptorAndHeader();
7459
}
7560

7661
// called by unity just before rendering the frame
@@ -90,19 +75,20 @@ void FixedUpdate()
9075
/// </summary>
9176
public void RecordRow()
9277
{
93-
if (!recording) throw new System.InvalidOperationException("Tracker measurements cannot be taken when not in a trial!");
78+
if (!recording) throw new System.InvalidOperationException("Tracker measurements cannot be taken when not recording!");
9479

9580
UXFDataRow newRow = GetCurrentValues();
9681
newRow.Add(("time", Time.time));
97-
data.AddCompleteRow(newRow);
82+
Data.AddCompleteRow(newRow);
9883
}
9984

10085
/// <summary>
10186
/// Begins recording.
10287
/// </summary>
10388
public void StartRecording()
10489
{
105-
data = new UXFDataTable(header);
90+
var header = baseHeaders.Concat(CustomHeader);
91+
Data = new UXFDataTable(header.ToArray());
10692
recording = true;
10793
}
10894

@@ -120,11 +106,6 @@ public void StopRecording()
120106
/// <returns></returns>
121107
protected abstract UXFDataRow GetCurrentValues();
122108

123-
/// <summary>
124-
/// Override this method and define your own descriptor and header.
125-
/// </summary>
126-
protected abstract void SetupDescriptorAndHeader();
127-
128109
}
129110

130111
/// <summary>

Assets/UXF/Scripts/Etc/Trial.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void End()
124124

125125
// check no duplicate trackers
126126
List<string> duplicateTrackers = session.trackedObjects.Where(tracker => tracker != null)
127-
.GroupBy(tracker => tracker.dataName)
127+
.GroupBy(tracker => tracker.DataName)
128128
.Where(g => g.Count() > 1)
129129
.Select(y => y.Key)
130130
.ToList();
@@ -137,7 +137,7 @@ public void End()
137137
try
138138
{
139139
tracker.StopRecording();
140-
SaveDataTable(tracker.data, tracker.dataName, dataType: UXFDataType.Trackers);
140+
SaveDataTable(tracker.Data, tracker.DataName, dataType: UXFDataType.Trackers);
141141
}
142142
catch (NullReferenceException)
143143
{

Assets/UXF/Scripts/Trackers/MouseScreenTracker.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
using System.Collections.Generic;
2+
using UnityEngine;
23

34
namespace UXF
45
{
@@ -8,19 +9,8 @@ namespace UXF
89
/// </summary>
910
public class MouseScreenTracker : Tracker
1011
{
11-
/// <summary>
12-
/// Sets measurementDescriptor and customHeader to appropriate values
13-
/// </summary>
14-
protected override void SetupDescriptorAndHeader()
15-
{
16-
measurementDescriptor = "mouse_screen";
17-
18-
customHeader = new string[]
19-
{
20-
"pix_x",
21-
"pix_y"
22-
};
23-
}
12+
public override string MeasurementDescriptor => "mouse_screen";
13+
public override IEnumerable<string> CustomHeader => new string[] { "pix_x", "pix_y" };
2414

2515
/// <summary>
2616
/// Returns current mouse position in screen coordinates

Assets/UXF/Scripts/Trackers/MouseWorldTracker.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
using System.Collections.Generic;
2+
using UnityEngine;
23

34
namespace UXF
45
{
@@ -13,20 +14,9 @@ public class MouseWorldTracker : Tracker
1314
[Tooltip("Assign the main camera in the scene here.")]
1415
public Camera mainCamera;
1516

16-
/// <summary>
17-
/// Sets measurementDescriptor and customHeader to appropriate values
18-
/// </summary>
19-
protected override void SetupDescriptorAndHeader()
20-
{
21-
measurementDescriptor = "mouse_world";
22-
23-
customHeader = new string[]
24-
{
25-
"pos_x",
26-
"pos_y",
27-
"pos_z",
28-
};
29-
}
17+
public override string MeasurementDescriptor => "mouse_world";
18+
19+
public override IEnumerable<string> CustomHeader => new string[] { "pos_x", "pos_y", "pos_z", };
3020

3121
/// <summary>
3222
/// Returns current mouse position in world coordinates

Assets/UXF/Scripts/Trackers/PositionRotationTracker.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,8 @@ namespace UXF
1111
/// </summary>
1212
public class PositionRotationTracker : Tracker
1313
{
14-
/// <summary>
15-
/// Sets measurementDescriptor and customHeader to appropriate values
16-
/// </summary>
17-
protected override void SetupDescriptorAndHeader()
18-
{
19-
measurementDescriptor = "movement";
20-
21-
customHeader = new string[]
22-
{
23-
"pos_x",
24-
"pos_y",
25-
"pos_z",
26-
"rot_x",
27-
"rot_y",
28-
"rot_z"
29-
};
30-
}
14+
public override string MeasurementDescriptor => "movement";
15+
public override IEnumerable<string> CustomHeader => new string[] { "pos_x", "pos_y", "pos_z", "rot_x", "rot_y", "rot_z" };
3116

3217
/// <summary>
3318
/// Returns current position and rotation values

Assets/UXF/Tests/Editor/TestTrackers.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,12 @@ public void RecordingException()
164164
public void DuplicateTrackersCausesError()
165165
{
166166
string objectName = session.trackedObjects[0].objectName;
167-
string measurementDescriptor = session.trackedObjects[0].measurementDescriptor;
168167

169168
bool errorCaught = false;
170169

171170
foreach (var trial in session.Trials)
172171
{
173172
session.trackedObjects[0].objectName = session.trackedObjects[1].objectName;
174-
session.trackedObjects[0].measurementDescriptor = session.trackedObjects[1].measurementDescriptor;
175173

176174
trial.Begin();
177175

@@ -185,7 +183,6 @@ public void DuplicateTrackersCausesError()
185183
}
186184

187185
session.trackedObjects[0].objectName = objectName;
188-
session.trackedObjects[0].measurementDescriptor = measurementDescriptor;
189186

190187
trial.End();
191188
}

Assets/UXF/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.7
1+
2.4.0

0 commit comments

Comments
 (0)