using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; /* 设备的电池显示界面(右上角) */ public class DeviceBatteryView : MonoBehaviour { public static DeviceBatteryView ins; public Text labelTemperature; public int batteryValue; public int batteryDeviceID; void Start() { if (ins) { Destroy(this.gameObject); } else { ins = this; DontDestroyOnLoad(this.gameObject); } } float countingTime1 = 0; float countingTime2 = 1; void Update() { #if UNITY_EDITOR #region pc端操作,模拟添加分数 //if (Input.GetKeyDown(KeyCode.F5)) //{ // //string[] dates = UserPlayer.ins.getDateArray(); // //rankComp.uploadSeasonSinglePlayerGameRes 使用赛季上传分数接口,替换rankComp.uploadSinglePlayerGameRes // UserPlayer.ins.call( // "rankComp.uploadSeasonSinglePlayerGameRes", // GlobalData.singlePlayerGameType, // 100 // ); //} //if (Input.GetKeyDown(KeyCode.F6)) //{ // //rankComp.uploadSeasonPKGameRes 使用赛季上传分数接口,替换rankComp.uploadPKGameRes // UserPlayer.ins.call( // "rankComp.uploadSeasonPKGameResTest", //rankComp.uploadPKGameRes // //GlobalData.roomKey, // //GlobalData.matchGameType, // //GlobalData.matchPlayerInfos[0].playerID, // //GlobalData.matchPlayerInfos[1].playerID, // 9, 178, 281, // 0 //玩家1胜利,1:玩家2, 2:平局 // //使用时间筛选 // ); //} //if (Input.GetKeyDown(KeyCode.F7)) //{ // //rankComp.uploadSeasonPKGameRes 使用赛季上传分数接口,替换rankComp.uploadPKGameRes // UserPlayer.ins.call( // "rankComp.uploadSeasonPKGameResTest", // 9, 178, 281, // 1 //玩家1胜利,1:玩家2, 2:平局 // //使用时间筛选 // ); //} //if (Input.GetKeyDown(KeyCode.F8)) //{ // //rankComp.uploadSeasonPKGameRes 使用赛季上传分数接口,替换rankComp.uploadPKGameRes // UserPlayer.ins.call( // "rankComp.uploadSeasonPKGameResTest", // 9, 178, 281, // 2 //玩家1胜利,1:玩家2, 2:平局 // //使用时间筛选 // ); //} #endregion #endif if (countingTime1 < 5) { countingTime1 += Time.deltaTime; } else { countingTime1 = 0; RequestBatteryForBow(); //RequestBatteryForArrow(); RequestBatteryForBow2(); } if (countingTime2 < 1) { countingTime2 += Time.deltaTime; } else { countingTime2 = 0; //bool activeBow = BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess; //bool activeArrow = BluetoothShoot.ins && BluetoothShoot.ins.status == BluetoothStatusEnum.ConnectSuccess; //if (!activeBow) { // this.transform.Find("Layout/Label1").gameObject.SetActive(false); // this.transform.Find("Layout/Frame1").gameObject.SetActive(false); //} //if (!activeArrow) { // this.transform.Find("Layout/Label2").gameObject.SetActive(false); // this.transform.Find("Layout/Frame2").gameObject.SetActive(false); //} } } void RequestBatteryForBow() { try { if (BluetoothAim.ins.hasData && JCUnityLib.TimeUtils.GetTimestamp() - BluetoothAim.ins.hasDataTime > 5000) { BluetoothAim.ins.RequestBattery(); } } catch (Exception) {} } void RequestBatteryForArrow() { //try { // if (BluetoothShoot.ins.hasData) { // BluetoothShoot.ins.WriteData("B"); // } //} catch (Exception) {} } //弓箭2电量 void RequestBatteryForBow2() { if (BluetoothAim.ins == null || HomeView.ins == null) return; //渲染电量 HomeView.ins.RenderBattery2(); } //batteryDeviceID 本来用于区分箭和弓的 public void RenderBattery(int deviceID, int value) { batteryDeviceID = deviceID; batteryValue = value; if(HomeView.ins)HomeView.ins.RenderBattery(batteryDeviceID,batteryValue); //bool active = true; //if (value <= 1) active = false; //Image img = this.transform.Find($"Layout/Frame{deviceID}/Bar").GetComponent(); //Text txt = this.transform.Find($"Layout/Frame{deviceID}/Value").GetComponent(); //this.transform.Find($"Layout/Label{deviceID}").gameObject.SetActive(active); //img.transform.parent.gameObject.SetActive(active); //img.fillAmount = value / 100f; //txt.text = value + "%"; } }