8 using System.Collections;
10 namespace Valve.VR.InteractionSystem
13 [RequireComponent( typeof( Interactable ) )]
16 private TextMesh textMesh;
17 private Vector3 oldPosition;
18 private Quaternion oldRotation;
20 private float attachTime;
22 private Hand.AttachmentFlags attachmentFlags = Hand.defaultAttachmentFlags & ( ~
Hand.AttachmentFlags.SnapOnAttach ) & ( ~
Hand.AttachmentFlags.DetachOthers );
27 textMesh = GetComponentInChildren<TextMesh>();
28 textMesh.text =
"No Hand Hovering";
35 private void OnHandHoverBegin(
Hand hand )
37 textMesh.text =
"Hovering hand: " + hand.name;
44 private void OnHandHoverEnd(
Hand hand )
46 textMesh.text =
"No Hand Hovering";
53 private void HandHoverUpdate(
Hand hand )
55 if ( hand.GetStandardInteractionButtonDown() || ( ( hand.controller != null ) && hand.controller.GetPressDown( Valve.VR.EVRButtonId.k_EButton_Grip ) ) )
57 if ( hand.currentAttachedObject != gameObject )
60 oldPosition = transform.position;
61 oldRotation = transform.rotation;
65 hand.HoverLock( GetComponent<Interactable>() );
68 hand.AttachObject( gameObject, attachmentFlags );
73 hand.DetachObject( gameObject );
76 hand.HoverUnlock( GetComponent<Interactable>() );
79 transform.position = oldPosition;
80 transform.rotation = oldRotation;
89 private void OnAttachedToHand(
Hand hand )
91 textMesh.text =
"Attached to hand: " + hand.name;
92 attachTime = Time.time;
99 private void OnDetachedFromHand(
Hand hand )
101 textMesh.text =
"Detached from hand: " + hand.name;
108 private void HandAttachedUpdate(
Hand hand )
110 textMesh.text =
"Attached to hand: " + hand.name +
"\nAttached time: " + ( Time.time - attachTime ).ToString(
"F2" );
117 private void OnHandFocusAcquired(
Hand hand )
125 private void OnHandFocusLost(
Hand hand )