22using System . Collections ;
33using System . IO ;
44using System . Collections . Generic ;
5+ using System . Linq ;
56
67namespace 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>
0 commit comments