123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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(GameManager.LOG_TO_FILE);
- }
- 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()
- {
- await logger.UpdateRegisteredLogs();
- FileLogger.DestroyInstance();
- }
- }
- }
|