Пример #1
0
    private void UpdateOverlappedColliders()
    {
        _overlappedColliders.Clear();
        foreach (var pair in _childCollidersToTypeDict)
        {
            Collider            childCollider  = pair.Key;
            OverlapColliderType colliderType   = pair.Value;
            Collider[]          otherColliders = new Collider[0];
            switch (colliderType)
            {
            case OverlapColliderType.BoxCollider:
                otherColliders = ColliderUtility.CheckOverlapBox((BoxCollider)childCollider);
                break;

            case OverlapColliderType.SphereCollider:
                otherColliders = ColliderUtility.CheckOverlapSphere((SphereCollider)childCollider);
                break;

            default:
                break;
            }
            int n = otherColliders.Length;
            for (int i = 0; i < n; i++)
            {
                Collider otherCollider = otherColliders[i];
                _overlappedColliders.Add(otherCollider);
            }
        }
    }
        /// <summary>
        /// Return a set of overlapping colliders with colliders attached to this
        /// game object.
        /// </summary>
        /// <returns>A set of overlapping colliders.</returns>
        public HashSet <Collider> CheckOverlapColliders()
        {
            _overlappedColliderSet.Clear();
            // Check OverlapBox for all box colliders
            int n = _selfBoxColliders.Count;

            for (int i = 0; i < n; i++)
            {
                BoxCollider boxCollider         = _selfBoxColliders[i];
                Collider[]  overlappedColliders = ColliderUtility.CheckOverlapBox(
                    boxCollider);
                int overlappedColliderLength = overlappedColliders.Length;
                for (int j = 0; j < overlappedColliderLength; j++)
                {
                    Collider overlappedCollider = overlappedColliders[j];
                    _overlappedColliderSet.Add(overlappedCollider);
                }
            }
            // Check OverlapSphere for all sphere colliders
            n = _selfSphereColliders.Count;
            for (int i = 0; i < n; i++)
            {
                SphereCollider sphereCollider      = _selfSphereColliders[i];
                Collider[]     overlappedColliders =
                    ColliderUtility.CheckOverlapSphere(sphereCollider);
                int overlappedColliderLength = overlappedColliders.Length;
                for (int j = 0; j < overlappedColliderLength; j++)
                {
                    Collider overlappedCollider = overlappedColliders[j];
                    _overlappedColliderSet.Add(overlappedCollider);
                }
            }
            return(_overlappedColliderSet);
        }