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

94 lines
2.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-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();
}
private void RefreshDelay()
{
if (App.user == null)
{
DelayValue.text = $"-";
return;
}
if (App.user.IsLoggedIn)
DelayValue.text = $"{App.tickLoop.AveNetDelay * 1000:0}ms";
else
DelayValue.text = "-";
}
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);
}
}
}