BITFALL/Assets/BITKit/Unity/Scripts/Components/ShowProfiler.cs

45 lines
1.5 KiB
C#
Raw Normal View History

2023-08-12 01:43:24 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
2023-08-27 02:58:19 +08:00
public class ShowProfiler : MonoBehaviour
2023-08-12 01:43:24 +08:00
{
[Header(Constant.Header.Settings)]
[SubclassSelector, SerializeReference] public References pingAddress;
2023-08-23 01:59:40 +08:00
[SerializeField] private IntervalUpdate fpsInterval;
2023-08-12 01:43:24 +08:00
[Header(Constant.Header.Output)]
2023-08-27 02:58:19 +08:00
[SerializeReference,SubclassSelector] private IProvider fpsOutput;
[SerializeReference,SubclassSelector] private IProvider pingOutput;
[SerializeReference,SubclassSelector] private IProvider resolutionOutput;
[SerializeReference,SubclassSelector] private IProvider frameRateOutput;
2023-08-12 01:43:24 +08:00
private readonly DeltaTimer timer = new();
private Ping ping;
[Header(Constant.Header.InternalVariables)]
private int frameRate;
2023-08-23 01:59:40 +08:00
2023-08-12 01:43:24 +08:00
private void Update()
{
timer.Update();
frameRate = timer;
2023-08-23 01:59:40 +08:00
resolutionOutput?.Set(Screen.currentResolution.ToString());
if (fpsInterval.AllowUpdate)
fpsOutput.Set((string)timer);
2023-08-12 01:43:24 +08:00
if (pingOutput is not null && (ping is null || ping.isDone))
{
if (ping is not null && ping.isDone)
{
pingOutput.Set(ping.time.ToString());
}
2023-08-23 01:59:40 +08:00
2023-08-12 01:43:24 +08:00
ping = new Ping(pingAddress);
}
2023-08-23 01:59:40 +08:00
frameRateOutput?.Set(Application.targetFrameRate is -1 or 0
? "Unlimited"
: Application.targetFrameRate.ToString());
2023-08-12 01:43:24 +08:00
}
}
}