CVR_InteractableVRTK_ChildOfController.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. namespace ChivaXR.VR
  2. {
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using VRTK.GrabAttachMechanics;
  7. public class CVR_InteractableVRTK_ChildOfController : CVR_InteractableVRTK
  8. {
  9. private VRTK_ChildOfControllerGrabAttach childGrabAttach;
  10. private Rigidbody rigidbody_Interactable;
  11. protected override void Awake()
  12. {
  13. InitInteractable();
  14. base.Awake();
  15. }
  16. /// <summary>
  17. /// 初始化交互功能属性
  18. /// </summary>
  19. private void InitInteractable()
  20. {
  21. rigidbody_Interactable = this.GetComponent<Rigidbody>() == null
  22. ? this.gameObject.AddComponent<Rigidbody>()
  23. : this.GetComponent<Rigidbody>();
  24. childGrabAttach = this.GetComponent<VRTK_ChildOfControllerGrabAttach>() == null
  25. ? this.gameObject.AddComponent<VRTK_ChildOfControllerGrabAttach>()
  26. : this.GetComponent<VRTK_ChildOfControllerGrabAttach>();
  27. this.isUsable = true;
  28. this.useOnlyIfGrabbed = true;
  29. this.isGrabbable = true;
  30. this.holdButtonToGrab = false;
  31. this.holdButtonToUse = true;
  32. if (this.grabAttachMechanicScript == null)
  33. {
  34. this.grabAttachMechanicScript = childGrabAttach;
  35. childGrabAttach.precisionGrab = true;
  36. }
  37. rigidbody_Interactable.isKinematic = true;
  38. rigidbody_Interactable.useGravity = false;
  39. }
  40. }
  41. }