diff --git a/Event Logger/EventLog.cs b/Event Logger/EventLog.cs index a1ed765c040e68f09b82c9aa00e477377e61376e..375e3391f4a0ff59f3f01b4e5385264d3265e361 100644 --- a/Event Logger/EventLog.cs +++ b/Event Logger/EventLog.cs @@ -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}"; + } } }