Logging.cs 884 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using UnityEngine;
  3. namespace Logging
  4. {
  5. public class Logging : MonoBehaviour
  6. {
  7. public float writeInterval = 1f;
  8. private float prevLogTimestamp = 0f;
  9. private FileLogger logger;
  10. private void Awake()
  11. {
  12. gameObject.SetActive(GameManager.LOG_TO_FILE);
  13. }
  14. private void Start()
  15. {
  16. logger = FileLogger.Instance;
  17. }
  18. private async void Update()
  19. {
  20. var time = Time.time;
  21. var dif = time - prevLogTimestamp;
  22. if (dif >= writeInterval)
  23. {
  24. await logger.UpdateRegisteredLogs();
  25. prevLogTimestamp = time;
  26. }
  27. }
  28. private async void OnDestroy()
  29. {
  30. await logger.UpdateRegisteredLogs();
  31. FileLogger.DestroyInstance();
  32. }
  33. }
  34. }