WristPanel.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using EZXR.Glass.Core;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Events;
  6. namespace EZXR.Glass.UI
  7. {
  8. [ScriptExecutionOrder(-1)]
  9. public class WristPanel : MonoBehaviour
  10. {
  11. private static WristPanel instance;
  12. #region 多例
  13. static WristPanel instance_Left;
  14. static WristPanel instance_Right;
  15. public static WristPanel Left
  16. {
  17. get
  18. {
  19. return instance_Left;
  20. }
  21. }
  22. public static WristPanel Right
  23. {
  24. get
  25. {
  26. return instance_Right;
  27. }
  28. }
  29. #endregion
  30. public enum WristType
  31. {
  32. Left,
  33. Right
  34. }
  35. public WristType wristType;
  36. public TextMesh battery;
  37. public TextMesh time;
  38. static SpatialTrigger spatialTrigger;
  39. private void Awake()
  40. {
  41. instance = this;
  42. if (wristType == WristType.Left)
  43. {
  44. instance_Left = this;
  45. }
  46. else
  47. {
  48. instance_Right = this;
  49. }
  50. }
  51. // Update is called once per frame
  52. void Update()
  53. {
  54. battery.text = SystemInfo.batteryLevel * 100 + "%";
  55. time.text = System.DateTime.Now.ToString("HH:mm");
  56. }
  57. /// <summary>
  58. /// 当手腕面板被触碰的时候回调
  59. /// </summary>
  60. /// <param name="action"></param>
  61. public void AddListener(UnityAction action)
  62. {
  63. if (spatialTrigger == null)
  64. {
  65. spatialTrigger = transform.Find("SpatialTrigger").GetComponent<SpatialTrigger>();
  66. }
  67. spatialTrigger.onTriggerEnter.AddListener(action);
  68. }
  69. public void RemoveListener(UnityAction action)
  70. {
  71. if (spatialTrigger == null)
  72. {
  73. spatialTrigger = transform.Find("SpatialTrigger").GetComponent<SpatialTrigger>();
  74. }
  75. spatialTrigger.onTriggerEnter.RemoveListener(action);
  76. }
  77. public void ClearListener()
  78. {
  79. if (spatialTrigger == null)
  80. {
  81. spatialTrigger = transform.Find("SpatialTrigger").GetComponent<SpatialTrigger>();
  82. }
  83. spatialTrigger.onTriggerEnter.RemoveAllListeners();
  84. }
  85. }
  86. }