Esempio n. 1
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(Interactable interactable)
 {
     HandDebugLog("HoverLock " + interactable);
     hoverLocked          = true;
     hoveringInteractable = interactable;
 }
Esempio n. 2
0
        //-------------------------------------------------
        private void UpdateHovering()
        {
            if ((noSteamVRFallbackCamera == null) && (controller == null))
            {
                return;
            }

            if (hoverLocked)
            {
                return;
            }

            if (applicationLostFocusObject.activeSelf)
            {
                return;
            }

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

            // Pick the closest hovering
            float flHoverRadiusScale   = playerInstance.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 - playerInstance.trackingOriginTransform.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;
            }

            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;
                }

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

                // 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 (iActualColliderCount > 0 && iActualColliderCount != prevOverlappingColliders)
            {
                prevOverlappingColliders = iActualColliderCount;
                HandDebugLog("Found " + iActualColliderCount + " overlapping colliders.");
            }
        }