Exemplo n.º 1
0
        /// <summary>
        /// Clean up the resources associated with the surface.
        /// </summary>
        /// <param name="surface">The surface whose resources will be cleaned up.</param>
        /// <param name="destroyGameObject"></param>
        /// <param name="destroyMeshes"></param>
        /// <param name="objectToPreserve">If the surface's game object matches this parameter, it will not be destroyed.</param>
        /// <param name="meshToPreserveA">If either of the surface's meshes matches this parameter, it will not be destroyed.</param>
        /// <param name="meshToPreserveB">If either of the surface's meshes matches this parameter, it will not be destroyed.</param>
        protected void CleanUpSurface(
            SurfaceObject surface,
            bool destroyGameObject      = true,
            bool destroyMeshes          = true,
            GameObject objectToPreserve = null,
            Mesh meshToPreserveA        = null,
            Mesh meshToPreserveB        = null
            )
        {
            if (destroyGameObject &&
                (surface.Object != null) &&
                (surface.Object != objectToPreserve)
                )
            {
                Destroy(surface.Object);
                Debug.Assert(surface.GetType().IsValueType(), "If surface is no longer a value type, you should probably set surface.Object to null.");
            }

            Mesh filterMesh   = surface.Filter.sharedMesh;
            Mesh colliderMesh = surface.Collider.sharedMesh;

            if (destroyMeshes &&
                (filterMesh != null) &&
                (filterMesh != meshToPreserveA) &&
                (filterMesh != meshToPreserveB)
                )
            {
                Destroy(filterMesh);
                surface.Filter.sharedMesh = null;
            }

            if (destroyMeshes &&
                (colliderMesh != null) &&
                (colliderMesh != filterMesh) &&
                (colliderMesh != meshToPreserveA) &&
                (colliderMesh != meshToPreserveB)
                )
            {
                Destroy(colliderMesh);
                surface.Collider.sharedMesh = null;
            }
        }