| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class DeviceView_ItemShow : MonoBehaviour
- {
- [SerializeField] Button btnConnectBow;
- [SerializeField] GameObject process;
- [SerializeField] GameObject connected;
- [SerializeField] GameObject betteryBar;
- [SerializeField] GameObject betteryValue;
- [SerializeField] Image pointImage;
- [SerializeField] Sprite[] pointImages;
- float countingTime1 = 0;
- BluetoothStatusEnum bowStatus;
- // Start is called before the first frame update
- void Start()
- {
- btnConnectBow.onClick.AddListener(delegate () {
- if (HomeView.ShowProminentBeforeConnectBLE()) return;
- BluetoothAim.ins.DoConnect();
- });
- }
- // Update is called once per frame
- void Update()
- {
- if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status)
- {
- bowStatus = BluetoothAim.ins.status;
- if (!process.activeSelf) process.SetActive(true);
- if (connected.activeSelf) connected.SetActive(false);
- if (process.activeSelf)
- {
- (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
- process.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
- process.GetComponentInChildren<Text>().color = color;
- }
- //btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
- pointImage.sprite = pointImages[1];
- }
- else if (BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
- {
- if (process.activeSelf) process.SetActive(false);
- if (!connected.activeSelf) connected.SetActive(true);
- //Á¬½Óºó£¬¸üÐÂµç³Ø×´Ì¬
- if (countingTime1 < 5)
- {
- countingTime1 += Time.deltaTime;
- }
- else
- {
- countingTime1 = 0;
- //RequestBatteryForBow();
- RenderBattery(DeviceBatteryView.ins.batteryDeviceID, DeviceBatteryView.ins.batteryValue);
- pointImage.sprite = pointImages[0];
- }
- }
- }
- void RequestBatteryForBow()
- {
- try
- {
- if (BluetoothAim.ins.hasData && JCUnityLib.TimeUtils.GetTimestamp() - BluetoothAim.ins.hasDataTime > 5000)
- {
- BluetoothAim.ins.RequestBattery();
- }
- }
- catch (Exception) { }
- }
- public void RenderBattery(int deviceID, int value)
- {
- Image img = betteryBar.GetComponent<Image>();
- Text txt = betteryValue.GetComponent<Text>();
- img.fillAmount = value / 100f;
- txt.text = value + "%";
- }
- }
|