123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using EZXR.Glass.Core;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- namespace EZXR.Glass.UI
- {
- [ScriptExecutionOrder(-1)]
- public class WristPanel : MonoBehaviour
- {
- private static WristPanel instance;
- #region 多例
- static WristPanel instance_Left;
- static WristPanel instance_Right;
- public static WristPanel Left
- {
- get
- {
- return instance_Left;
- }
- }
- public static WristPanel Right
- {
- get
- {
- return instance_Right;
- }
- }
- #endregion
- public enum WristType
- {
- Left,
- Right
- }
- public WristType wristType;
- public TextMesh battery;
- public TextMesh time;
- static SpatialTrigger spatialTrigger;
- private void Awake()
- {
- instance = this;
- if (wristType == WristType.Left)
- {
- instance_Left = this;
- }
- else
- {
- instance_Right = this;
- }
- }
- // Update is called once per frame
- void Update()
- {
- battery.text = SystemInfo.batteryLevel * 100 + "%";
- time.text = System.DateTime.Now.ToString("HH:mm");
- }
- /// <summary>
- /// 当手腕面板被触碰的时候回调
- /// </summary>
- /// <param name="action"></param>
- public void AddListener(UnityAction action)
- {
- if (spatialTrigger == null)
- {
- spatialTrigger = transform.Find("SpatialTrigger").GetComponent<SpatialTrigger>();
- }
- spatialTrigger.onTriggerEnter.AddListener(action);
- }
- public void RemoveListener(UnityAction action)
- {
- if (spatialTrigger == null)
- {
- spatialTrigger = transform.Find("SpatialTrigger").GetComponent<SpatialTrigger>();
- }
- spatialTrigger.onTriggerEnter.RemoveListener(action);
- }
- public void ClearListener()
- {
- if (spatialTrigger == null)
- {
- spatialTrigger = transform.Find("SpatialTrigger").GetComponent<SpatialTrigger>();
- }
- spatialTrigger.onTriggerEnter.RemoveAllListeners();
- }
- }
- }
|