예제 #1
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);
             }
         }
     }
 }
        //-------------------------------------------------
        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;
        }
예제 #3
0
        //-------------------------------------------------
        public void StartNock(VRTRIXGloveArrowHand currentArrowHand)
        {
            arrowHand = currentArrowHand;
            hand.HoverLock(GetComponent <VRTRIXInteractable>());
            nocked                = true;
            nockLerpStartTime     = Time.time;
            nockLerpStartRotation = pivotTransform.rotation;

            // Sound of arrow sliding on nock as it's being pulled back
            arrowSlideSound.Play();

            // Decide which hand we're drawing with and lerp to the correct side
            DoHandednessCheck();
        }
        //-------------------------------------------------
        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;
        }
예제 #5
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);
                }
            }
        }
예제 #6
0
        //-------------------------------------------------
        private void HandAttachedUpdate(VRTRIXGloveGrab 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 the trigger, and we're not nocked yet, Nock
                if ((distanceToNockPosition < nockDistance) && hand.GetStandardInteractionButtonDown() && !nocked)
                {
                    if (currentArrow == null)
                    {
                        currentArrow = InstantiateArrow();
                    }

                    nocked = true;
                    bow.StartNock(this);
                    hand.HoverLock(GetComponent <VRTRIXInteractable>());
                    allowTeleport.teleportAllowed = false;
                    currentArrow.transform.parent = bow.nockTransform;
                    Util.ResetTransform(currentArrow.transform);
                    Util.ResetTransform(arrowNockTransform);
                }
            }


            // If arrow is nocked, and we release the trigger
            if (nocked && (!hand.GetStandardInteractionButtonDown()))
            {
                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 <VRTRIXInteractable>());
                    allowTeleport.teleportAllowed = true;
                }

                bow.StartRotationLerp(); // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation
            }
        }
        //-------------------------------------------------
        private void ShowPointer(VRTRIXGloveGrab newPointerHand, VRTRIXGloveGrab oldPointerHand)
        {
            if (!visible)
            {
                pointedAtTeleportMarker = null;
                pointerShowStartTime    = Time.time;
                visible    = true;
                meshFading = true;

                teleportPointerObject.SetActive(false);
                teleportArc.Show();

                foreach (VRTRIXTeleportMarkerBase teleportMarker in teleportMarkers)
                {
                    if (teleportMarker.markerActive && teleportMarker.ShouldActivate(player.feetPositionGuess))
                    {
                        teleportMarker.gameObject.SetActive(true);
                        teleportMarker.Highlight(false);
                    }
                }

                startingFeetOffset = player.trackingOriginTransform.position - player.feetPositionGuess;
                movedFeetFarEnough = false;

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

                loopingAudioSource.clip = pointerLoopSound;
                loopingAudioSource.loop = true;
                loopingAudioSource.Play();
                loopingAudioSource.volume = 0.0f;
            }


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

            pointerHand = newPointerHand;

            if (visible && oldPointerHand != pointerHand)
            {
                PlayAudioClip(pointerAudioSource, pointerStartSound);
            }

            if (pointerHand)
            {
                pointerStartTransform = GetPointerStartTransform(pointerHand);
                //print(pointerStartTransform);

                if (pointerHand.currentAttachedObject != null)
                {
                    allowTeleportWhileAttached = pointerHand.currentAttachedObject.GetComponent <VRTRIXAllowTeleportWhileAttachedToHand>();
                }

                //Keep track of any existing hovering interactable on the hand
                originalHoverLockState       = pointerHand.hoverLocked;
                originalHoveringInteractable = pointerHand.hoveringInteractable;

                if (ShouldOverrideHoverLock())
                {
                    pointerHand.HoverLock(null);
                }

                pointerAudioSource.transform.SetParent(pointerStartTransform);
                pointerAudioSource.transform.localPosition = Vector3.zero;

                loopingAudioSource.transform.SetParent(pointerStartTransform);
                loopingAudioSource.transform.localPosition = Vector3.zero;
            }
        }