示例#1
0
 //-------------------------------------------------
 // Called when a Hand starts hovering over this object
 //-------------------------------------------------
 private void OnHandHoverBegin(VRTRIXGloveGrab hand)
 {
     if (textMesh != null)
     {
         textMesh.text = "Hovering hand: " + hand.name;
     }
 }
示例#2
0
 //-------------------------------------------------
 private void OnAttachedToHand(VRTRIXGloveGrab hand)
 {
     if (onAttachedToHand != null)
     {
         onAttachedToHand.Invoke(hand);
     }
 }
示例#3
0
 //-------------------------------------------------
 private void OnDetachedFromHand(VRTRIXGloveGrab hand)
 {
     if (onDetachedFromHand != null)
     {
         onDetachedFromHand.Invoke(hand);
     }
 }
示例#4
0
 //-------------------------------------------------
 // Called when this GameObject is detached from the hand
 //-------------------------------------------------
 private void OnDetachedFromHand(VRTRIXGloveGrab hand)
 {
     if (textMesh != null)
     {
         textMesh.text = "Detached from hand: " + hand.name;
     }
 }
        //-------------------------------------------------
        private void HandAttachedUpdate(VRTRIXGloveGrab hand)
        {
            //Trigger got released
            if (!hand.GetStandardInteractionButton())
            {
                // 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 (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;
                }
            }
        }
示例#6
0
 //-------------------------------------------------
 // Called when a Hand stops hovering over this object
 //-------------------------------------------------
 private void OnHandHoverEnd(VRTRIXGloveGrab hand)
 {
     if (textMesh != null)
     {
         textMesh.text = "No Hand Hovering";
     }
 }
示例#7
0
 //-------------------------------------------------
 // Called every Update() while a Hand is hovering over this object
 //-------------------------------------------------
 private void HandHoverUpdate(VRTRIXGloveGrab hand)
 {
     //Debug.Log(VRTRIXGloveVRInteraction.GetGesture(hand.GetHandType()));
     if (hand.GetStandardInteractionButtonDown())
     {
         if (hand.currentAttachedObject != gameObject)
         {
             isHoveredbyHand = true;
             //Call this to continue receiving HandHoverUpdate messages,
             // and prevent the hand from hovering over anything else
             hand.HoverLock(GetComponent <VRTRIXInteractable>());
             if (hand.GetHandType() == HANDTYPE.LEFT_HAND)
             {
                 // Attach this object to the left hand
                 //hand.AttachObject(gameObject, attachmentFlags);
                 hand.AttachLongBow(gameObject, attachmentFlags, "L_Middle_1");
                 gameObject.transform.localPosition = new Vector3(-0.311f, 0.072f, 0.04f);
                 gameObject.transform.localRotation = Quaternion.Euler(0, 200f, 90f);
             }
             else if (hand.GetHandType() == HANDTYPE.RIGHT_HAND)
             {
                 hand.AttachLongBow(gameObject, attachmentFlags, "R_Middle_1");
                 gameObject.transform.localPosition = new Vector3(-0.311f, 0.072f, 0.04f);
                 gameObject.transform.localRotation = Quaternion.Euler(0, -20f, -90f);
             }
         }
     }
 }
示例#8
0
 //-------------------------------------------------
 // Called when this GameObject becomes attached to the hand
 //-------------------------------------------------
 private void OnAttachedToHand(VRTRIXGloveGrab hand)
 {
     if (textMesh != null)
     {
         textMesh.text = "Attached to hand: " + hand.name;
     }
     attachTime = Time.time;
 }
示例#9
0
 //-------------------------------------------------
 // Called when a Hand stops hovering over this object
 //-------------------------------------------------
 private void OnHandHoverEnd(VRTRIXGloveGrab hand)
 {
     //if (textMesh != null)
     //{
     //    textMesh.text = "No Hand Hovering";
     //}
     //isHoveredbyHand = false;
 }
示例#10
0
        //-------------------------------------------------
        private void OnHandHoverEnd(VRTRIXGloveGrab hand)
        {
            //if (!justPickedUpItem && requireTriggerPressToTake && showTriggerHint)
            //{
            //    ControllerButtonHints.HideTextHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
            //}

            justPickedUpItem = false;
        }
示例#11
0
        //-------------------------------------------------
        private void TakeBackItem(VRTRIXGloveGrab hand)
        {
            RemoveMatchingItemsFromHandStack(itemPackage, hand);

            if (itemPackage.packageType == VRTRIXGloveItemPackage.ItemPackageType.TwoHanded)
            {
                RemoveMatchingItemsFromHandStack(itemPackage, hand.otherHand);
            }
        }
示例#12
0
        //-------------------------------------------------
        // Called when a Hand starts hovering over this object
        //-------------------------------------------------
        private void OnHandHoverBegin(VRTRIXGloveGrab hand)
        {
            //if (textMesh != null)
            //{
            //    textMesh.text = "Hovering hand: " + hand.name;
            //}

            //isHoveredbyHand = true;
        }
 //-------------------------------------------------
 private void HandHoverUpdate(VRTRIXGloveGrab hand)
 {
     if (hand.GetPressButtonDown())
     {
         //InputModule.instance.Submit(gameObject);
         OnButtonClick();
         //ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
     }
 }
        //-------------------------------------------------
        private void HidePointer()
        {
            if (visible)
            {
                pointerHideStartTime = Time.time;
            }

            visible = false;
            if (pointerHand)
            {
                if (ShouldOverrideHoverLock())
                {
                    //Restore the original hovering interactable on the hand
                    if (originalHoverLockState == true)
                    {
                        pointerHand.HoverLock(originalHoveringInteractable);
                    }
                    else
                    {
                        pointerHand.HoverUnlock(null);
                    }
                }

                //Stop looping sound
                loopingAudioSource.Stop();
                PlayAudioClip(pointerAudioSource, pointerStopSound);
            }
            teleportPointerObject.SetActive(false);

            teleportArc.Hide();

            foreach (VRTRIXTeleportMarkerBase teleportMarker in teleportMarkers)
            {
                if (teleportMarker != null && teleportMarker.markerActive && teleportMarker.gameObject != null)
                {
                    teleportMarker.gameObject.SetActive(false);
                }
            }

            destinationReticleTransform.gameObject.SetActive(false);
            invalidReticleTransform.gameObject.SetActive(false);
            offsetReticleTransform.gameObject.SetActive(false);

            if (playAreaPreviewTransform != null)
            {
                playAreaPreviewTransform.gameObject.SetActive(false);
            }

            if (onActivateObjectTransform.gameObject.activeSelf)
            {
                onActivateObjectTransform.gameObject.SetActive(false);
            }
            onDeactivateObjectTransform.gameObject.SetActive(true);

            pointerHand = null;
        }
示例#15
0
 //-------------------------------------------------
 private void HandHoverUpdate(VRTRIXGloveGrab hand)
 {
     if (requireTriggerPressToTake)
     {
         if (hand.GetStandardInteractionButtonDown())
         {
             SpawnAndAttachObject(hand);
         }
     }
 }
 //-------------------------------------------------
 private void HandHoverUpdate(VRTRIXGloveGrab hand)
 {
     //Trigger got pressed
     //Debug.Log(hand.GetStandardInteractionButtonDown());
     if (hand.GetStandardInteractionButtonDown())
     {
         hand.AttachObject(gameObject, attachmentFlags, attachmentPoint);
         //ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
     }
 }
        //-------------------------------------------------
        private void OnHandHoverEnd(VRTRIXGloveGrab hand)
        {
            //InputModule.instance.HoverEnd(gameObject);
            //ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
            currentHand = null;
            ColorBlock cb = button.colors;

            cb.normalColor = new Color(0f, 0f, 255f);
            cb.normalColor = Color.blue;
            button.colors  = cb;
        }
示例#18
0
 //-------------------------------------------------
 private Transform GetPointerStartTransform(VRTRIXGloveGrab hand)
 {
     //if (hand.noSteamVRFallbackCamera != null)
     //{
     //    return hand.noSteamVRFallbackCamera.transform;
     //}
     //else
     //{
     return(hand.teleportArcStartTransform);
     //}
 }
示例#19
0
        //-------------------------------------------------
        private void FireExposure()
        {
            if (fireObject == null)
            {
                Invoke("StartBurning", ignitionDelay);
            }

            if (hand = GetComponentInParent <VRTRIXGloveGrab>())
            {
                //hand.controller.TriggerHapticPulse( 1000 );
            }
        }
        //-------------------------------------------------
        private void OnDetachedFromHand(VRTRIXGloveGrab hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            Rigidbody rb = GetComponent <Rigidbody>();

            rb.isKinematic   = false;
            rb.interpolation = RigidbodyInterpolation.Interpolate;

            Vector3 position        = Vector3.zero;
            Vector3 velocity        = Vector3.zero;
            Vector3 angularVelocity = Vector3.zero;

            //if (hand.controller == null)
            //{
            velocityEstimator.FinishEstimatingVelocity();
            velocity        = velocityEstimator.GetVelocityEstimate();
            angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
            position        = velocityEstimator.transform.position;
            //}
            //else
            //{
            //    velocity = Player.instance.trackingOriginTransform.TransformVector(hand.controller.velocity);
            //    angularVelocity = Player.instance.trackingOriginTransform.TransformVector(hand.controller.angularVelocity);
            //    position = hand.transform.position;
            //}

            Vector3 r = transform.TransformPoint(rb.centerOfMass) - position;

            rb.velocity        = velocity + Vector3.Cross(angularVelocity, r);
            rb.angularVelocity = angularVelocity;

            // Make the object travel at the release velocity for the amount
            // of time it will take until the next fixed update, at which
            // point Unity physics will take over
            float timeUntilFixedUpdate = (Time.fixedDeltaTime + Time.fixedTime) - Time.time;

            transform.position += timeUntilFixedUpdate * velocity;
            float   angle = Mathf.Rad2Deg * angularVelocity.magnitude;
            Vector3 axis  = angularVelocity.normalized;

            transform.rotation *= Quaternion.AngleAxis(angle * timeUntilFixedUpdate, axis);
        }
        //-------------------------------------------------
        private bool WasTeleportButtonPressed(VRTRIXGloveGrab hand)
        {
            if (IsEligibleForTeleport(hand))
            {
                //if (hand.noSteamVRFallbackCamera != null)
                //{
                //    return Input.GetKeyDown(KeyCode.T);
                //}
                //else
                //{
                //return hand.controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad);
                //}
                return(hand.GetTeleportButtonDown());
            }

            return(false);
        }
示例#22
0
 //-------------------------------------------------
 // Called every Update() while this GameObject is attached to the hand
 //-------------------------------------------------
 private void HandAttachedUpdate(VRTRIXGloveGrab hand)
 {
     if (textMesh != null)
     {
         textMesh.text = "Attached to hand: " + hand.name + "\nAttached time: " + (Time.time - attachTime).ToString("F2");
     }
     if (!hand.GetStandardInteractionButton())
     {
         // 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));
     }
 }
示例#23
0
        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);
        }
示例#24
0
        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);
        }
        //-------------------------------------------------
        private void OnAttachedToHand(VRTRIXGloveGrab hand)
        {
            attached = true;

            onPickUp.Invoke();

            hand.HoverLock(null);

            Rigidbody rb = GetComponent <Rigidbody>();

            rb.isKinematic   = true;
            rb.interpolation = RigidbodyInterpolation.None;
            velocityEstimator.BeginEstimatingVelocity();
            //if (hand.controller == null)
            //{
            //    velocityEstimator.BeginEstimatingVelocity();
            //}

            attachTime     = Time.time;
            attachPosition = transform.position;
            attachRotation = transform.rotation;

            if (attachEaseIn)
            {
                attachEaseInTransform = hand.transform;
                if (!Util.IsNullOrEmpty(attachEaseInAttachmentNames))
                {
                    float smallestAngle = float.MaxValue;
                    for (int i = 0; i < attachEaseInAttachmentNames.Length; i++)
                    {
                        Transform t     = hand.GetAttachmentTransform(attachEaseInAttachmentNames[i]);
                        float     angle = Quaternion.Angle(t.rotation, attachRotation);
                        if (angle < smallestAngle)
                        {
                            attachEaseInTransform = t;
                            smallestAngle         = angle;
                        }
                    }
                }
            }

            snapAttachEaseInCompleted = false;
        }
        ////-------------------------------------------------
        //public void ShowTeleportHint()
        //{
        //    CancelTeleportHint();

        //    hintCoroutine = StartCoroutine(TeleportHintCoroutine());
        //}


        //-------------------------------------------------
        //public void CancelTeleportHint()
        //{
        //    if (hintCoroutine != null)
        //    {
        //        foreach (Hand hand in player.hands)
        //        {
        //            ControllerButtonHints.HideTextHint(hand, EVRButtonId.k_EButton_SteamVR_Touchpad);
        //        }

        //        StopCoroutine(hintCoroutine);
        //        hintCoroutine = null;
        //    }

        //    CancelInvoke("ShowTeleportHint");
        //}


        ////-------------------------------------------------
        //private IEnumerator TeleportHintCoroutine()
        //{
        //    float prevBreakTime = Time.time;
        //    float prevHapticPulseTime = Time.time;

        //    while (true)
        //    {
        //        bool pulsed = false;

        //        //Show the hint on each eligible hand
        //        foreach (Hand hand in player.hands)
        //        {
        //            bool showHint = IsEligibleForTeleport(hand);
        //            bool isShowingHint = !string.IsNullOrEmpty(ControllerButtonHints.GetActiveHintText(hand, EVRButtonId.k_EButton_SteamVR_Touchpad));
        //            if (showHint)
        //            {
        //                if (!isShowingHint)
        //                {
        //                    ControllerButtonHints.ShowTextHint(hand, EVRButtonId.k_EButton_SteamVR_Touchpad, "Teleport");
        //                    prevBreakTime = Time.time;
        //                    prevHapticPulseTime = Time.time;
        //                }

        //                if (Time.time > prevHapticPulseTime + 0.05f)
        //                {
        //                    //Haptic pulse for a few seconds
        //                    pulsed = true;

        //                    hand.controller.TriggerHapticPulse(500);
        //                }
        //            }
        //            else if (!showHint && isShowingHint)
        //            {
        //                ControllerButtonHints.HideTextHint(hand, EVRButtonId.k_EButton_SteamVR_Touchpad);
        //            }
        //        }

        //        if (Time.time > prevBreakTime + 3.0f)
        //        {
        //            //Take a break for a few seconds
        //            yield return new WaitForSeconds(3.0f);

        //            prevBreakTime = Time.time;
        //        }

        //        if (pulsed)
        //        {
        //            prevHapticPulseTime = Time.time;
        //        }

        //        yield return null;
        //    }
        //}


        //-------------------------------------------------
        public bool IsEligibleForTeleport(VRTRIXGloveGrab hand)
        {
            if (hand == null)
            {
                return(false);
            }

            if (!hand.gameObject.activeInHierarchy)
            {
                return(false);
            }

            if (hand.hoveringInteractable != null)
            {
                return(false);
            }

            //if (hand.noSteamVRFallbackCamera == null)
            //{
            //    if (hand.controller == null)
            //    {
            //        return false;
            //    }

            //    //Something is attached to the hand
            //    if (hand.currentAttachedObject != null)
            //    {
            //        AllowTeleportWhileAttachedToHand allowTeleportWhileAttachedToHand = hand.currentAttachedObject.GetComponent<AllowTeleportWhileAttachedToHand>();

            //        if (allowTeleportWhileAttachedToHand != null && allowTeleportWhileAttachedToHand.teleportAllowed == true)
            //        {
            //            return true;
            //        }
            //        else
            //        {
            //            return false;
            //        }
            //    }
            //}

            return(true);
        }
示例#27
0
        //-------------------------------------------------
        private VRTRIXGloveItemPackage GetAttachedItemPackage(VRTRIXGloveGrab hand)
        {
            GameObject currentAttachedObject = hand.currentAttachedObject;

            if (currentAttachedObject == null) // verify the hand is holding something
            {
                return(null);
            }

            VRTRIXGloveItemPacakgeReference packageReference = hand.currentAttachedObject.GetComponent <VRTRIXGloveItemPacakgeReference>();

            if (packageReference == null) // verify the item in the hand is matchable
            {
                return(null);
            }

            VRTRIXGloveItemPackage attachedItemPackage = packageReference.itemPackage; // return the ItemPackage reference we find.

            return(attachedItemPackage);
        }
        //-------------------------------------------------
        private Transform GetPointerStartTransform(VRTRIXGloveGrab hand)
        {
            //if (hand.noSteamVRFallbackCamera != null)
            //{
            //    return hand.noSteamVRFallbackCamera.transform;
            //}
            //else
            //{

            if (hand.GetHandType() == HANDTYPE.LEFT_HAND)
            {
                return(GameObject.Find("L_Middle_3").transform);
            }
            else if (hand.GetHandType() == HANDTYPE.RIGHT_HAND)
            {
                return(GameObject.Find("R_Middle_3").transform);
            }
            return(null);
            //}
        }
示例#29
0
        //-------------------------------------------------
        // Called every Update() while a Hand is hovering over this object
        //-------------------------------------------------
        private void HandHoverUpdate(VRTRIXGloveGrab hand)
        {
            //Debug.Log(VRTRIXGloveVRInteraction.GetGesture(hand.GetHandType()));
            if (hand.GetStandardInteractionButtonDown())
            {
                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 <VRTRIXInteractable>());

                    // Attach this object to the hand
                    hand.AttachObject(gameObject, attachmentFlags);
                }
            }
        }
        //-------------------------------------------------
        private void OnHandHoverBegin(VRTRIXGloveGrab hand)
        {
            //bool showHint = false;

            // "Catch" the throwable by holding down the interaction button instead of pressing it.
            // Only do this if the throwable is moving faster than the prescribed threshold speed,
            // and if it isn't attached to another hand
            if (!attached)
            {
                if (hand.GetStandardInteractionButton())
                {
                    Rigidbody rb = GetComponent <Rigidbody>();
                    if (rb.velocity.magnitude >= catchSpeedThreshold)
                    {
                        hand.AttachObject(gameObject, attachmentFlags, attachmentPoint);
                        //showHint = false;
                    }
                }
            }
        }