using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BITKit { public class ShowProfiler : MonoBehaviour { [Header(Constant.Header.Settings)] [SubclassSelector, SerializeReference] public References pingAddress; [SerializeField] private IntervalUpdate fpsInterval; [Header(Constant.Header.Output)] [SerializeReference,SubclassSelector] private IProvider fpsOutput; [SerializeReference,SubclassSelector] private IProvider pingOutput; [SerializeReference,SubclassSelector] private IProvider resolutionOutput; [SerializeReference,SubclassSelector] private IProvider frameRateOutput; [SerializeReference, SubclassSelector] private INetClient clientPing; private readonly DeltaTimer timer = new(); private Ping ping; [Header(Constant.Header.InternalVariables)] private int frameRate; private void Update() { timer.Update(); frameRate = timer; resolutionOutput?.Set(Screen.currentResolution.ToString()); if (fpsInterval.AllowUpdate) fpsOutput.Set((string)timer); if (clientPing is not null) { pingOutput.Set(clientPing.Ping.ToString()); } else if (pingOutput is not null) { switch (ping) { case null: ping = new Ping(pingAddress); break; case var x when x.isDone: pingOutput.Set(ping.time.ToString()); ping = new Ping(pingAddress); break; } } frameRateOutput?.Set(Application.targetFrameRate is -1 or 0 ? "Unlimited" : Application.targetFrameRate.ToString()); } private void OnDestroy() { ping?.DestroyPing(); } } }