53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
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);
|
||
}
|
||
}
|
||
}
|