//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(ValveVR.Hand hand) { ValveVR.GrabTypes startingGrabType = hand.GetGrabStarting(); bool isGrabEnding = hand.IsGrabEnding(this.gameObject); if (interactable.attachedToHand == null && startingGrabType != ValveVR.GrabTypes.None) { // 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(interactable); // Attach this object to the hand hand.AttachObject(gameObject, startingGrabType, attachmentFlags); } else if (isGrabEnding) { // Detach this object from the hand hand.DetachObject(gameObject); // Call this to undo HoverLock hand.HoverUnlock(interactable); // Restore position/rotation //transform.position = oldPosition; //transform.rotation = oldRotation; } }
void OnPause() { if (storedItem) { storedItem.transform.parent = null; storedItem.GetComponent <Rigidbody>().isKinematic = false; storedItem = null; } //the funny way to make items get dropped from hand if (otherHand.AttachedObjects.Count > 0) { otherHand.DetachObject(otherHand.AttachedObjects[0].attachedObject); } }
//------------------------------------------------- private void RemoveMatchingItemsFromHandStack(ItemPackage package, Hand hand) { if (hand == null) { return; } for (int i = 0; i < hand.AttachedObjects.Count; i++) { ItemPackageReference packageReference = hand.AttachedObjects[i].attachedObject.GetComponent <ItemPackageReference>(); if (packageReference != null) { ItemPackage attachedObjectItemPackage = packageReference.itemPackage; if ((attachedObjectItemPackage != null) && (attachedObjectItemPackage == package)) { GameObject detachedItem = hand.AttachedObjects[i].attachedObject; hand.DetachObject(detachedItem); } } } }
//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(Hand hand) { if (hand.GetStandardInteractionButtonDown() || ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip))) { if (hand.currentAttachedObject != gameObject) { hand.HoverLock(GetComponent <Interactable>()); // 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 <Interactable>()); } } }
private void HandHoverUpdate(Hand hand) { UnityEngine.Debug.Log("Hover"); if (hand.GetStandardInteractionButtonDown() || ((hand.controller != null) && hand.controller.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip))) { if (hand.currentAttachedObject != gameObject) { UnityEngine.Debug.Log("Attatch"); //Orienting to hand this.transform.position = hand.transform.position; this.transform.rotation = Quaternion.Euler(hand.transform.rotation.eulerAngles + grabOrientation); //Locking for detatchment hand.HoverLock(GetComponent <Interactable>()); hand.AttachObject(gameObject, attatchmentFlags); //Used for velocity gathering isActive = true; //Connecting to hand with Joint //CreateHandJoint(); //handJoint.connectedBody = hand.GetComponent<Rigidbody>(); } } else if (hand.GetStandardInteractionButtonUp() || ((hand.controller != null) && hand.controller.GetPressUp(Valve.VR.EVRButtonId.k_EButton_Grip))) { if (hand.currentAttachedObject == gameObject) { UnityEngine.Debug.Log("Detatch"); hand.DetachObject(gameObject); hand.HoverUnlock(GetComponent <Interactable> ()); isActive = false; //Disconnecting handJoint //Destroy(handJoint); } } }
//------------------------------------------------- protected virtual void HandAttachedUpdate(Hand hand) { // CHANGE: added check for scripted grab type -> means that the release of the object es // managed separately and the object should not be released if the button is released if (hand.IsGrabEnding(this.gameObject) && GetGrabbingType(hand, this.gameObject) != GrabTypes.Scripted) { hand.DetachObject(gameObject, restoreOriginalParent); // Uncomment to detach ourselves late in the frame. // This is so that any vehicles the player is attached to // have a chance to finish updating themselves. // If we detach now, our position could be behind what it // will be at the end of the frame, and the object may appear // to teleport behind the hand when the player releases it. //StartCoroutine( LateDetach( hand ) ); } if (onHeldUpdate != null) { onHeldUpdate.Invoke(hand); } }
//------------------------------------------------- protected virtual void HandAttachedUpdate(Hand hand) { currentHand = hand; if (hand.IsGrabEnding(this.gameObject)) { hand.DetachObject(gameObject, restoreOriginalParent); // Uncomment to detach ourselves late in the frame. // This is so that any vehicles the player is attached to // have a chance to finish updating themselves. // If we detach now, our position could be behind what it // will be at the end of the frame, and the object may appear // to teleport behind the hand when the player releases it. //StartCoroutine( LateDetach( hand ) ); } if (onHeldUpdate != null) { onHeldUpdate.Invoke(hand); } }
public void disableComponentsForWaiting() { // Detach the pill from the hand holding it Valve.VR.InteractionSystem.Hand handHoldingPill = simManagerComponent.getHandScriptHoldingObj(waitPill); if (handHoldingPill != null) { handHoldingPill.DetachObject(waitPill); } justWait = true; waitBucketPlatform.SetActive(true); payPanel.SetActive(false); payPill.SetActive(false); waitPill.SetActive(false); payPedestal.SetActive(false); waitPedestal.SetActive(false); treatmentInformationPanel.SetActive(false); payBottlePositionA = new Vector3(NULL_POS, NULL_POS, NULL_POS); payBottlePositionB = new Vector3(NULL_POS, NULL_POS, NULL_POS); waitBottlePositionA = new Vector3(NULL_POS, NULL_POS, NULL_POS); waitBottlePositionB = new Vector3(NULL_POS, NULL_POS, NULL_POS); }
//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(Hand 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 <Interactable>()); // Attach this object to the hand hand.AttachObject(gameObject, attachmentFlags); // if (this.gameObject.tag == "Strip") { // Joint joint4 = GameObject.Find.name ("joint4"); // // Joint fixedJoint = joint4.gameObject.AddComponent<FixedJoint>(); // fixedJoint.connectedBody = hand; // } } else { // Detach this object from the hand hand.DetachObject(gameObject); // Call this to undo HoverLock hand.HoverUnlock(GetComponent <Interactable>()); // Restore position/rotation transform.position = oldPosition; transform.rotation = oldRotation; } } }
//------------------------------------------------- protected virtual void HandAttachedUpdate(Hand hand) { if (attachEaseIn) { float t = Util.RemapNumberClamped(Time.time, attachTime, attachTime + snapAttachEaseInTime, 0.0f, 1.0f); if (t < 1.0f) { t = snapAttachEaseInCurve.Evaluate(t); transform.position = Vector3.Lerp(attachPosition, attachEaseInTransform.position, t); transform.rotation = Quaternion.Lerp(attachRotation, attachEaseInTransform.rotation, t); } else if (!snapAttachEaseInCompleted) { gameObject.SendMessage("OnThrowableAttachEaseInCompleted", hand, SendMessageOptions.DontRequireReceiver); snapAttachEaseInCompleted = true; } } if (hand.IsGrabEnding(this.gameObject)) { hand.DetachObject(gameObject, restoreOriginalParent); // Uncomment to detach ourselves late in the frame. // This is so that any vehicles the player is attached to // have a chance to finish updating themselves. // If we detach now, our position could be behind what it // will be at the end of the frame, and the object may appear // to teleport behind the hand when the player releases it. //StartCoroutine( LateDetach( hand ) ); } if (onHeldUpdate != null) { onHeldUpdate.Invoke(hand); } }
/* * Attempt to make a transaction - validate that the participant * can afford it, and then call out as necessary to apply changes * to the environment to reflect the transaction. */ private bool attemptObtain(TreatmentObtainType t) { float effectiveWaitTime = -1.0f; // Seconds float effectiveCost = -1.0f; // Lab dollars bool transactionValid = false; SimManager.GameState currentSimState = simManagerComponent.currentState(); if (t == TreatmentObtainType.PAY) { effectiveCost = simManagerComponent.getCurrentTreatmentCost(); transactionValid = ( currentSimState == SimManager.GameState.RUNNING && simManagerComponent.getCurrentScore() > effectiveCost ); } else if (t == TreatmentObtainType.WAIT) { effectiveWaitTime = simManagerComponent.getCurrentTreatmentWaitTime(); transactionValid = currentSimState == SimManager.GameState.RUNNING; } // Only apply changes to the environment if the transaction was approved if (transactionValid) { if (t != TreatmentObtainType.WAIT) { disablePanels(); } simManagerComponent.determinePostTreatmentActions(t, effectiveCost, effectiveWaitTime); } else { // Play a quick error sound to make them realize it didn't work audioManagerComponent.playSound(AudioManager.SoundType.ERROR); Debug.Log("Invalid treatment obtain attempt. Resetting " + t.ToString() + " bottle position."); if (t == TreatmentObtainType.PAY) { // Detach the pill from the hand holding it Valve.VR.InteractionSystem.Hand handHoldingPill = simManagerComponent.getHandScriptHoldingObj(payPill); if (handHoldingPill != null) { handHoldingPill.DetachObject(payPill); } // Then, reset its position payPill.transform.position = new Vector3( payBottleInitXPosition, payBottleInitYPosition, payBottleInitZPosition ); payPill.transform.eulerAngles = new Vector3(0.0f, 0.0f, 0.0f); payBottlePositionA = payPill.transform.position; } else if (t == TreatmentObtainType.WAIT) { // Detach the pill from the hand holding it Valve.VR.InteractionSystem.Hand handHoldingPill = simManagerComponent.getHandScriptHoldingObj(waitPill); if (handHoldingPill != null) { handHoldingPill.DetachObject(waitPill); } // Then, reset its position waitPill.transform.position = new Vector3( waitBottleInitXPosition, waitBottleInitYPosition, waitBottleInitZPosition ); waitPill.transform.eulerAngles = new Vector3(0.0f, 0.0f, 0.0f); waitBottlePositionA = waitPill.transform.position; } else { Debug.Log("Unrecognized bottle type. Not resetting position."); } } return(transactionValid); }
//------------------------------------------------- protected virtual IEnumerator LateDetach(Hand hand) { yield return(new WaitForEndOfFrame()); hand.DetachObject(gameObject, restoreOriginalParent); }
//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(Hand hand) { //Debug.DrawLine(transform.position, transform.position + transform.forward, Color.blue); //Debug.DrawLine(transform.position, transform.position + transform.up, Color.green); //Debug.DrawLine(transform.position, transform.position + transform.right, Color.red); GrabTypes startingGrabType = hand.GetGrabStarting(); GrabTypes endingGrabType = hand.GetGrabEnding(); bool isGrabEnding = hand.IsGrabEnding(this.gameObject); if (interactable.attachedToHand == null) { if (startingGrabType != GrabTypes.None) { hand.HoverLock(interactable); hand.AttachObject(gameObject, startingGrabType, attachmentFlags); } } else { if (startingGrabType == GrabTypes.Pinch) { magicCircle = Instantiate(magicCirclePrefab, transform.position + transform.up * 3, Quaternion.identity); magicCircle.transform.LookAt(transform.position); point = Instantiate(pointPrefab, magicCircle.transform.position, Quaternion.identity); } if (hand.IsGrabbingWithType(GrabTypes.Pinch)) { // 마법 발동? 그리기 // holy 12365416851651561651456561561shit magicEffect.SetActive(true); if (Physics.Raycast(transform.position, transform.up, out RaycastHit hit, Mathf.Infinity)) { Debug.Log(hit.transform.name); if (hit.transform.CompareTag("paint") || hit.transform.CompareTag("paintTrigger")) { point.transform.position = hit.point; if (hit.transform.CompareTag("paintTrigger") && !isPointTrigger) { isPointTrigger = true; hand.hapticAction.Execute(0, 0.1f, 1, 30, hand.handType); line.positionCount++; line.SetPosition(line.positionCount - 1, hit.transform.position + hit.transform.forward * 0.1f); } else if (hit.transform.CompareTag("paint") && isPointTrigger) { isPointTrigger = false; } } } } if (endingGrabType == GrabTypes.Pinch) { magicEffect.SetActive(false); Destroy(magicCircle.gameObject); Destroy(point.gameObject); line.positionCount = 0; } if (startingGrabType == GrabTypes.Grip) { // 내려놓기 // 굳이 없어도 될듯? hand.DetachObject(gameObject); hand.HoverUnlock(interactable); } } }
//------------------------------------------------- // 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 = "") { 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; } HandDebugLog("AttachObject " + objectToAttach); objectToAttach.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver); UpdateHovering(); }
public void DetachFromHand(Hand hand) { hand.DetachObject(gameObject, restoreOriginalParent); }
//------------------------------------------------- private void HandHoverUpdate(Hand hand) { // ebaender worldPlaneNormal = new Vector3(0f, 0f, 0f); worldPlaneNormal[(int)axisOfRotation] = 1.0f; // ebaender if (transform.parent) { worldPlaneNormal = transform.parent.localToWorldMatrix.MultiplyVector(worldPlaneNormal).normalized; } GrabTypes startingGrabType = hand.GetGrabStarting(); bool isGrabEnding = hand.IsGrabbingWithType(grabbedWithType) == false; currentCoverLimit = Book.coverMapping.value * Book.hingeMaxLimit; if (grabbedWithType == GrabTypes.None) { if (startingGrabType == GrabTypes.Pinch && hand == Player.instance.leftHand) { grabbedWithType = startingGrabType; // Trigger was just pressed lastHandProjected = ComputeToTransformProjected(hand.hoverSphereTransform); if (hoverLock) { hand.HoverLock(interactable); handHoverLocked = hand; } driving = true; ComputeSimpleAngle(hand); UpdateAll(); hand.HideGrabHint(); // ebaender - attach hand hand.AttachObject(gameObject, startingGrabType, attachmentFlags); } else if (startingGrabType == GrabTypes.Grip) { if (hand == Player.instance.rightHand && hand.LastCollider.GetComponent <PageHandle>().handleType == PageHandle.Type.Back) { hand.LastCollider = Book.lowerBackHandle.GetComponent <Collider>(); hand.LastCollider.GetComponentInParent <BookThrowable>().SendMessage("HandHoverUpdate", hand); } else if (hand == Player.instance.leftHand && hand.LastCollider.GetComponent <PageHandle>().handleType == PageHandle.Type.Cover) { if (Book.pagePhysicsController.AttachedToBack) { hand.LastCollider = Book.lowerCoverHandle.GetComponent <Collider>(); hand.LastCollider.GetComponentInParent <CoverDrive>().SendMessage("HandHoverUpdate", hand); } } } } else if (grabbedWithType != GrabTypes.None && isGrabEnding) { // Trigger was just released if (hoverLock) { hand.HoverUnlock(interactable); handHoverLocked = null; } driving = false; grabbedWithType = GrabTypes.None; // ebaender - detach hand hand.DetachObject(gameObject); } if (driving && isGrabEnding == false && hand.hoveringInteractable == this.interactable) { ComputeSimpleAngle(hand); UpdateAll(); } }
void RPCDetachOthers() { Hand hand = GetComponent <InteractableNetworked>().hand; hand.DetachObject(gameObject); }