Example #1
0
 //-------------------------------------------------
 // Stop hovering over this object indefinitely.
 //
 // interactable - The hover-locked Interactable to stop hovering over indefinitely.
 //-------------------------------------------------
 public void HoverUnlock(VRTRIXInteractable interactable)
 {
     //Debug.Log("HoverUnlock " + interactable);
     if (hoveringInteractable == interactable)
     {
         hoverLocked = false;
     }
 }
Example #2
0
        private void UpdateHovering()
        {
            //if ((noSteamVRFallbackCamera == null) && (controller == null))
            //{
            //    return;
            //}

            if (hoverLocked)
            {
                return;
            }

            //if (applicationLostFocusObject.activeSelf)
            //    return;


            float closestDistance = float.MaxValue;
            VRTRIXInteractable closestInteractable = null;

            // Pick the closest hovering
            float flHoverRadiusScale   = transform.lossyScale.x;
            float flScaledSphereRadius = hoverSphereRadius * flHoverRadiusScale;
            // if we're close to the floor, increase the radius to make things easier to pick up
            float handDiff = Mathf.Abs(transform.position.y);
            float boxMult  = Util.RemapNumberClamped(handDiff, 0.0f, 0.5f * flHoverRadiusScale, 5.0f, 1.0f) * flHoverRadiusScale;

            // null out old vals
            for (int i = 0; i < overlappingColliders.Length; ++i)
            {
                overlappingColliders[i] = null;
            }
            //Debug.Log(new Vector3(0, flScaledSphereRadius * boxMult - flScaledSphereRadius, 0));
            Physics.OverlapBoxNonAlloc(
                hoverSphereTransform.position - new Vector3(0, flScaledSphereRadius * boxMult - flScaledSphereRadius, 0),
                new Vector3(flScaledSphereRadius, flScaledSphereRadius * boxMult * 2.0f, flScaledSphereRadius),
                overlappingColliders,
                Quaternion.identity,
                hoverLayerMask.value
                );

            // DebugVar
            int iActualColliderCount = 0;

            foreach (Collider collider in overlappingColliders)
            {
                if (collider == null)
                {
                    continue;
                }

                VRTRIXInteractable contacting = collider.GetComponentInParent <VRTRIXInteractable>();

                // Yeah, it's null, skip
                if (contacting == null)
                {
                    continue;
                }

                // Ignore this collider for hovering
                IgnoreHovering ignore = collider.GetComponent <IgnoreHovering>();
                if (ignore != null)
                {
                    if (ignore.onlyIgnoreHand == null || ignore.onlyIgnoreHand == this)
                    {
                        continue;
                    }
                }

                // Can't hover over the object if it's attached
                if (attachedObjects.FindIndex(l => l.attachedObject == contacting.gameObject) != -1)
                {
                    continue;
                }

                // Occupied by another hand, so we can't touch it
                if (otherHand && otherHand.hoveringInteractable == contacting)
                {
                    continue;
                }

                // Best candidate so far...
                float distance = Vector3.Distance(contacting.transform.position, hoverSphereTransform.position);
                if (distance < closestDistance)
                {
                    closestDistance     = distance;
                    closestInteractable = contacting;
                }
                iActualColliderCount++;
            }

            // Hover on this one
            hoveringInteractable = closestInteractable;
            //if(closestInteractable != null)
            //{
            //    Debug.Log(closestInteractable.gameObject);
            //}


            if (iActualColliderCount > 0 && iActualColliderCount != prevOverlappingColliders)
            {
                prevOverlappingColliders = iActualColliderCount;
                Debug.Log("Found " + iActualColliderCount + " overlapping colliders.");
            }
        }
Example #3
0
 //-------------------------------------------------
 // Continue to hover over this object indefinitely, whether or not the Hand moves out of its interaction trigger volume.
 //
 // interactable - The Interactable to hover over indefinitely.
 //-------------------------------------------------
 public void HoverLock(VRTRIXInteractable interactable)
 {
     //Debug.Log("HoverLock " + interactable);
     hoverLocked          = true;
     hoveringInteractable = interactable;
 }
        //-------------------------------------------------
        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;
            }
        }