public DetachObject ( GameObject objectToDetach, bool restoreOriginalParent = true ) : void | ||
objectToDetach | GameObject | The GameObject to detach from this VRHand |
restoreOriginalParent | bool | |
return | void |
/// <summary> /// Called every Update() while a VRHand is hovering over me. /// </summary> /// <param name="hand"></param> void HandHoverUpdate( VRHand hand ) { if ( hand.GetStandardInteractionButtonDown() || ( ( hand.controller != null ) && hand.controller.GetPressDown( Valve.VR.EVRButtonId.k_EButton_Grip ) ) ) { if ( hand.currentAttachedObject != gameObject ) { // Save our position/rotation so that we can restore it when we detach oldPosition = transform.position; oldRotation = transform.rotation; // Call this to continue receiving HandHoverUpdate messages, // and prevent the hand from hovering over anything else hand.HoverLock( GetComponent<VRInteractable>() ); // Attach this object to the hand hand.AttachObject( gameObject, false ); } else { // Detach this object from the hand hand.DetachObject( gameObject ); // Call this to undo HoverLock hand.HoverUnlock( GetComponent<VRInteractable>() ); // Restore position/rotation transform.position = oldPosition; transform.rotation = oldRotation; } } }
/// <summary> /// Attach a GameObject to this GameObject. /// </summary> /// <param name="objectToAttach">The GameObject to attach.</param> /// <param name="flags">The flags to use for attaching the object.</param> /// <param name="attachmentPoint">Name of the GameObject in the hierarchy of this VRHand which should act as the attachment point for this GameObject.</param> /// <seealso cref="DetachObject"/> public void AttachObject(GameObject objectToAttach, AttachmentFlags flags = defaultAttachmentFlags, string attachmentPoint = "") { if (flags == 0) { flags = defaultAttachmentFlags; } //Make sure top object on stack is non-null CleanUpAttachedObjectStack(); //Detach the object if it is already attached so that it can get re-attached at the top of the stack DetachObject(objectToAttach); //Detach from the other hand if requested if (((flags & AttachmentFlags.DetachFromOtherHand) == AttachmentFlags.DetachFromOtherHand) && otherHand) { otherHand.DetachObject(objectToAttach); } if ((flags & AttachmentFlags.DetachOthers) == AttachmentFlags.DetachOthers) { //Detach all the objects from the stack while (attachedObjects.Count > 0) { DetachObject(attachedObjects[0].attachedObject); } } if (currentAttachedObject) { currentAttachedObject.SendMessage("OnHandFocusLost", this, SendMessageOptions.DontRequireReceiver); } AttachedObject attachedObject = new AttachedObject(); attachedObject.attachedObject = objectToAttach; attachedObject.originalParent = objectToAttach.transform.parent != null ? objectToAttach.transform.parent.gameObject : null; if ((flags & AttachmentFlags.ParentToHand) == AttachmentFlags.ParentToHand) { //Parent the object to the hand objectToAttach.transform.parent = GetAttachmentTransform(attachmentPoint); attachedObject.isParentedToHand = true; } else { attachedObject.isParentedToHand = false; } attachedObjects.Add(attachedObject); if ((flags & AttachmentFlags.SnapOnAttach) == AttachmentFlags.SnapOnAttach) { objectToAttach.transform.localPosition = Vector3.zero; objectToAttach.transform.localRotation = Quaternion.identity; } VRHandDebugLog("AttachObject " + objectToAttach); objectToAttach.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver); UpdateHovering(); }
/// <summary> /// Called every Update() while a VRHand is hovering over me. /// </summary> /// <param name="hand"></param> void HandHoverUpdate(VRHand hand) { if (hand.GetStandardInteractionButtonDown() || ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip))) { if (hand.currentAttachedObject != gameObject) { // Save our position/rotation so that we can restore it when we detach oldPosition = transform.position; oldRotation = transform.rotation; // Call this to continue receiving HandHoverUpdate messages, // and prevent the hand from hovering over anything else hand.HoverLock(GetComponent <VRInteractable>()); // Attach this object to the hand hand.AttachObject(gameObject, attachmentFlags); } else { // Detach this object from the hand hand.DetachObject(gameObject); // Call this to undo HoverLock hand.HoverUnlock(GetComponent <VRInteractable>()); // Restore position/rotation transform.position = oldPosition; transform.rotation = oldRotation; } } }
void HandAttachedUpdate( VRHand hand ) { //Trigger got released if ( hand.GetStandardInteractionButtonUp() ) { hand.DetachObject( gameObject ); } }
void HandAttachedUpdate(VRHand hand) { //Trigger got released if (hand.GetStandardInteractionButtonUp()) { hand.DetachObject(gameObject); } }
/// <summary> /// Attach a GameObject to this GameObject. /// </summary> /// <param name="objectToAttach">The GameObject to attach.</param> /// <param name="snapOnAttach">Should the GameObject snap to an attachment point?</param> /// <param name="attachmentPoint">Name of the GameObject in the hierarchy of this VRHand which should act as the attachment point for this GameObject.</param> /// <param name="detachOthers">Should all other attached objects in the attached object stack of this VRHand be detached?</param> /// <seealso cref="DetachObject"/> public void AttachObject(GameObject objectToAttach, bool snapOnAttach = true, string attachmentPoint = "", bool detachOthers = true) { //Make sure top object on stack is non-null CleanUpAttachedObjectStack(); //Detach the object if it is already attached so that it can get re-attached at the top of the stack DetachObject(objectToAttach); if (otherHand) { otherHand.DetachObject(objectToAttach); } if (detachOthers) { //Detach all the objects from the stack while (attachedObjects.Count > 0) { DetachObject(attachedObjects[0].attachedObject); } } if (currentAttachedObject) { currentAttachedObject.SendMessage("OnHandFocusLost", this, SendMessageOptions.DontRequireReceiver); } AttachedObject attachedObject = new AttachedObject(); attachedObject.attachedObject = objectToAttach; attachedObject.originalParent = objectToAttach.transform.parent != null ? objectToAttach.transform.parent.gameObject : null; attachedObjects.Add(attachedObject); //Parent the object to the hand objectToAttach.transform.parent = GetAttachmentTransform(attachmentPoint); if (snapOnAttach) { objectToAttach.transform.localPosition = Vector3.zero; objectToAttach.transform.localRotation = Quaternion.identity; } objectToAttach.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver); UpdateHovering(); }
IEnumerator LateDetach( VRHand hand ) { yield return new WaitForEndOfFrame(); hand.DetachObject( gameObject, restoreOriginalParent ); }
IEnumerator LateDetach(VRHand hand) { yield return(new WaitForEndOfFrame()); hand.DetachObject(gameObject, restoreOriginalParent); }