123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System.Threading.Tasks;
- using UnityEngine;
- namespace Logging.Base
- {
- public class Logging : MonoBehaviour
- {
- public float writeInterval = 1f;
- private float prevLogTimestamp;
- private FileLogger logger;
- private Task previousLogUpdateTask = Task.CompletedTask;
- private void Awake()
- {
- gameObject.SetActive(false);
- }
- private void Start()
- {
- logger = FileLogger.Instance;
- }
- private void Update()
- {
- if(!previousLogUpdateTask.IsCompleted) return;
- var time = Time.time;
- var dif = time - prevLogTimestamp;
- if (dif >= writeInterval)
- {
- prevLogTimestamp = time;
- previousLogUpdateTask = logger.UpdateRegisteredLogs();
- }
- }
- private async void OnDestroy()
- {
- if (logger != null)
- {
- await logger.UpdateRegisteredLogs();
- }
- FileLogger.DestroyInstance();
- }
- }
- }
|