Power.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2016 Nibiru. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using NibiruTask;
  15. using UnityEngine;
  16. namespace NXR.Samples
  17. {
  18. [RequireComponent(typeof(TextMesh))]
  19. public class Power : MonoBehaviour
  20. {
  21. private TextMesh textField;
  22. private double power = 0;
  23. private bool IsNeedRefreshStatus = true;
  24. private void Start()
  25. {
  26. NibiruTaskApi.addOnPowerChangeListener(onPowerChanged);
  27. }
  28. public void onPowerChanged(double value)
  29. {
  30. power = value;
  31. }
  32. void Awake()
  33. {
  34. textField = GetComponent<TextMesh>();
  35. //// change keyboard postion or rotation
  36. // NibiruKeyBoard.Instance.keyBoardTransform.Rotate(new Vector3(30, 0, 0));
  37. // // show keyboard
  38. // NibiruKeyBoard.Instance.Show();
  39. }
  40. void Update()
  41. {
  42. if (textField != null)
  43. {
  44. textField.text = "Power:" + ((int)(power * 100)) + "%";
  45. }
  46. UpdateBluetoothAndNetwordStatus();
  47. }
  48. void UpdateBluetoothAndNetwordStatus()
  49. {
  50. if (!IsNeedRefreshStatus) return;
  51. // IsNeedRefreshStatus = false;
  52. // 0=off, 1=on
  53. int networkStatus = NibiruTaskApi.GetNetworkStatus();
  54. int bluetoothStatus = NibiruTaskApi.GetBluetoothStatus();
  55. GameObject.Find("Bluetooth").GetComponent<TextMesh>().text = "Bluetooth: " + (bluetoothStatus == 1 ? "on" : "off");
  56. GameObject.Find("Network").GetComponent<TextMesh>().text = "Network: " + (networkStatus == 1 ? "on" : "off");
  57. }
  58. private void OnDestroy()
  59. {
  60. NibiruTaskApi.removeOnPowerChangeListener(onPowerChanged);
  61. Debug.Log("Power.OnDestroy");
  62. }
  63. private void OnApplicationPause(bool pause)
  64. {
  65. Debug.Log("Power-OnApplicationPause." + pause);
  66. IsNeedRefreshStatus = !pause;
  67. }
  68. }
  69. }