killapp/Assets/Scripts/UI/Pages/HomePage/HomePageDeviceState.cs
“虞渠成” 3abf31324c 0610
2026-06-10 15:04:14 +08:00

53 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using Kill.Bluetooth;
using Kill.Managers;
using UnityEngine;
using UnityEngine.UI;
namespace Kill.UI.Pages
{
public class HomePageDeviceState : MonoBehaviour
{
/// <summary>
/// 设备在线状态图标 0离线 1在线
/// </summary>
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];
bluetoothSearchIcon.SetActive(!isBluetooth);
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()
{
if(!BluetoothManager.Instance.IsConnected)
BluetoothManager.Instance.StartScan(10);
bluetoothSearchIcon.SetActive(true);
}
}
}