Skip to content
Snippets Groups Projects
Commit e70b1572 authored by Heine, Eric R's avatar Heine, Eric R
Browse files

Merge branch 'redirect-events-to-unity-debug-log' into 'master'

EventLog can now redirect events to the Unity Log.

See merge request !5
parents cb00b530 3473ffca
No related branches found
No related tags found
1 merge request!5EventLog can now redirect events to the Unity Log.
......@@ -10,6 +10,9 @@ namespace Shared.EventLog {
// Depends on ScriptableVariable package
[CreateAssetMenu(menuName = "Scriptable Objects/Event Log")]
public class EventLog : ScriptableVariable {
[Tooltip("Redirect all incoming events to the Unity Log or not")]
public bool redirectToUnityLog = false;
readonly List<KeyValuePair<string, string>> events = new List<KeyValuePair<string, string>>();
private DateTime startTime = DateTime.Now;
......@@ -17,7 +20,12 @@ namespace Shared.EventLog {
// ---------------------------------------------------------------------------
// Add an event to the log
public void Add(string key, string value) {
events.Add(new KeyValuePair<string, string>(DateTime.Now.Subtract(startTime).TotalSeconds.ToString() + "," + key, value));
var evt = new KeyValuePair<string, string>(DateTime.Now.Subtract(startTime).TotalSeconds.ToString() + "," + key, value);
events.Add(evt);
if (redirectToUnityLog) {
Debug.Log(EventToString(evt));
}
}
// ---------------------------------------------------------------------------
......@@ -34,7 +42,7 @@ namespace Shared.EventLog {
public void WriteToFile(string directory, string filename) {
string csv = string.Join(
System.Environment.NewLine,
events.Select(d => d.Key + "," + d.Value).ToArray()
events.Select(d => EventToString(d)).ToArray()
);
#if UNITY_ANDROID
......@@ -47,5 +55,11 @@ namespace Shared.EventLog {
directory += "/" + filename;
File.WriteAllText(directory, csv);
}
// ---------------------------------------------------------------------------
//Utility used to convert an Event data to a string, suitable for display.
private string EventToString(KeyValuePair<string, string> evt) {
return $"{evt.Key},{evt.Value}";
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment