DeviceBatteryView.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. /* 设备的电池显示界面(右上角) */
  8. public class DeviceBatteryView : MonoBehaviour
  9. {
  10. public static DeviceBatteryView ins;
  11. public Text labelTemperature;
  12. public int batteryValue;
  13. public int batteryDeviceID;
  14. void Start()
  15. {
  16. if (ins) {
  17. Destroy(this.gameObject);
  18. } else {
  19. ins = this;
  20. DontDestroyOnLoad(this.gameObject);
  21. }
  22. }
  23. float countingTime1 = 0;
  24. float countingTime2 = 1;
  25. void Update()
  26. {
  27. #if UNITY_EDITOR
  28. #region pc端操作,模拟添加分数
  29. //if (Input.GetKeyDown(KeyCode.F5))
  30. //{
  31. // //string[] dates = UserPlayer.ins.getDateArray();
  32. // //rankComp.uploadSeasonSinglePlayerGameRes 使用赛季上传分数接口,替换rankComp.uploadSinglePlayerGameRes
  33. // UserPlayer.ins.call(
  34. // "rankComp.uploadSeasonSinglePlayerGameRes",
  35. // GlobalData.singlePlayerGameType,
  36. // 100
  37. // );
  38. //}
  39. //if (Input.GetKeyDown(KeyCode.F6))
  40. //{
  41. // //rankComp.uploadSeasonPKGameRes 使用赛季上传分数接口,替换rankComp.uploadPKGameRes
  42. // UserPlayer.ins.call(
  43. // "rankComp.uploadSeasonPKGameResTest", //rankComp.uploadPKGameRes
  44. // //GlobalData.roomKey,
  45. // //GlobalData.matchGameType,
  46. // //GlobalData.matchPlayerInfos[0].playerID,
  47. // //GlobalData.matchPlayerInfos[1].playerID,
  48. // 9, 178, 281,
  49. // 0 //玩家1胜利,1:玩家2, 2:平局
  50. // //使用时间筛选
  51. // );
  52. //}
  53. //if (Input.GetKeyDown(KeyCode.F7))
  54. //{
  55. // //rankComp.uploadSeasonPKGameRes 使用赛季上传分数接口,替换rankComp.uploadPKGameRes
  56. // UserPlayer.ins.call(
  57. // "rankComp.uploadSeasonPKGameResTest",
  58. // 9, 178, 281,
  59. // 1 //玩家1胜利,1:玩家2, 2:平局
  60. // //使用时间筛选
  61. // );
  62. //}
  63. //if (Input.GetKeyDown(KeyCode.F8))
  64. //{
  65. // //rankComp.uploadSeasonPKGameRes 使用赛季上传分数接口,替换rankComp.uploadPKGameRes
  66. // UserPlayer.ins.call(
  67. // "rankComp.uploadSeasonPKGameResTest",
  68. // 9, 178, 281,
  69. // 2 //玩家1胜利,1:玩家2, 2:平局
  70. // //使用时间筛选
  71. // );
  72. //}
  73. #endregion
  74. #endif
  75. if (countingTime1 < 5) {
  76. countingTime1 += Time.deltaTime;
  77. } else {
  78. countingTime1 = 0;
  79. RequestBatteryForBow();
  80. //RequestBatteryForArrow();
  81. RequestBatteryForBow2();
  82. }
  83. if (countingTime2 < 1) {
  84. countingTime2 += Time.deltaTime;
  85. } else {
  86. countingTime2 = 0;
  87. //bool activeBow = BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess;
  88. //bool activeArrow = BluetoothShoot.ins && BluetoothShoot.ins.status == BluetoothStatusEnum.ConnectSuccess;
  89. //if (!activeBow) {
  90. // this.transform.Find("Layout/Label1").gameObject.SetActive(false);
  91. // this.transform.Find("Layout/Frame1").gameObject.SetActive(false);
  92. //}
  93. //if (!activeArrow) {
  94. // this.transform.Find("Layout/Label2").gameObject.SetActive(false);
  95. // this.transform.Find("Layout/Frame2").gameObject.SetActive(false);
  96. //}
  97. }
  98. }
  99. void RequestBatteryForBow()
  100. {
  101. try {
  102. if (BluetoothAim.ins.hasData && JCUnityLib.TimeUtils.GetTimestamp() - BluetoothAim.ins.hasDataTime > 5000) {
  103. BluetoothAim.ins.RequestBattery();
  104. }
  105. } catch (Exception) {}
  106. }
  107. void RequestBatteryForArrow()
  108. {
  109. //try {
  110. // if (BluetoothShoot.ins.hasData) {
  111. // BluetoothShoot.ins.WriteData("B");
  112. // }
  113. //} catch (Exception) {}
  114. }
  115. //弓箭2电量
  116. void RequestBatteryForBow2()
  117. {
  118. if (BluetoothAim.ins == null || HomeView.ins == null) return;
  119. //渲染电量
  120. HomeView.ins.RenderBattery2();
  121. }
  122. //batteryDeviceID 本来用于区分箭和弓的
  123. public void RenderBattery(int deviceID, int value)
  124. {
  125. batteryDeviceID = deviceID;
  126. batteryValue = value;
  127. if(HomeView.ins)HomeView.ins.RenderBattery(batteryDeviceID,batteryValue);
  128. //bool active = true;
  129. //if (value <= 1) active = false;
  130. //Image img = this.transform.Find($"Layout/Frame{deviceID}/Bar").GetComponent<Image>();
  131. //Text txt = this.transform.Find($"Layout/Frame{deviceID}/Value").GetComponent<Text>();
  132. //this.transform.Find($"Layout/Label{deviceID}").gameObject.SetActive(active);
  133. //img.transform.parent.gameObject.SetActive(active);
  134. //img.fillAmount = value / 100f;
  135. //txt.text = value + "%";
  136. }
  137. }