ModalThrowable.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Basic throwable object
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using System.Collections;
  9. namespace Valve.VR.InteractionSystem
  10. {
  11. public class ModalThrowable : Throwable
  12. {
  13. [Tooltip("The local point which acts as a positional and rotational offset to use while held with a grip type grab")]
  14. public Transform gripOffset;
  15. [Tooltip("The local point which acts as a positional and rotational offset to use while held with a pinch type grab")]
  16. public Transform pinchOffset;
  17. protected override void HandHoverUpdate(Hand hand)
  18. {
  19. GrabTypes startingGrabType = hand.GetGrabStarting();
  20. if (startingGrabType != GrabTypes.None)
  21. {
  22. if (startingGrabType == GrabTypes.Pinch)
  23. {
  24. hand.AttachObject(gameObject, startingGrabType, attachmentFlags, pinchOffset);
  25. }
  26. else if (startingGrabType == GrabTypes.Grip)
  27. {
  28. hand.AttachObject(gameObject, startingGrabType, attachmentFlags, gripOffset);
  29. }
  30. else
  31. {
  32. hand.AttachObject(gameObject, startingGrabType, attachmentFlags, attachmentOffset);
  33. }
  34. hand.HideGrabHint();
  35. }
  36. }
  37. protected override void HandAttachedUpdate(Hand hand)
  38. {
  39. if (interactable.skeletonPoser != null)
  40. {
  41. interactable.skeletonPoser.SetBlendingBehaviourEnabled("PinchPose", hand.currentAttachedObjectInfo.Value.grabbedWithType == GrabTypes.Pinch);
  42. }
  43. base.HandAttachedUpdate(hand);
  44. }
  45. }
  46. }