Exemplo n.º 1
0
        /// <summary>
        /// Create a spherical bounds inside of a Renderer bounds.
        /// It'll take every meshes found in the hierarchy into account.
        /// </summary>
        /// <param name="go">GameObject having Renderer component(s).</param>
        /// <param name="bounds">Sphere bounds instance in which sphere information will be store.</param>
        /// <returns>True if bounds data has been set.</returns>
        internal static bool GetSphereBounds(GameObject go, out SphereBounds bounds)
        {
            Bounds entireObjectBounds = GetHierarchyBounds(go);

            bounds = default(SphereBounds);

            if (entireObjectBounds.size == Vector3.zero)
            {
                return(false);
            }

            bounds.position = entireObjectBounds.center;
            bounds.radius   = Mathf.Max(entireObjectBounds.extents.x, entireObjectBounds.extents.z);

            return(true);
        }
Exemplo n.º 2
0
        private static bool GetSphereBounds(GameObject go, out SphereBounds bounds)
        {
            bounds = new SphereBounds();

            if (go == null)
            {
                return(false);
            }

            Mesh mesh = null;

            MeshFilter mf = go.GetComponentInChildren <MeshFilter>();

            if (mf != null && mf.sharedMesh != null)
            {
                mesh = mf.sharedMesh;
            }
            else
            {
                SkinnedMeshRenderer smr = go.GetComponentInChildren <SkinnedMeshRenderer>();

                if (smr != null && smr.sharedMesh != null)
                {
                    mesh = smr.sharedMesh;
                }
            }

            if (mesh != null)
            {
                Bounds meshBounds = mf.sharedMesh.bounds;
                bounds.position = mf.transform.TransformPoint(meshBounds.center - (Vector3.up * meshBounds.extents.y));
                bounds.radius   = Mathf.Max(meshBounds.extents.x, meshBounds.extents.z);

                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
 public bool Intersects(SphereBounds other)
 {
     return(Vector3.Distance(position, other.position) < (radius + other.radius));
 }