public void PageDriveAttached(Hand hand) { isDriving = true; attachedHandleType = hand.LastCollider.GetComponent <PageHandle>().handleType; switch (attachedHandleType) { case PageHandle.Type.Cover: baseProgress--; Book.pageMapping.value = 1f; SyncRigidbodyToMapping(1f); state = PageState.Cover; break; case PageHandle.Type.Back: Book.pageMapping.value = 0f; SyncRigidbodyToMapping(0f); state = PageState.Back; break; } Unlock(); if (leftHandColliders == null) { leftHandColliders = hand.GetComponent <HandPhysics>().handCollider.GetComponentsInChildren <Collider>(); SetLeftHandCollisionState(false); } }
private void Awake() { //Match up the hardware index with the "steamVR Hand2" //So the Hand2 is always the starting rightmost hand reletive to the HMD //Not sure why steamVR's select hand option doesn't do this, let me know if you figure it out hand1 = GameObject.Find("Hand1").GetComponent <Valve.VR.InteractionSystem.Hand>(); hand2 = GameObject.Find("Hand2").GetComponent <Valve.VR.InteractionSystem.Hand>(); trackedController1 = hand1.gameObject.GetComponent <SteamVR_TrackedController>(); trackedController2 = hand2.gameObject.GetComponent <SteamVR_TrackedController>(); trackedObject2 = hand2.GetComponent <SteamVR_TrackedObject>(); selectorHand = SteamVR_Controller.Input((int)trackedObject2.index); //This method depends on another steamVR method which fires 1s after the app starts. //The steamVR method finds the hardware indecies of the controllers Invoke("setControllerIndecies", 1.2f); }
private void Awake() { canvas.SetActive(false); hand.GetComponent <VRUIINPUT>().enabled = false; hand.GetComponent <SteamVR_LaserPointer>().enabled = false; }
void Update() { if (draggingBound) { if (lastAtomHovered != null && lastAtomHovered.GetComponent <AtomBehavior>().boundCount < lastAtomHovered.GetComponent <AtomBehavior>().maxBounds&& atomHovered.GetComponent <AtomBehavior>().boundCount < atomHovered.GetComponent <AtomBehavior>().maxBounds) { boundLength = Vector3.Distance(lastAtomHovered.transform.position, atomHovered.transform.position) / 2; currentBound.transform.LookAt(lastAtomHovered.transform); connected = true; } else { boundLength = Vector3.Distance(actingHand.transform.position, atomHovered.transform.position) / 2; currentBound.transform.LookAt(actingHand.transform); connected = false; TriggerVibration(1000); } Vector3 newScale = currentBound.transform.localScale; newScale.z = boundLength; currentBound.transform.localScale = newScale; } else if (creatingBound) { if (atomHovered) { currentBound = null; currentBound = Instantiate(bound, atomHovered.GetComponent <Transform>().position, atomHovered.GetComponent <Transform>().rotation); draggingBound = true; } } else if (dragging) { if (atomHovered != null) { atomHovered.transform.position = actingHand.GetComponent <Transform> ().position; TriggerVibration(1000); } } else if ((Input.GetKeyDown(KeyCode.JoystickButton14) || Input.GetKeyDown(KeyCode.JoystickButton15)) && available) { switch (atomCode) { case -2: if (hovered) { dragging = true; } break; case -1: if (hovered && atomHovered != null) { if (atomHovered.GetComponent <AtomBehavior> ().boundCount != 0) { foreach (GameObject b in atomHovered.GetComponent <AtomBehavior>().bounds) { listedBounds.Add(b); listedAtom1.Add(b); listedAtom2.Add(b); //Debug.Log(b.transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[0].GetComponent<AtomBehavior>().boundCount); //Debug.Log(b.transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[1]); // b.transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[0].GetComponent<AtomBehavior>().DeleteBound(b); // b.transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[1].GetComponent<AtomBehavior>().DeleteBound(b); //atomHovered.GetComponent<AtomBehavior>().DeleteBound(b); // Destroy(b);/* //[0].GetComponent<AtomBehavior>().DeleteBound(b); //b.transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[1].GetComponent<AtomBehavior>().DeleteBound(b); //*/ } foreach (GameObject b in listedAtom1) { Debug.Log(b); b.transform.Find("Cylinder").GetComponent <AtomBehavior>().linkedAtoms[0].GetComponent <AtomBehavior>().DeleteBound(b); } foreach (GameObject b in listedAtom2) { Debug.Log(b); b.transform.Find("Cylinder").GetComponent <AtomBehavior>().linkedAtoms[1].GetComponent <AtomBehavior>().DeleteBound(b); } foreach (GameObject b in listedBounds) { Debug.Log("Bound Destroy"); Destroy(b); } /* * for (int i = 0; i <= listedBounds.Count; i++) * { * if (listedBounds[i].transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[0] != atomHovered) * { * listedBounds[i].transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[0].GetComponent<AtomBehavior>().DeleteBound(listedBounds[i]); * } * else * { * listedBounds[i].transform.Find("Cylinder").GetComponent<AtomBehavior>().linkedAtoms[1].GetComponent<AtomBehavior>().DeleteBound(listedBounds[i]); * } * atomHovered.GetComponent<AtomBehavior>().DeleteBound(listedBounds[i]); * Destroy(listedBounds[i]); * * }*/ } Destroy(atomHovered); listedAtom1.Clear(); listedAtom2.Clear(); listedBounds.Clear(); } else if (hovered && boundHovered != null && !draggingBound) { boundHovered.GetComponent <AtomBehavior>().linkedAtoms[0].GetComponent <AtomBehavior>().DeleteBound(boundHovered.transform.parent.gameObject); boundHovered.GetComponent <AtomBehavior>().linkedAtoms[1].GetComponent <AtomBehavior>().DeleteBound(boundHovered.transform.parent.gameObject); Destroy(boundHovered.transform.parent.gameObject); } break; case 0: if (hovered) { creatingBound = true; } else { creatingBound = false; } break; case 1: Instantiate(hydrogen, actingHand.GetComponent <Transform> ().position, actingHand.GetComponent <Transform> ().rotation); TriggerVibration(1000); break; case 2: Instantiate(oxygen, actingHand.GetComponent <Transform> ().position, actingHand.GetComponent <Transform> ().rotation); TriggerVibration(1000); break; case 3: Instantiate(carbon, actingHand.GetComponent <Transform> ().position, actingHand.GetComponent <Transform> ().rotation); TriggerVibration(1000); break; default: break; } } if ((Input.GetKeyUp(KeyCode.JoystickButton14) || Input.GetKeyUp(KeyCode.JoystickButton15)) && selected) { available = true; creatingBound = false; dragging = false; if (draggingBound && connected && currentBound != null) { atomHovered.GetComponent <AtomBehavior> ().AddBound(currentBound); lastAtomHovered.GetComponent <AtomBehavior> ().AddBound(currentBound); currentBound.transform.Find("Cylinder").GetComponent <AtomBehavior> ().AddAtom(atomHovered); currentBound.transform.Find("Cylinder").GetComponent <AtomBehavior> ().AddAtom(lastAtomHovered); currentBound = null; draggingBound = false; } else { Destroy(currentBound); draggingBound = false; } if (lastAtomHovered != null) { atomHovered = lastAtomHovered; } lastAtomHovered = null; } }
// Update is called once per frame void Update() { if (player) { Hand h2 = player.hands[1]; if (parking && h2.isActiveAndEnabled) { if (h2.controller.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu)) { parking.SetActive(!parking.activeSelf); } } Hand h = player.hands[0]; if (h.isActiveAndEnabled) { if (h.controller.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger)) { h.GetComponent <SteamVR_LaserPointer>().thickness = (float)0.01; } else if (h.controller.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger)) { h.GetComponent <SteamVR_LaserPointer>().thickness = 0; drawer.SendMessage("toggleDrawF"); } } if ((h.controller.GetPress(EVRButtonId.k_EButton_Grip) && player.hands[1].controller.GetPressDown(EVRButtonId.k_EButton_Grip)) || (h.controller.GetPressDown(EVRButtonId.k_EButton_Grip) && player.hands[1].controller.GetPress(EVRButtonId.k_EButton_Grip))) { bothHands = true; Vectinit = h.transform.position - h2.transform.position; } if (!h.controller.GetPress(EVRButtonId.k_EButton_Grip) || !h2.controller.GetPress(EVRButtonId.k_EButton_Grip)) { bothHands = false; } //if (h.controller.GetPressDown(EVRButtonId.k_EButton_Grip) && player.hands[1].controller.GetPressDown(EVRButtonId.k_EButton_Grip)) //player.transform.Rotate(rotinit); //bothHands = h.controller.GetPress(EVRButtonId.k_EButton_Grip) && player.hands[1].controller.GetPress(EVRButtonId.k_EButton_Grip); if (!bothHands) { if (idOverwatchHand == 0) { if (h.controller.GetPressDown(EVRButtonId.k_EButton_Grip) && h.AttachedObjects.Count == 1) { idOverwatchHand = 1; initialPosition = new Vector3(h.transform.position.x, h.transform.position.y, h.transform.position.z); } else if (player.hands[1].controller.GetPressDown(EVRButtonId.k_EButton_Grip) && player.hands[1].AttachedObjects.Count == 1) { initialPosition = new Vector3(player.hands[1].transform.position.x, player.hands[1].transform.position.y, player.hands[1].transform.position.z); idOverwatchHand = 2; } } else { if (idOverwatchHand == 1 && h.controller.GetPress(EVRButtonId.k_EButton_Grip)) { player.transform.Translate(-h.controller.velocity * 3 / 5);//(player.hands[0].transform.position - initialPosition)*3; } else if (idOverwatchHand == 2 && player.hands[1].controller.GetPress(EVRButtonId.k_EButton_Grip)) { player.transform.Translate(-h2.controller.velocity * 3 / 5); //(player.hands[1].transform.position - initialPosition)*3; } if (player.transform.position.y < 0.5) { player.transform.position = new Vector3 { x = player.transform.position.x, y = (float)0.5, z = player.transform.position.z } } ; if ((idOverwatchHand == 1 && h.controller.GetPressUp(EVRButtonId.k_EButton_Grip)) || (idOverwatchHand == 2 && player.hands[1].controller.GetPressUp(EVRButtonId.k_EButton_Grip))) { idOverwatchHand = 0; } } } else { //Vector3 newVect = h.transform.position - h2.transform.position; // Vectinit.y = 0; newVect.y = 0; //player.transform.rotation.y = h2.controller.angularVelocity.y; // Vector3 hp1 = h.transform.position - player.transform.position, hp2 = h2.transform.position - player.transform.position, difh = h.transform.position - h2.transform.position; player.transform.Rotate(new Vector3(0, 1, 0), h2.controller.angularVelocity.y); // rotinit = player.transform.rotation.eulerAngles; } } }
//------------------------------------------------- private void HandAttachedUpdate(Hand hand) { if (bow == null) { FindBow(); } if (bow == null) { return; } if (allowArrowSpawn && (currentArrow == null)) // If we're allowed to have an active arrow in hand but don't yet, spawn one { currentArrow = InstantiateArrow(); arrowSpawnSound.Play(); } float distanceToNockPosition = Vector3.Distance(transform.parent.position, bow.nockTransform.position); // If there's an arrow spawned in the hand and it's not nocked yet if (!nocked) { // If we're close enough to nock position that we want to start arrow rotation lerp, do so if (distanceToNockPosition < rotationLerpThreshold) { float lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1); arrowNockTransform.rotation = Quaternion.Lerp(arrowNockTransform.parent.rotation, bow.nockRestTransform.rotation, lerp); } else // Not close enough for rotation lerp, reset rotation { arrowNockTransform.localRotation = Quaternion.identity; } // If we're close enough to the nock position that we want to start arrow position lerp, do so if (distanceToNockPosition < positionLerpThreshold) { float posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1); posLerp = Mathf.Clamp(posLerp, 0f, 1f); arrowNockTransform.position = Vector3.Lerp(arrowNockTransform.parent.position, bow.nockRestTransform.position, posLerp); } else // Not close enough for position lerp, reset position { arrowNockTransform.position = arrowNockTransform.parent.position; } // Give a haptic tick when lerp is visually complete if (distanceToNockPosition < lerpCompleteDistance) { if (!arrowLerpComplete) { arrowLerpComplete = true; hand.controller.TriggerHapticPulse(500); } } else { if (arrowLerpComplete) { arrowLerpComplete = false; } } // Allow nocking the arrow when controller is close enough if (distanceToNockPosition < nockDistance) { if (!inNockRange) { inNockRange = true; bow.ArrowInPosition(); } } else { if (inNockRange) { inNockRange = false; } } // If arrow is close enough to the nock position and we're pressing any of the recognized inputs, and we're not nocked yet, Nock if ((distanceToNockPosition < nockDistance) && hand.GetComponent <Controller>().inputPressed(inputs) && !nocked) { if (currentArrow == null) { currentArrow = InstantiateArrow(); } nocked = true; bow.StartNock(this); hand.HoverLock(GetComponent <Interactable>()); allowTeleport.teleportAllowed = false; currentArrow.transform.parent = bow.nockTransform; Util.ResetTransform(currentArrow.transform); Util.ResetTransform(arrowNockTransform); } } // If arrow is nocked, and we release a recognized input if (nocked && (!hand.GetComponent <Controller>().inputPressed(inputs) || hand.GetComponent <Controller>().inputUnpressing(inputs))) { if (bow.pulled) // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand { FireArrow(); } else { arrowNockTransform.rotation = currentArrow.transform.rotation; currentArrow.transform.parent = arrowNockTransform; Util.ResetTransform(currentArrow.transform); nocked = false; bow.ReleaseNock(); hand.HoverUnlock(GetComponent <Interactable>()); allowTeleport.teleportAllowed = true; } bow.StartRotationLerp(); // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation } }
// Interactable events // private void OnAttachedToHand(Hand hand) // "Called when this GameObject becomes attached to the hand" => stretchingController = hand.GetComponent <Controller>().otherController;