RockerMove_VRTK.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using VRTK;
  5. public class RockerMove_VRTK : RockerMove
  6. {
  7. //平面移动
  8. [Header("仅XZ轴平面移动")]
  9. public bool planarMovement = false;
  10. //移动按键
  11. public SDK_BaseController.ButtonTypes moveBtn;
  12. //移动控制器
  13. public SDK_BaseController.ControllerHand moveHand = SDK_BaseController.ControllerHand.Right;
  14. public override void Update()
  15. {
  16. base.Update();
  17. VRTK_ControllerReference _controllerReference = VRTK_DeviceFinder.GetControllerReferenceRightHand();
  18. if (VRTK_SDK_Bridge.GetControllerButtonState(moveBtn, SDK_BaseController.ButtonPressTypes.PressDown
  19. , _controllerReference))
  20. {
  21. InitRockerPoint(_controllerReference.model.transform);
  22. }
  23. else if (VRTK_SDK_Bridge.GetControllerButtonState(moveBtn, SDK_BaseController.ButtonPressTypes.PressUp
  24. , _controllerReference))
  25. {
  26. Close();
  27. }
  28. }
  29. /// <summary>
  30. /// 移动方式
  31. /// </summary>
  32. public override void Move()
  33. {
  34. Vector3 _moveDir = holdPoint.position - rockerPoint.position;
  35. if (planarMovement)
  36. {
  37. _moveDir = new Vector3(_moveDir.x, 0, _moveDir.z);
  38. }
  39. cameraRig.transform.Translate(_moveDir * moveSpeed * Time.deltaTime, Space.World);
  40. }
  41. }