Module_BatteryStatus.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SC.XR.Unity {
  6. public class Module_BatteryStatus {
  7. private static Module_BatteryStatus instance;
  8. public static Module_BatteryStatus getInstance {
  9. get {
  10. if (instance == null) {
  11. instance = new Module_BatteryStatus();
  12. }
  13. return instance;
  14. }
  15. }
  16. private AndroidJavaObject BatteryStatusObject;
  17. Module_BatteryStatus() {
  18. if (Application.platform == RuntimePlatform.Android) {
  19. BatteryStatusObject = new AndroidJavaObject("com.example.batterystatus.BatteryStatus", AndroidPluginBase.CurrentActivity);
  20. }
  21. }
  22. public void SetCallBack(Action<int, BATTERYHEALTH, int, BATTERYPLUGGED, BATTERYSTATUS, string, int> batteryStatusCallBack, Action batteryLowCallBack, Action batteryOKAYCallBack) {
  23. if (BatteryStatusObject!=null) {
  24. BatteryStatusObject.Call("SetCallBack", new BatteryListener(batteryStatusCallBack, batteryLowCallBack, batteryOKAYCallBack));
  25. }
  26. }
  27. public int BatteryLevel {
  28. get {
  29. if (BatteryStatusObject != null) {
  30. return BatteryStatusObject.Call<int>("BatteryLevel");
  31. }
  32. return -1;
  33. }
  34. }
  35. public BATTERYSTATUS IsCharging {
  36. get {
  37. if (BatteryStatusObject != null) {
  38. return (BATTERYSTATUS)BatteryStatusObject.Call<int>("IsCharging");
  39. }
  40. return BATTERYSTATUS.BATTERY_STATUS_UNKNOWN;
  41. }
  42. }
  43. }
  44. }