GrassLandShootView.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using SmartBowSDK;
  6. public class GrassLandShootView : MonoBehaviour
  7. {
  8. [SerializeField] GameObject batteryProgress;
  9. void Start()
  10. {
  11. }
  12. float lastUpdateBatteryTime = 0;
  13. void Update()
  14. {
  15. if (Time.realtimeSinceStartup - lastUpdateBatteryTime > 2) {
  16. lastUpdateBatteryTime = Time.realtimeSinceStartup;
  17. if (SmartBowHelper.GetInstance().GetBluetoothStatus() == BluetoothStatusEnum.Connected) {
  18. int battery = SmartBowHelper.GetInstance().GetBattery();
  19. if (battery > 0) {
  20. Text text = batteryProgress.transform.Find("Value").GetComponent<Text>();
  21. text.text = battery + "%";
  22. Image bar = batteryProgress.transform.Find("Bar").GetComponent<Image>();
  23. bar.fillAmount = battery / 100f;
  24. batteryProgress.SetActive(true);
  25. }
  26. } else {
  27. batteryProgress.SetActive(false);
  28. }
  29. }
  30. }
  31. public void OnClick_Close() {
  32. AudioMgr.ins.PlayBtn();
  33. Application.Quit();
  34. }
  35. }