AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/UI/XMBTopGroupUI/XMBTopGroup.cs

125 lines
3.2 KiB
C#
Raw Normal View History

2024-09-13 16:26:26 +08:00
using AxibugEmuOnline.Client;
using AxibugEmuOnline.Client.ClientCore;
using System;
using UnityEngine;
using UnityEngine.UI;
public class XMBTopGroup : MonoBehaviour
{
public Text txtDateTime;
public Image imgPowerRoot;
public Image imgPower1;
public Image imgPower2;
public Image imgPower3;
2024-11-08 16:23:26 +08:00
public Text DelayValue;
2024-11-29 16:36:26 +08:00
public Text OnlinePlayerCount;
2024-11-19 13:09:53 +08:00
public Text FPS;
2024-09-13 16:26:26 +08:00
void OnEnable()
{
TickLoop.LoopAction_1s += RefreshAll;
2024-11-08 16:23:26 +08:00
RefreshAll();
2024-09-13 16:26:26 +08:00
}
void OnDisable()
{
TickLoop.LoopAction_1s -= RefreshAll;
}
void RefreshAll()
{
RefreshTime();
RefreshPower();
2024-11-08 16:23:26 +08:00
RefreshDelay();
2024-11-19 13:09:53 +08:00
RefreshFps();
}
(uint lastFrame, float lastTime) m_lastFrameInfo;
private void RefreshFps()
{
if (App.emu.Core.IsNull())
FPS.gameObject.SetActiveEx(false);
else
{
FPS.gameObject.SetActiveEx(true);
var gap = App.emu.Core.Frame - m_lastFrameInfo.lastFrame;
var time = Time.realtimeSinceStartup - m_lastFrameInfo.lastTime;
var fps = gap / time;
FPS.text = $"FPS:{fps:.#}";
m_lastFrameInfo.lastFrame = App.emu.Core.Frame;
m_lastFrameInfo.lastTime = Time.realtimeSinceStartup;
}
2024-11-08 16:23:26 +08:00
}
private void RefreshDelay()
{
if (App.user == null)
{
DelayValue.text = $"-";
2024-11-29 16:36:26 +08:00
OnlinePlayerCount.text = $"-";
2024-11-08 16:23:26 +08:00
return;
}
else
2024-11-29 16:36:26 +08:00
{
if (App.user.IsLoggedIn)
{
DelayValue.text = $"{App.tickLoop.AveNetDelay * 1000:0}ms";
OnlinePlayerCount.text = App.user.OnlinePlayerCount.ToString();
}
else
{
DelayValue.text = "-";
OnlinePlayerCount.text = $"-";
}
}
2024-11-08 16:23:26 +08:00
}
2024-09-13 16:26:26 +08:00
void RefreshTime()
{
txtDateTime.text = DateTime.Now.ToString("MM/dd HH:mm");
}
void RefreshPower()
{
float battery = SystemInfo.batteryLevel;
if (Application.platform == RuntimePlatform.WindowsPlayer
||
Application.platform == RuntimePlatform.WindowsEditor
||
Application.platform == RuntimePlatform.OSXPlayer
||
Application.platform == RuntimePlatform.OSXEditor
)
{
battery = 1f;
}
2024-09-13 16:44:33 +08:00
2024-09-13 16:26:26 +08:00
if (battery > 0.80f)
{
imgPower1.gameObject.SetActive(true);
imgPower2.gameObject.SetActive(true);
imgPower2.gameObject.SetActive(true);
}
else if (battery > 0.50f)
{
imgPower1.gameObject.SetActive(false);
imgPower2.gameObject.SetActive(true);
imgPower2.gameObject.SetActive(true);
}
else if (battery > 0.20f)
{
imgPower1.gameObject.SetActive(false);
imgPower2.gameObject.SetActive(false);
imgPower2.gameObject.SetActive(true);
}
else
{
imgPower1.gameObject.SetActive(false);
imgPower2.gameObject.SetActive(false);
imgPower2.gameObject.SetActive(false);
}
}
}