//------------------------------------------------- private void OnDetachedFromHand(Hand hand) { lastHeld = Time.time; if (onDetachedFromHand != null) { onDetachedFromHand.Invoke(hand); } Vector3 aux = Player.instance.trackingOriginTransform.TransformVector(hand.controller.velocity); Debug.Log("WE ARE DETACHED FROM LIFE AND LOVE!"); if (hand.GetInstanceID() == Hand1.GetInstanceID()) { script.startPoint = Hand1.transform.position; script.endPoint = Hand2.transform.position; script.heightVector = aux; if (2.0f * aux.y > Mathf.Sqrt(aux.x * aux.x + aux.z * aux.z) && aux.y > 0.03f) { script.followTrajectory = true; } else { script.followTrajectory = false; } } if (hand.GetInstanceID() == Hand2.GetInstanceID()) { script.startPoint = Hand2.transform.position; script.endPoint = Hand1.transform.position; script.heightVector = aux; if (2.0f * aux.y > Mathf.Sqrt(aux.x * aux.x + aux.z * aux.z) && aux.y > 0.03f) { script.followTrajectory = true; } else { script.followTrajectory = false; } } script.count = 0.0f; if (hand.GuessCurrentHandType() == Hand.HandType.Right) { } if (hand.GuessCurrentHandType() == Hand.HandType.Left) { } }
//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(Hand hand) { if (hand.GuessCurrentHandType() == Hand.HandType.Right) { // Trigger gets pulled if (hand.GetStandardInteractionButtonDown()) { // Hand is not already holding this object if (hand.currentAttachedObject != gameObject) { // Hand is hovering over toolbox item if (isFake) { // Spawn a new item and attach it GameObject newPiece = Instantiate(gMan.tools[pieceIndex]) as GameObject; //newPiece.transform.localScale *= growthMod; newPiece.transform.position = hand.transform.position; newPiece.transform.rotation = hand.transform.rotation; newPiece.GetComponent <Movable>().isFake = false; // Call this to continue receiving HandHoverUpdate messages, // and prevent the hand from hovering over anything else hand.HoverLock(newPiece.GetComponent <Interactable>()); // Attach this object to the hand hand.AttachObject(newPiece, newPiece.GetComponent <Movable>().attachmentFlags); } else { // Call this to continue receiving HandHoverUpdate messages, // and prevent the hand from hovering over anything else hand.HoverLock(GetComponent <Interactable>()); // Unsnap in case if (this.GetComponent <SnappingScript>()) { GetComponent <SnappingScript>().Unsnap(); } //this.GetComponentInChildren<MeshCollider>().convex = false; // if it's the ball enable physics if (this.GetComponentInChildren <Ball>()) { this.GetComponentInChildren <Rigidbody>().isKinematic = true; } // Attach this object to the hand hand.AttachObject(gameObject, attachmentFlags); } } } } }
private void OnDrawGizmos() { if (this != Player.instance) { return; } Gizmos.color = Color.white; Gizmos.DrawIcon(this.feetPositionGuess, "vr_interaction_system_feet.png"); Gizmos.color = Color.cyan; Gizmos.DrawLine(this.feetPositionGuess, this.feetPositionGuess + this.trackingOriginTransform.up * this.eyeHeight); Gizmos.color = Color.blue; Vector3 bodyDirectionGuess = this.bodyDirectionGuess; Vector3 b = Vector3.Cross(this.trackingOriginTransform.up, bodyDirectionGuess); Vector3 vector = this.feetPositionGuess + this.trackingOriginTransform.up * this.eyeHeight * 0.75f; Vector3 vector2 = vector + bodyDirectionGuess * 0.33f; Gizmos.DrawLine(vector, vector2); Gizmos.DrawLine(vector2, vector2 - 0.033f * (bodyDirectionGuess + b)); Gizmos.DrawLine(vector2, vector2 - 0.033f * (bodyDirectionGuess - b)); Gizmos.color = Color.red; int handCount = this.handCount; for (int i = 0; i < handCount; i++) { Hand hand = this.GetHand(i); if (hand.startingHandType == Hand.HandType.Left) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_left_hand.png"); } else if (hand.startingHandType == Hand.HandType.Right) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_right_hand.png"); } else { Hand.HandType handType = hand.GuessCurrentHandType(); if (handType == Hand.HandType.Left) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_left_hand_question.png"); } else if (handType == Hand.HandType.Right) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_right_hand_question.png"); } else { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_unknown_hand.png"); } } } }
//------------------------------------------------- // Called when a Hand stops hovering over this object //------------------------------------------------- private void OnHandHoverEnd(Hand hand) { if (hand.GuessCurrentHandType() == Hand.HandType.Right) { //Debug.Log("No Hand Hovering"); if (isFake) { //Debug.Log("Fake offHover"); // Decrease the size slightly this.transform.localScale -= new Vector3(uiGrowth, uiGrowth, uiGrowth); } } }
//------------------------------------------------- private void EvaluateHandedness() { var handType = hand.GuessCurrentHandType(); if (handType == Hand.HandType.Left) // Bow hand is further left than arrow hand. { // We were considering a switch, but the current controller orientation matches our currently assigned handedness, so no longer consider a switch if (possibleHandSwitch && currentHandGuess == Handedness.Left) { possibleHandSwitch = false; } // If we previously thought the bow was right-handed, and were not already considering switching, start considering a switch if (!possibleHandSwitch && currentHandGuess == Handedness.Right) { possibleHandSwitch = true; timeOfPossibleHandSwitch = Time.time; } // If we are considering a handedness switch, and it's been this way long enough, switch if (possibleHandSwitch && Time.time > (timeOfPossibleHandSwitch + timeBeforeConfirmingHandSwitch)) { currentHandGuess = Handedness.Left; possibleHandSwitch = false; } } else // Bow hand is further right than arrow hand { // We were considering a switch, but the current controller orientation matches our currently assigned handedness, so no longer consider a switch if (possibleHandSwitch && currentHandGuess == Handedness.Right) { possibleHandSwitch = false; } // If we previously thought the bow was right-handed, and were not already considering switching, start considering a switch if (!possibleHandSwitch && currentHandGuess == Handedness.Left) { possibleHandSwitch = true; timeOfPossibleHandSwitch = Time.time; } // If we are considering a handedness switch, and it's been this way long enough, switch if (possibleHandSwitch && Time.time > (timeOfPossibleHandSwitch + timeBeforeConfirmingHandSwitch)) { currentHandGuess = Handedness.Right; possibleHandSwitch = false; } } }
//------------------------------------------------- // Called when a Hand starts hovering over this object //------------------------------------------------- private void OnHandHoverBegin(Hand hand) { if (hand.GuessCurrentHandType() == Hand.HandType.Right) { //Debug.Log("Hovering hand:" + hand.name); if (isFake) { //Debug.Log(this.name); // Increase the size slightly, try and vibrate briefly? this.transform.localScale += new Vector3(uiGrowth, uiGrowth, uiGrowth); // Vibrate briefly gMan.vibeRight(); } } }
//------------------------------------------------- void OnDrawGizmos() { if (this != instance) { return; } //NOTE: These gizmo icons don't work in the plugin since the icons need to exist in a specific "Gizmos" // folder in your Asset tree. These icons are included under Core/Icons. Moving them into a // "Gizmos" folder should make them work again. Gizmos.color = Color.white; Gizmos.DrawIcon(feetPositionGuess, "vr_interaction_system_feet.png"); Gizmos.color = Color.cyan; Gizmos.DrawLine(feetPositionGuess, feetPositionGuess + trackingOriginTransform.up * eyeHeight); // Body direction arrow Gizmos.color = Color.blue; Vector3 bodyDirection = bodyDirectionGuess; Vector3 bodyDirectionTangent = Vector3.Cross(trackingOriginTransform.up, bodyDirection); Vector3 startForward = feetPositionGuess + trackingOriginTransform.up * eyeHeight * 0.75f; Vector3 endForward = startForward + bodyDirection * 0.33f; Gizmos.DrawLine(startForward, endForward); Gizmos.DrawLine(endForward, endForward - 0.033f * (bodyDirection + bodyDirectionTangent)); Gizmos.DrawLine(endForward, endForward - 0.033f * (bodyDirection - bodyDirectionTangent)); Gizmos.color = Color.red; int count = handCount; for (int i = 0; i < count; i++) { Hand hand = GetHand(i); if (hand.startingHandType == Hand.HandType.Left) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_left_hand.png"); } else if (hand.startingHandType == Hand.HandType.Right) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_right_hand.png"); } else { Hand.HandType guessHandType = hand.GuessCurrentHandType(); if (guessHandType == Hand.HandType.Left) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_left_hand_question.png"); } else if (guessHandType == Hand.HandType.Right) { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_right_hand_question.png"); } else { Gizmos.DrawIcon(hand.transform.position, "vr_interaction_system_unknown_hand.png"); } } } }