SensorDataLogger.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Reflection;
  4. using UnityEngine;
  5. namespace Logging
  6. {
  7. public abstract class SensorDataLogger<T> : MonoBehaviour, ILogable, ISerializableLog<T>
  8. {
  9. public abstract string Key { get; }
  10. public IEnumerable<string> HeaderNames => typeof(T).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Select((f) => f.Name);
  11. public IEnumerable<IEnumerable<string>> BufferLines => Buffer;
  12. protected List<string[]> Buffer;
  13. public virtual void Awake()
  14. {
  15. gameObject.SetActive(GameManager.LOG_TO_FILE);
  16. }
  17. public virtual async void Start()
  18. {
  19. Buffer = new List<string[]>();
  20. await FileLogger.Instance.RegisterLogable(this);
  21. }
  22. public void ClearBuffer()
  23. {
  24. Buffer.Clear();
  25. }
  26. public abstract void Log(T value);
  27. public abstract IEnumerable<T> ReadLog(IEnumerable<IEnumerable<string>> lines);
  28. }
  29. }