1 using System.Collections;
2 using System.Collections.Generic;
4 using System.Reflection;
19 public string filepath =
"logs/sample.log";
20 public string delimeter =
";";
22 public bool manualLog =
false;
24 public enum deltaTypes {ON_UPDATE, ON_FIXEDUPDATE, ON_LATEUPDATE, CUSTOM}
29 public float delta = 0.05f;
31 private float stime = 0.0f;
36 public enum ReadTypes {AUTO, HIGH_ACCURACY_NUMERAL, HIGH_ACCURACY_VECTOR3};
46 public List<DataSource> columns =
new List<DataSource>();
53 if(deltaType==
deltaTypes.ON_UPDATE) logObjects();
54 else if(deltaType ==
deltaTypes.CUSTOM && Time.time >= stime + delta - 0.005f) {
61 if (deltaType ==
deltaTypes.ON_FIXEDUPDATE) logObjects();
65 if (deltaType ==
deltaTypes.ON_LATEUPDATE) logObjects();
69 if(file!=null) file.Close();
79 o += getData(c) + delimeter;
85 string folder =
new FileInfo(filepath).Directory.FullName;
86 var dir = Directory.CreateDirectory(folder);
87 file = File.CreateText(filepath);
90 header += c.label + delimeter;
92 file.WriteLine(header);
97 case DataSource.ValueTypes.TIME : {
98 return Time.time.ToString();
101 var data = getPropertyValue(src.
target, src.
field);
104 case DataSource.ReadTypes.HIGH_ACCURACY_NUMERAL : {
105 return ((
float) data).ToString();
107 case DataSource.ReadTypes.HIGH_ACCURACY_VECTOR3:
109 Vector3 v = (Vector3) data;
110 return "("+v.x.ToString()+
"f, "+v.y.ToString()+
"f, "+v.z.ToString()+
"f)";
114 if(data==null)
return "null";
115 return data.ToString();
121 if (target == null || field==null)
return null;
123 if (field.Contains(
"."))
125 var temp = field.Split(
new char[] {
'.' }, 2);
126 return getPropertyValue(getPropertyValue(target, temp[0]), temp[1]);
132 BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Default | BindingFlags.GetField | BindingFlags.GetProperty;
134 return target.GetType().GetProperty(field, flags).GetValue(target, null);
136 catch(System.Exception) {
137 return target.GetType().GetField(field, flags).GetValue(target);
144 [CustomPropertyDrawer(typeof(AVR_Logger.DataSource))]
145 public class LookAtPointEditor : PropertyDrawer
147 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
149 if(property.FindPropertyRelative(
"valueType").intValue == (int)AVR_Logger.DataSource.ValueTypes.CUSTOM) {
155 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
157 EditorGUI.BeginProperty(position, label, property);
159 EditorGUIUtility.labelWidth = 50;
160 EditorGUI.PropertyField(
new Rect(position.x+0, position.y, 200, 20), property.FindPropertyRelative(
"label"),
new GUIContent(
"Label:",
"Header given to the value in the logged table"));
161 EditorGUI.PropertyField(
new Rect(position.x+200, position.y, 140, 20), property.FindPropertyRelative(
"valueType"),
new GUIContent(
"Type:",
"Type of value logged."));
163 if(property.FindPropertyRelative(
"valueType").intValue == (int)AVR_Logger.DataSource.ValueTypes.CUSTOM) {
164 EditorGUIUtility.labelWidth = 80;
165 EditorGUI.PropertyField(
new Rect(position.x + 20, position.y+20, 320, 20), property.FindPropertyRelative(
"target"),
new GUIContent(
"Target:",
"Target Monobehavior."));
166 EditorGUI.PropertyField(
new Rect(position.x + 20, position.y+40, 320, 20), property.FindPropertyRelative(
"field"),
new GUIContent(
"Field:",
"Field or Property of the target that will be logged."));
167 EditorGUI.PropertyField(
new Rect(position.x + 20, position.y+60, 320, 20), property.FindPropertyRelative(
"readType"),
new GUIContent(
"ReadType:",
"How we log the data extracted from the field."));
170 EditorGUI.EndProperty();
Monobehaviour but with an added URL button to a documentation page.
override void OnDestroy()
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
string getData(DataSource src)
Generic datalogger that logs any given variables or object properties in a csv-like format...
Allows for simple hiding of properties in the UnityEditor depending on certain conditions. For instance, in the following example the "type" field will only be displayed in the inspector if the "tracking" field is set to true:
object getPropertyValue(object target, string field)