SW 중심대학 OSS GIT 서버 새로운 리포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.1 KiB

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.XR.Interaction.Toolkit;
  5. public class LocomotionController : MonoBehaviour
  6. {
  7. public XRController leftTeleportRay;
  8. public XRController rightTeleportRay;
  9. public InputHelpers.Button teleportActivationButton; //텔레포트 활성화 버튼
  10. public float activationThreshold = 0.1f; //살짝만 누르면 텔레포트 활성화 되도록
  11. //각 손의 텔레포트 활성화 할것인가? => UnityEvent 에서 설정
  12. public bool EnableLeftTeleport { get; set; } = true;
  13. public bool EnableRightTeleport { get; set; } = true;
  14. public XRRayInteractor leftRayInteractor;
  15. public XRRayInteractor rightRayInteractor;
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. //각 컨트롤러의 텔레포트를 활성화/비활성화
  20. if (leftTeleportRay)
  21. {
  22. //InteractorRay가 무엇에 닿았는가?
  23. bool isLeftInteractorRayHovering = leftRayInteractor.TryGetHitInfo(out Vector3 pos, out Vector3 norm, out int posInLine, out bool isValid);
  24. leftTeleportRay.gameObject.SetActive(CheckIfActivated(leftTeleportRay) && EnableLeftTeleport && !isLeftInteractorRayHovering);
  25. }
  26. if (rightTeleportRay)
  27. {
  28. bool isRightInteractorRayHovering = rightRayInteractor.TryGetHitInfo(out Vector3 pos, out Vector3 norm, out int posInLine, out bool isValid);
  29. rightTeleportRay.gameObject.SetActive(CheckIfActivated(rightTeleportRay) && EnableRightTeleport && !isRightInteractorRayHovering);
  30. }
  31. }
  32. //특정 컨트롤러의 특정 버튼이 눌렀는가? 를 리턴하는 함수
  33. public bool CheckIfActivated(XRController controller)
  34. {
  35. //controller의 활성화 버튼을 activationThreshold 이상으로 눌렀으면, 그 값을 저장하고 리턴
  36. InputHelpers.IsPressed(controller.inputDevice, teleportActivationButton, out bool isActivated, activationThreshold);
  37. return isActivated;
  38. }
  39. }