拼ui 一些业务逻辑x实现
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class uServerStatus : MonoBehaviour
|
||||
{
|
||||
[Header("UI References")]
|
||||
public Image statusIcon;
|
||||
public Text statusText;
|
||||
|
||||
[Header("Status Configurations")]
|
||||
public StatusConfig[] statusConfigs;
|
||||
|
||||
[Serializable]
|
||||
public class StatusConfig
|
||||
{
|
||||
public ServerStatus status;
|
||||
public Sprite icon;
|
||||
public string displayText;
|
||||
}
|
||||
|
||||
public enum ServerStatus
|
||||
{
|
||||
Good,
|
||||
Fair,
|
||||
Unreachable,
|
||||
Unknown,
|
||||
Offline,
|
||||
Test
|
||||
}
|
||||
|
||||
public void SetStatus(ServerStatus newStatus)
|
||||
{
|
||||
foreach (var config in statusConfigs)
|
||||
{
|
||||
if (config.status == newStatus)
|
||||
{
|
||||
if (statusIcon != null) statusIcon.sprite = config.icon;
|
||||
if (statusText != null) statusText.text = string.IsNullOrEmpty(config.displayText) ? newStatus.ToString() : config.displayText;
|
||||
return;
|
||||
}
|
||||
}
|
||||
Debug.LogWarning($"No configuration found for status {newStatus}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user