public static Sphere FromCollider(Collider c, BoundingSphereAlgorithm algorithm, bool local = false)
 {
     if (c is SphereCollider)
     {
         return(FromCollider(c as SphereCollider, local));
     }
     else if (c is CapsuleCollider)
     {
         return(FromCollider(c as CapsuleCollider, local));
     }
     else if (algorithm != BoundingSphereAlgorithm.FromBounds && c is MeshCollider)
     {
         return(FromMesh((c as MeshCollider).sharedMesh, algorithm, Trans.GetGlobal(c.transform)));
     }
     else
     {
         var bounds = AABBox.FromCollider(c, local);
         return(new Sphere(bounds.Center, bounds.Extents.magnitude));
     }
 }
Example #2
0
        /// <summary>
        /// Attempts to calculate geometry for a collider. Not tested yet.
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static IPhysicsGeom GetGeom(this Collider c, BoundingSphereAlgorithm algorithm, bool local = false)
        {
            if (c == null)
            {
                return(null);
            }

            if (c is CharacterController)
            {
                return(Capsule.FromCollider(c as CharacterController, local));
            }
            if (c is CapsuleCollider)
            {
                return(Capsule.FromCollider(c as CapsuleCollider, local));
            }
            else if (c is BoxCollider)
            {
                return(Box.FromCollider(c as BoxCollider, local));
            }
            else if (c is SphereCollider)
            {
                return(Sphere.FromCollider(c as SphereCollider, local));
            }
            else if (algorithm != BoundingSphereAlgorithm.FromBounds && c is MeshCollider)
            {
                if (local)
                {
                    return(Sphere.FromMesh((c as MeshCollider).sharedMesh, algorithm));
                }
                else
                {
                    return(Sphere.FromMesh((c as MeshCollider).sharedMesh, algorithm, Trans.GetGlobal(c.transform)));
                }
            }
            else
            {
                //otherwise just return bounds as AABBox
                return(AABBox.FromCollider(c, local));
            }
        }