//------------------------------------------------- void Awake() { if (attachEaseIn) { attachmentFlags &= ~Hand.AttachmentFlags.SnapOnAttach; } }
// Called every Update() while a Hand is hovering over this object private void HandHoverUpdate(Hand hand) { Hand.AttachmentFlags attachmentFlags = Hand.defaultAttachmentFlags; if ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip)) { if (hand.currentAttachedObject != gameObject) { // Call this to continue receiving HandHoverUpdate messages, and prevent the hand from hovering over anything else hand.HoverLock(GetComponent <Interactable>()); // Attach this object to the hand hand.AttachObject(gameObject, attachmentFlags); hand.transform.Find("ControllerHoverHighlight").gameObject.SetActive(false); hand.transform.Find("ControllerButtonHints").gameObject.SetActive(false); } else { activeHand = null; // Detach this object from the hand hand.DetachObject(gameObject); // Call this to undo HoverLock hand.HoverUnlock(GetComponent <Interactable>()); hand.transform.Find("ControllerHoverHighlight").gameObject.SetActive(true); hand.transform.Find("ControllerButtonHints").gameObject.SetActive(true); } } }
void Start() { if (grabposition != null) { attachmentFlags = Hand.AttachmentFlags.SnapOnAttach | attachmentFlags; } if (isDoubleHanded) { secondHand = GetComponentInChildren <SecondHanded>(); } }
//------------------------------------------------- void Awake() { velocityEstimator = GetComponent <VelocityEstimator>(); if (attachEaseIn) { attachmentFlags &= ~Hand.AttachmentFlags.SnapOnAttach; } Rigidbody rb = GetComponent <Rigidbody>(); rb.maxAngularVelocity = 50.0f; }
//------------------------------------------------- void Start() { //hand = GetComponentInParent<Hand>(); thr = GetComponent <Throwable>(); if (thr == null) { att = Hand.AttachmentFlags.ParentToHand; } else { att = thr.attachmentFlags; } }
//------------------------------------------------- void Awake() { gm = GetComponent <GameManager>(); keyObjectScript = GetComponent <KeyObject>(); velocityEstimator = GetComponent <VelocityEstimator>(); if (attachEaseIn) { attachmentFlags &= ~Hand.AttachmentFlags.SnapOnAttach; } Rigidbody rb = GetComponent <Rigidbody>(); rb.maxAngularVelocity = 50.0f; }
public void AttachObject(GameObject objectToAttach, Hand.AttachmentFlags flags = Hand.AttachmentFlags.SnapOnAttach | Hand.AttachmentFlags.DetachOthers | Hand.AttachmentFlags.DetachFromOtherHand | Hand.AttachmentFlags.ParentToHand, string attachmentPoint = "") { if (flags == (Hand.AttachmentFlags) 0) { flags = (Hand.AttachmentFlags.SnapOnAttach | Hand.AttachmentFlags.DetachOthers | Hand.AttachmentFlags.DetachFromOtherHand | Hand.AttachmentFlags.ParentToHand); } this.CleanUpAttachedObjectStack(); this.DetachObject(objectToAttach, true); if ((flags & Hand.AttachmentFlags.DetachFromOtherHand) == Hand.AttachmentFlags.DetachFromOtherHand && this.otherHand) { this.otherHand.DetachObject(objectToAttach, true); } if ((flags & Hand.AttachmentFlags.DetachOthers) == Hand.AttachmentFlags.DetachOthers) { while (this.attachedObjects.Count > 0) { this.DetachObject(this.attachedObjects[0].attachedObject, true); } } if (this.currentAttachedObject) { this.currentAttachedObject.SendMessage("OnHandFocusLost", this, SendMessageOptions.DontRequireReceiver); } Hand.AttachedObject item = default(Hand.AttachedObject); item.attachedObject = objectToAttach; item.originalParent = ((!(objectToAttach.transform.parent != null)) ? null : objectToAttach.transform.parent.gameObject); if ((flags & Hand.AttachmentFlags.ParentToHand) == Hand.AttachmentFlags.ParentToHand) { objectToAttach.transform.parent = this.GetAttachmentTransform(attachmentPoint); item.isParentedToHand = true; } else { item.isParentedToHand = false; } this.attachedObjects.Add(item); if ((flags & Hand.AttachmentFlags.SnapOnAttach) == Hand.AttachmentFlags.SnapOnAttach) { objectToAttach.transform.localPosition = Vector3.zero; objectToAttach.transform.localRotation = Quaternion.identity; } this.HandDebugLog("AttachObject " + objectToAttach); objectToAttach.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver); this.UpdateHovering(); }
//------------------------------------------------- protected virtual void Awake() { velocityEstimator = GetComponent <VelocityEstimator>(); interactable = GetComponent <Interactable>(); if (attachEaseIn) { attachmentFlags &= ~Hand.AttachmentFlags.SnapOnAttach; } rigidbody = GetComponent <Rigidbody>(); rigidbody.maxAngularVelocity = 50.0f; if (attachmentOffset != null) { interactable.handFollowTransform = attachmentOffset; } }
private void TeleportToHand(Hand pointerHand) { // Store default attachment flags Hand.AttachmentFlags attachmentFlags = Hand.defaultAttachmentFlags & ~Hand.AttachmentFlags.SnapOnAttach & ~Hand.AttachmentFlags.DetachOthers & ~Hand.AttachmentFlags.VelocityMovement; // Move object before attach otherwise the player remote controls the object transform.position = pointerHand.gameObject.transform.position + offset; // Attach object and store hand for future reference pointerHand.AttachObject(gameObject, GrabTypes.Grip, attachmentFlags); this.pointerHand = pointerHand; if (throwable) { throwable.Attach(); } // Reset material colour otherwise object stays green ResetMat(); }
//------------------------------------------------- // 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, Hand.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); if (((flags & Hand.AttachmentFlags.DetachFromOtherHand) == Hand.AttachmentFlags.DetachFromOtherHand)) { //Detach from the other hand if requested foreach (Hand otherHand in otherHandsThatCanGrabStuff) { if (otherHand) { otherHand.DetachObject(objectToAttach); } } foreach (PickUpAndDrop pUAD in allPickUpAndDropScripts) { if (pUAD && !pUAD.Equals(this)) { pUAD.DetachObject(objectToAttach); } } } if ((flags & Hand.AttachmentFlags.DetachOthers) == Hand.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); } Hand.AttachedObject attachedObject = new Hand.AttachedObject(); attachedObject.attachedObject = objectToAttach; attachedObject.originalParent = objectToAttach.transform.parent != null ? objectToAttach.transform.parent.gameObject : null; if ((flags & Hand.AttachmentFlags.ParentToHand) == Hand.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 & Hand.AttachmentFlags.SnapOnAttach) == Hand.AttachmentFlags.SnapOnAttach) { objectToAttach.transform.localPosition = Vector3.zero; objectToAttach.transform.localRotation = Quaternion.identity; } HandDebugLog("AttachObject " + objectToAttach); objectToAttach.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver); //objectToAttach.SendMessage( "OnAttachedToPUAD", this, SendMessageOptions.DontRequireReceiver ); //UpdateHovering(); }