Example #1
0
        // Token: 0x06002076 RID: 8310 RVA: 0x000A03E8 File Offset: 0x0009E5E8
        private void UpdateHovering()
        {
            if (this.noSteamVRFallbackCamera == null && this.controller == null)
            {
                return;
            }
            if (this.hoverLocked)
            {
                return;
            }
            if (this.applicationLostFocusObject.activeSelf)
            {
                return;
            }
            float        num = float.MaxValue;
            Interactable hoveringInteractable = null;
            float        x    = this.playerInstance.transform.lossyScale.x;
            float        num2 = this.hoverSphereRadius * x;
            float        num3 = Util.RemapNumberClamped(Mathf.Abs(base.transform.position.y - this.playerInstance.trackingOriginTransform.position.y), 0f, 0.5f * x, 5f, 1f) * x;

            for (int i = 0; i < this.overlappingColliders.Length; i++)
            {
                this.overlappingColliders[i] = null;
            }
            Physics.OverlapBoxNonAlloc(this.hoverSphereTransform.position - new Vector3(0f, num2 * num3 - num2, 0f), new Vector3(num2, num2 * num3 * 2f, num2), this.overlappingColliders, Quaternion.identity, this.hoverLayerMask.value);
            int num4 = 0;

            Collider[] array = this.overlappingColliders;
            for (int j = 0; j < array.Length; j++)
            {
                Collider collider = array[j];
                if (!(collider == null))
                {
                    Interactable contacting = collider.GetComponentInParent <Interactable>();
                    if (!(contacting == null))
                    {
                        IgnoreHovering component = collider.GetComponent <IgnoreHovering>();
                        if ((!(component != null) || (!(component.onlyIgnoreHand == null) && !(component.onlyIgnoreHand == this))) && this.attachedObjects.FindIndex((Hand.AttachedObject l) => l.attachedObject == contacting.gameObject) == -1 && (!this.otherHand || !(this.otherHand.hoveringInteractable == contacting)))
                        {
                            float num5 = Vector3.Distance(contacting.transform.position, this.hoverSphereTransform.position);
                            if (num5 < num)
                            {
                                num = num5;
                                hoveringInteractable = contacting;
                            }
                            num4++;
                        }
                    }
                }
            }
            this.hoveringInteractable = hoveringInteractable;
            if (num4 > 0 && num4 != this.prevOverlappingColliders)
            {
                this.prevOverlappingColliders = num4;
                this.HandDebugLog("Found " + num4 + " overlapping colliders.");
            }
        }
Example #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.");
            }
        }
Example #3
0
        protected virtual bool CheckHoveringForTransform(Vector3 hoverPosition, float hoverRadius, ref float closestDistance, ref Interactable closestInteractable, Color debugColor)
        {
            bool foundCloser = false;

            // null out old vals
            for (int i = 0; i < overlappingColliders.Length; ++i)
            {
                overlappingColliders[i] = null;
            }

            int numColliding = Physics.OverlapSphereNonAlloc(hoverPosition, hoverRadius, overlappingColliders, hoverLayerMask.value);

            if (numColliding == ColliderArraySize)
            {
                Debug.LogWarning("This hand is overlapping the max number of colliders: " + ColliderArraySize + ". Some collisions may be missed. Increase ColliderArraySize on Hand.cs");
            }

            // DebugVar
            int iActualColliderCount = 0;

            // Pick the closest hovering
            for (int colliderIndex = 0; colliderIndex < overlappingColliders.Length; colliderIndex++)
            {
                Collider collider = overlappingColliders[colliderIndex];

                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
                bool hoveringOverAttached = false;
                for (int attachedIndex = 0; attachedIndex < attachedObjects.Count; attachedIndex++)
                {
                    if (attachedObjects[attachedIndex].attachedObject == contacting.gameObject)
                    {
                        hoveringOverAttached = true;
                        break;
                    }
                }
                if (hoveringOverAttached)
                {
                    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, hoverPosition);
                if (distance < closestDistance)
                {
                    closestDistance     = distance;
                    closestInteractable = contacting;
                    foundCloser         = true;
                }
                iActualColliderCount++;
            }

            if (showDebugInteractables && foundCloser)
            {
                Debug.DrawLine(hoverPosition, closestInteractable.transform.position, debugColor, .05f, false);
            }

            if (iActualColliderCount > 0 && iActualColliderCount != prevOverlappingColliders)
            {
                prevOverlappingColliders = iActualColliderCount;

                HandDebugLog("Found " + iActualColliderCount + " overlapping colliders.");
            }

            return(foundCloser);
        }