HandTouchUIDemo.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using EZXR.Glass.Inputs;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class HandTouchUIDemo : MonoBehaviour
  7. {
  8. public Text keyTipsText;
  9. public Slider sliderView;
  10. public Text sliderValueText;
  11. public GameObject canvasHandler;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. if (canvasHandler != null)
  16. {
  17. canvasHandler.GetComponent<CanvasHandler>().enabled = true;
  18. canvasHandler.GetComponent<CanvasTouchHandler>().enabled = false;
  19. }
  20. }
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. if (Input.GetKeyDown(KeyCode.E) && canvasHandler != null)
  25. {
  26. if (canvasHandler.GetComponent<CanvasHandler>().enabled)
  27. {
  28. canvasHandler.GetComponent<CanvasHandler>().enabled = false;
  29. canvasHandler.GetComponent<CanvasTouchHandler>().enabled = true;
  30. }
  31. else
  32. {
  33. canvasHandler.GetComponent<CanvasHandler>().enabled = true;
  34. canvasHandler.GetComponent<CanvasTouchHandler>().enabled = false;
  35. }
  36. }
  37. }
  38. public void OnSiliderChanged()
  39. {
  40. sliderValueText.text = sliderView.value.ToString();
  41. }
  42. public void OnButtonClicked()
  43. {
  44. keyTipsText.text = $"{Time.frameCount}";
  45. }
  46. }