private void DestroyGeneratedProceduralMeshes(TileSystem system)
        {
            foreach (var proceduralMesh in system.GetComponentsInChildren <ProceduralMesh>())
            {
                var transform = proceduralMesh.transform;

                Object.DestroyImmediate(transform.GetComponent <MeshFilter>());
                Object.DestroyImmediate(transform.GetComponent <MeshRenderer>());

                Object.DestroyImmediate(proceduralMesh.mesh);

                Object.DestroyImmediate(proceduralMesh);

                StrippingUtility.StripEmptyGameObject(transform);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Strip plop instance and group components for tile system.
        /// </summary>
        /// <param name="system">Tile system.</param>
        private static void StripPlopComponents(TileSystem system)
        {
            // Strip `PlopGroup` components from tile system.
            foreach (var plopGroup in system.GetComponentsInChildren <PlopGroup>())
            {
                InternalUtility.Destroy(plopGroup);
            }

            // Strip `PlopInstance` components which are associated from tile system.
            foreach (var plopInstance in Resources.FindObjectsOfTypeAll <PlopInstance>())
            {
                if (plopInstance.Owner == system)
                {
                    InternalUtility.Destroy(plopInstance);
                }
            }
        }
        /// <summary>
        /// Display user interface to clear all plops associated with a tile system.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="system"/> is <c>null</c>.
        /// </exception>
        internal static void Command_ClearPlops(TileSystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            if (!EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Action", "Clear Plops"),
                    string.Format(
                        /* 0: name of tile system */
                        TileLang.Text("Do you want to clear all plops associated with '{0}'?"),
                        system.name
                        ),
                    TileLang.ParticularText("Action", "Yes"),
                    TileLang.ParticularText("Action", "No")
                    ))
            {
                return;
            }

            // Clear all plops which are associated with tile system.
            foreach (var plop in UnityEngine.Resources.FindObjectsOfTypeAll <PlopInstance>())
            {
                if (plop.Owner == system)
                {
                    Undo.DestroyObjectImmediate(plop.gameObject);
                }
            }

            // Clear plop groups from tile system.
            foreach (var plopGroup in system.GetComponentsInChildren <PlopGroup>())
            {
                var plopGroupTransform = plopGroup.transform;
                if (plopGroupTransform.childCount == 0 && plopGroupTransform.GetComponents <Component>().Length == 2)
                {
                    Undo.DestroyObjectImmediate(plopGroup.gameObject);
                }
            }
        }