using Cryville.Common.Unity; using UnityEngine; using UnityEngine.UI; namespace Cryville.Crtr { public class NetworkTaskWorkerTicker : MonoBehaviour { private Image _image; private float timer; #pragma warning disable IDE0051 void Awake() { _image = GetComponent(); } static Color _idleColor = new(1, 1, 1, .5f); static Color _tickColor1 = new(1, 1, 1, 1); static Color _tickColor2 = new(1, 1, 1, .8f); static Color _suspendedColor = new(1, 0, 0, 1); void Update() { var status = Game.NetworkTaskWorker.TickBackgroundTasks(); if (_image == null) return; switch (status) { case WorkerStatus.Idle: _image.color = _idleColor; timer = 0f; break; case WorkerStatus.Suspended: _image.color = _suspendedColor; timer = 0f; break; case WorkerStatus.Working: timer += Time.deltaTime; timer %= 0.5f; _image.color = timer < 0.25f ? _tickColor1 : _tickColor2; break; } } #pragma warning restore IDE0051 } }