TouchpadSample.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using NibiruTask;
  2. using Nxr.Internal;
  3. using UnityEngine;
  4. namespace NXR.Samples
  5. {
  6. public class TouchpadSample : MonoBehaviour
  7. {
  8. public GameObject sphere;
  9. private Vector3 sphereInitPos = new Vector3(0, 0.165f, 0);
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. if(sphere != null)
  14. {
  15. sphereInitPos = sphere.transform.localPosition;
  16. }
  17. }
  18. // Update is called once per frame
  19. void Update()
  20. {
  21. bool IsTouchpadTouched = false;
  22. if(NxrInput.GetControllerKeyPressed(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH) ||
  23. NxrInput.GetControllerKeyPressed(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH, InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) ||
  24. NxrInput.GetControllerKeyPressed(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD_TOUCH, InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT))
  25. {
  26. IsTouchpadTouched = true;
  27. }
  28. if (sphere != null)
  29. {
  30. if(IsTouchpadTouched)
  31. {
  32. Vector2 pos = InteractionManager.TouchPadPosition;
  33. sphere.transform.localPosition = sphereInitPos + new Vector3(pos.x/2, -pos.y/2, 0);
  34. } else
  35. {
  36. sphere.transform.localPosition = sphereInitPos;
  37. }
  38. }
  39. }
  40. }
  41. }