killapp/Assets/Scripts/UI/Pages/HomePage/HomePageDeviceState.cs

59 lines
1.9 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
2026-06-10 15:04:14 +08:00
using Kill.Bluetooth;
using Kill.Managers;
using UnityEngine;
using UnityEngine.UI;
namespace Kill.UI.Pages
{
public class HomePageDeviceState : MonoBehaviour
{
/// <summary>
/// 设备在线状态图标 0离线 1在线
/// </summary>
2026-06-10 15:04:14 +08:00
public Sprite[] onlineState;
public Image onlineStateIcon;
public Text onlineStateText;
/// <summary>
/// 设备连接状态背景颜色 0未连接 1已连接
/// </summary>
public Color[] stateBgColor;
public Image bluetoothStateIcon;
public GameObject bluetoothSearchIcon;
public Image wifiStateIcon;
bool isBluetooth;
public void UpdateDeviceState(bool isBluetooth, bool isWifi)
{
this.isBluetooth = isBluetooth;
bluetoothStateIcon.color = stateBgColor[isBluetooth ? 1 : 0];
wifiStateIcon.color = stateBgColor[isWifi ? 1 : 0];
bool isOnline = isBluetooth || isWifi;
onlineStateIcon.sprite = onlineState[isOnline ? 1 : 0];
onlineStateText.text = isOnline ? LanguageManager.Instance.GetLanguage("100098") : LanguageManager.Instance.GetLanguage("100097");
}
public void StopScan()
{
bluetoothSearchIcon.SetActive(false);
}
public void OnStartScan()
{
if(isBluetooth)
return;
bluetoothSearchIcon.SetActive(true);
}
public void ClickScan()
{
2026-06-23 15:19:47 +08:00
if (!BluetoothManager.Instance.IsConnected)
{
// 用户主动点击,强制初始化以触发蓝牙开启提示
BluetoothManager.Instance.ForceInitialize();
2026-06-10 15:04:14 +08:00
BluetoothManager.Instance.StartScan(10);
2026-06-23 15:19:47 +08:00
}
else
{
return;
}
2026-06-10 15:04:14 +08:00
}
}
}