PointerViewer.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // /******************************************************************************
  2. // * File: PointerViewer.cs
  3. // * Copyright (c) 2023 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
  4. // *
  5. // *
  6. // ******************************************************************************/
  7. using UnityEngine;
  8. using UnityEngine.InputSystem;
  9. namespace QCHT.Samples.Menu
  10. {
  11. public class PointerViewer : MonoBehaviour
  12. {
  13. [SerializeField] protected GameObject leftController;
  14. [SerializeField] protected GameObject rightController;
  15. [SerializeField] protected InputAction leftIsTracked;
  16. [SerializeField] protected InputAction rightIsTracked;
  17. [SerializeField] protected InputAction leftFlipRatio;
  18. [SerializeField] protected InputAction rightFlipRatio;
  19. protected bool updateRays = true;
  20. public bool UpdateRays
  21. {
  22. get => updateRays;
  23. set => updateRays = value;
  24. }
  25. private void OnEnable()
  26. {
  27. leftIsTracked.Enable();
  28. rightIsTracked.Enable();
  29. leftFlipRatio.Enable();
  30. rightFlipRatio.Enable();
  31. }
  32. private void OnDisable()
  33. {
  34. leftIsTracked.Disable();
  35. rightIsTracked.Disable();
  36. leftFlipRatio.Disable();
  37. rightFlipRatio.Disable();
  38. }
  39. protected virtual void Update()
  40. {
  41. if (!updateRays) return;
  42. leftController.SetActive(leftIsTracked.IsInProgress() && leftFlipRatio.ReadValue<float>() <= 0f);
  43. rightController.SetActive(rightIsTracked.IsInProgress() && rightFlipRatio.ReadValue<float>() <= 0f);
  44. }
  45. }
  46. }