BITKit/Packages/Runtime~/Unity/Scripts/Components/ShowProfiler.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
2023-08-11 23:57:37 +08:00
public class ShowProfiler : BITBehavior
2023-06-05 19:57:17 +08:00
{
[Header(Constant.Header.Settings)]
[SubclassSelector, SerializeReference] public References pingAddress;
2023-08-23 01:59:26 +08:00
[SerializeField] private IntervalUpdate fpsInterval;
2023-06-05 19:57:17 +08:00
[Header(Constant.Header.Output)]
2023-08-11 23:57:37 +08:00
[SerializeField,SerializeReference,SubclassSelector] private IProvider fpsOutput;
[SerializeField,SerializeReference,SubclassSelector] private IProvider pingOutput;
[SerializeField,SerializeReference,SubclassSelector] private IProvider resolutionOutput;
[SerializeField,SerializeReference,SubclassSelector] private IProvider frameRateOutput;
private readonly DeltaTimer timer = new();
private Ping ping;
2023-06-05 19:57:17 +08:00
[Header(Constant.Header.InternalVariables)]
2023-08-11 23:57:37 +08:00
private int frameRate;
2023-08-23 01:59:26 +08:00
2023-08-11 23:57:37 +08:00
private void Update()
2023-06-05 19:57:17 +08:00
{
timer.Update();
frameRate = timer;
2023-08-23 01:59:26 +08:00
resolutionOutput?.Set(Screen.currentResolution.ToString());
if (fpsInterval.AllowUpdate)
fpsOutput.Set((string)timer);
2023-06-05 19:57:17 +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:26 +08:00
2023-08-11 23:57:37 +08:00
ping = new Ping(pingAddress);
2023-06-05 19:57:17 +08:00
}
2023-08-23 01:59:26 +08:00
frameRateOutput?.Set(Application.targetFrameRate is -1 or 0
? "Unlimited"
: Application.targetFrameRate.ToString());
2023-06-05 19:57:17 +08:00
}
2023-08-23 01:59:26 +08:00
2023-06-05 19:57:17 +08:00
public override string GetName()
{
return nameof(ShowProfiler);
}
}
}