1
0

Logging.cs 1.0 KB

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