void SetCtrState(Peripheral peripheral) { if (ctrPeripheral == null) { ctrPeripheral = peripheral; } ctrflag = peripheral.Connected; Ctr.Find("Switch").gameObject.SetActive(ctrflag); Ctr.Find("False").gameObject.SetActive(!ctrflag); if (CtrState != null) { CtrState(ctrflag); } if (ctrflag) { if (peripheral.GetBatteryLevel() < 0) { SetBatteryLevel = true; } else { Ctr.Find("Text").GetComponent <UnityEngine.UI.Text>().text = peripheral.GetBatteryLevel().ToString() + "%"; } } }
public override void update() { //if Space Time > 1S,Update The Baettery Info if (Time.timeSinceLevelLoad - tempTime > 1) { UpdateCtrBattery(); UpdateUsbBattery(); tempTime = Time.timeSinceLevelLoad; } if (SetBatteryLevel) { if (ctrPeripheral != null && ctrPeripheral.GetBatteryLevel() > 0) { SetBatteryLevel = false; Ctr.Find("Text").GetComponent <UnityEngine.UI.Text>().text = ctrPeripheral.GetBatteryLevel().ToString() + "%"; } } }
/// <summary> /// Output the Info of Controller /// </summary> private void OutputControllerInfo(Peripheral peripheral) { if (!peripheral.Connected) { return; } Sdk.Logger.Log("Controller Device Name: " + peripheral.GetDeviceName()); Sdk.Logger.Log("Controller FW Info: " + peripheral.GetFirmwareVersion()); Sdk.Logger.Log("Controller Modle Name: " + peripheral.GetModelName()); Sdk.Logger.Log("Controller Serial Number: " + peripheral.GetSerialNumber()); Sdk.Logger.Log("Controller Battery: " + peripheral.GetBatteryLevel()); }