//------------------------------------------------- private void RemoveMatchingItemTypesFromHand(VRTRIXGloveItemPackage.ItemPackageType packageType, VRTRIXGloveGrab hand) { for (int i = 0; i < hand.AttachedObjects.Count; i++) { VRTRIXGloveItemPacakgeReference packageReference = hand.AttachedObjects[i].attachedObject.GetComponent <VRTRIXGloveItemPacakgeReference>(); if (packageReference != null) { if (packageReference.itemPackage.packageType == packageType) { GameObject detachedItem = hand.AttachedObjects[i].attachedObject; hand.DetachObject(detachedItem); } } } }
private IEnumerator LateDetach(VRTRIXGloveGrab hand) { yield return(new WaitForEndOfFrame()); //Debug.Log(hand.currentAttachedObject); if (hand.currentAttachedObject == gameObject) { // Detach this object from the hand hand.DetachObject(gameObject); // Call this to undo HoverLock hand.HoverUnlock(GetComponent <VRTRIXInteractable>()); isHoveredbyHand = false; } // hand.DetachObject(gameObject); }
private IEnumerator LateDetach(VRTRIXGloveGrab hand) { yield return(new WaitForEndOfFrame()); //Debug.Log(hand.currentAttachedObject); if (hand.currentAttachedObject == gameObject) { // Detach this object from the hand hand.DetachObject(gameObject); // Call this to undo HoverLock hand.HoverUnlock(GetComponent <VRTRIXInteractable>()); // Restore position/rotation transform.position = oldPosition; transform.rotation = oldRotation; } // hand.DetachObject(gameObject); }
//------------------------------------------------- // Attach a GameObject to this GameObject // // objectToAttach - The GameObject to attach // flags - The flags to use for attaching the object // attachmentPoint - Name of the GameObject in the hierarchy of this Hand which should act as the attachment point for this GameObject //------------------------------------------------- public void AttachObject(GameObject objectToAttach, AttachmentFlags flags = defaultAttachmentFlags, string attachmentPoint = "") { //Debug.Log("AttachObject1 " + objectToAttach); 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) { //Debug.Log("Flag: " + flags); otherHand.DetachObject(objectToAttach); } if ((flags & AttachmentFlags.DetachOthers) == AttachmentFlags.DetachOthers) { //Debug.Log("Flag: " + flags); //Detach all the objects from the stack while (attachedObjects.Count > 0) { DetachObject(attachedObjects[0].attachedObject); } } if (currentAttachedObject) { //Debug.Log("Flag: " + flags); currentAttachedObject.SendMessage("OnHandFocusLost", this, SendMessageOptions.DontRequireReceiver); } AttachedObject attachedObject = new AttachedObject(); attachedObject.attachedObject = objectToAttach; attachedObject.originalParent = objectToAttach.transform.parent != null ? objectToAttach.transform.parent.gameObject : null; //Debug.Log(attachedObject.originalParent); if ((flags & AttachmentFlags.ParentToHand) == AttachmentFlags.ParentToHand) { //Debug.Log("Flag: " + flags); //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) { //Debug.Log("Flag: " + flags); objectToAttach.transform.localPosition = Vector3.zero; objectToAttach.transform.localRotation = Quaternion.identity; } Debug.Log("AttachObject " + objectToAttach); objectToAttach.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver); UpdateHovering(); }
//------------------------------------------------- private IEnumerator LateDetach(VRTRIXGloveGrab hand) { yield return(new WaitForEndOfFrame()); hand.DetachObject(gameObject, restoreOriginalParent); }