CUI_touchpad.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. using System.Collections;
  3. using CurvedUI;
  4. public class CUI_touchpad : MonoBehaviour {
  5. #pragma warning disable 0649
  6. RectTransform container;
  7. [SerializeField] RectTransform dot;
  8. #pragma warning restore 0649
  9. #if CURVEDUI_STEAMVR_LEGACY
  10. CurvedUIViveController controller;
  11. void Start () {
  12. controller = CurvedUIInputModule.Right;
  13. //subscribe to event that will be fired every time a finger moves across the touchpad.
  14. controller.TouchpadAxisChanged += MoveDotOnTouchpadAxisChanged;
  15. }
  16. void Update()
  17. {
  18. //show / hide dot when touchpad is touched or not
  19. dot.gameObject.SetActive(controller.IsTouchpadTouched);
  20. }
  21. #endif
  22. void Awake()
  23. {
  24. container = this.transform as RectTransform;
  25. }
  26. void MoveDotOnTouchpadAxisChanged(object o, ViveInputArgs args)
  27. {
  28. //update dot position when touch position changes.
  29. dot.anchoredPosition = new Vector2(args.touchpadAxis.x * container.rect.width * 0.5f, args.touchpadAxis.y * container.rect.width * 0.5f);
  30. }
  31. }