Ejemplo n.º 1
0
        // Note: When Unity colliders are used, this will actually perform an 'OverlapSphere' check
        public List <GameObject> OverlapBox(Box box, ObjectOverlapPrecision overlapPrecision = ObjectOverlapPrecision.ObjectBox)
        {
            if (!RuntimeEditorApplication.Instance.UseUnityColliders)
            {
                return(_gameObjectSphereTree.OverlapBox(box, overlapPrecision));
            }
            else
            {
                var        overlappedObjects   = new List <GameObject>();
                Collider[] overlappedColliders = Physics.OverlapSphere(box.Center, box.Extents.magnitude);
                foreach (var collider in overlappedColliders)
                {
                    overlappedObjects.Add(collider.gameObject);
                }

                return(overlappedObjects);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a list of all objects which are overlapped by the specified sphere.
        /// </summary>
        /// <param name="sphere">
        /// The sphere involved in the overlap query.
        /// </param>
        /// <param name="objectOverlapPrecision">
        /// The desired overlap precision. For the moment this is not used.
        /// </param>
        public List <GameObject> OverlapSphere(Sphere3D sphere, ObjectOverlapPrecision objectOverlapPrecision = ObjectOverlapPrecision.ObjectBox)
        {
            // Retrieve all the sphere tree nodes which are overlapped by the sphere. If no nodes are overlapped,
            // we can return an empty list because it means that no objects could possibly be overlapped either.
            List <SphereTreeNode <GameObject> > allOverlappedNodes = _sphereTree.OverlapSphere(sphere);

            if (allOverlappedNodes.Count == 0)
            {
                return(new List <GameObject>());
            }

            // Loop through all overlapped nodes
            var overlappedObjects = new List <GameObject>();

            foreach (SphereTreeNode <GameObject> node in allOverlappedNodes)
            {
                // Store the node's object for easy access
                GameObject gameObject = node.Data;

                // Note: It is important to check for null because the object may have been destroyed. 'RemoveNullObjectNodes'
                //       removes null objects but given the order in which Unity calls certain key functions such as 'OnSceneGUI'
                //       and any editor registered callbacks, null object references can still pop up.
                if (gameObject == null)
                {
                    continue;
                }
                if (!gameObject.activeSelf)
                {
                    continue;
                }

                // We need to perform an additional check. Even though the sphere overlaps the object's node (which is
                // another sphere), we must also check if the sphere overlaps the object's world oriented box. This allows
                // for better precision.
                OrientedBox objectWorldOrientedBox = gameObject.GetWorldOrientedBox();
                if (sphere.OverlapsFullyOrPartially(objectWorldOrientedBox))
                {
                    overlappedObjects.Add(gameObject);
                }
            }

            return(overlappedObjects);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a list of all objects which are overlapped by the specified box.
        /// </summary>
        /// <param name="box">
        /// The box involved in the overlap query.
        /// </param>
        /// <param name="objectOverlapPrecision">
        /// The desired overlap precision. For the moment this is not used.
        /// </param>
        public List <GameObject> OverlapBox(Box box, ObjectOverlapPrecision objectOverlapPrecision = ObjectOverlapPrecision.ObjectBox)
        {
            // Retrieve all the sphere tree nodes which are overlapped by the box. If no nodes are overlapped,
            // we can return an empty list because it means that no objects could possibly be overlapped either.
            List <SphereTreeNode <GameObject> > allOverlappedNodes = _sphereTree.OverlapBox(box);

            if (allOverlappedNodes.Count == 0)
            {
                return(new List <GameObject>());
            }

            // Loop through all overlapped nodes
            OrientedBox orientedBox       = box.ToOrientedBox();
            var         overlappedObjects = new List <GameObject>();

            foreach (SphereTreeNode <GameObject> node in allOverlappedNodes)
            {
                // Store the node's object for easy access
                GameObject gameObject = node.Data;
                if (gameObject == null)
                {
                    continue;
                }
                if (!gameObject.activeSelf)
                {
                    continue;
                }

                // We need to perform an additional check. Even though the box overlaps the object's node (which is
                // a sphere), we must also check if the box overlaps the object's world oriented box. This allows
                // for better precision.
                OrientedBox objectWorldOrientedBox = gameObject.GetWorldOrientedBox();
                if (orientedBox.Intersects(objectWorldOrientedBox))
                {
                    overlappedObjects.Add(gameObject);
                }
            }

            return(overlappedObjects);
        }
Ejemplo n.º 4
0
 public List <GameObject> OverlapBox(Box box, ObjectOverlapPrecision overlapPrecision = ObjectOverlapPrecision.ObjectBox)
 {
     return(_gameObjectSphereTree.OverlapBox(box, overlapPrecision));
 }
Ejemplo n.º 5
0
 public List <GameObject> OverlapSphere(Sphere3D sphere, ObjectOverlapPrecision overlapPrecision = ObjectOverlapPrecision.ObjectBox)
 {
     return(_gameObjectSphereTree.OverlapSphere(sphere, overlapPrecision));
 }