private void OnGUI_Buttons()
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(TileLang.ParticularText("Action", "Save"), ExtraEditorStyles.Instance.BigButton, RotorzEditorStyles.ContractWidth))
            {
                if (this.brush != null && this.brushTab != null)
                {
                    this.brush.UserFlagLabels = this.brushTab.FlagLabels;
                    EditorUtility.SetDirty(this.brush);
                }

                ProjectSettings.Instance.FlagLabels = this.projectTab.FlagLabels;

                DesignerWindow.RepaintWindow();
                this.Close();
                GUIUtility.ExitGUI();
            }
            if (GUILayout.Button(TileLang.ParticularText("Action", "Cancel"), ExtraEditorStyles.Instance.BigButton, RotorzEditorStyles.ContractWidth))
            {
                this.Close();
                GUIUtility.ExitGUI();
            }

            GUILayout.EndHorizontal();
        }
Пример #2
0
        /// <summary>
        /// Show tileset in designer window.
        /// </summary>
        /// <param name="tileset">Tileset asset.</param>
        public static void ShowTilesetInDesigner(Tileset tileset)
        {
            // Ensure that designer window is shown.
            DesignerWindow designer = DesignerWindow.ShowWindow();

            // Show tileset in designer.
            designer.SelectedObject = tileset;

            // Focus designer window?
            if (EditorWindow.focusedWindow != designer)
            {
                designer.Focus();
            }
        }
Пример #3
0
        /// <summary>
        /// Show brush in designer window.
        /// </summary>
        /// <param name="brush">Brush asset.</param>
        public static void ShowBrushInDesigner(Brush brush)
        {
            // Ensure that designer window is shown.
            DesignerWindow designer = DesignerWindow.ShowWindow();

            // Show brush in designer.
            designer.SelectedObject = brush;

            // Focus designer window?
            if (EditorWindow.focusedWindow != designer)
            {
                designer.Focus();
            }
        }
Пример #4
0
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            if (!s_EnableScanner)
            {
                return;
            }

            // Check for new brush/tileset assets.
            if (ContainsNewBrushOrTileset(importedAssets))
            {
                BrushDatabase.Instance.Rescan();
                ToolUtility.RepaintBrushPalette();
            }

            // Check for deleted brush/tileset assets.
            BrushDatabase.Instance.ClearMissingRecords();
            ToolUtility.RepaintBrushPalette();
            DesignerWindow.RepaintWindow();
        }
Пример #5
0
        /// <summary>
        /// Cleanup tileset mesh assets that are not referenced by tileset brushes.
        /// </summary>
        /// <remarks>
        /// <para>Meshes will become missing in scenes and assets where tile meshes
        /// were previously used (i.e. where previously used tileset brushes have been
        /// deleted). Previously painted tiles should be refreshed.</para>
        /// </remarks>
        /// <param name="tileset">The tileset.</param>
        public static void CleanupTilesetMeshes(Tileset tileset)
        {
            if (tileset == null)
            {
                throw new ArgumentNullException("tileset");
            }

            // No mesh assets to cleanup!
            if (tileset.tileMeshAsset == null || tileset.tileMeshes == null)
            {
                return;
            }

            var tilesetRecord = BrushDatabase.Instance.FindTilesetRecord(tileset);

            if (tilesetRecord == null)
            {
                throw new Exception("Tileset record was not found for '" + tileset.name + "'");
            }

            int keep = 0, lastIndex = 0;

            for (int i = 0; i < tileset.tileMeshes.Length; ++i)
            {
                Mesh m = tileset.tileMeshes[i];
                if (m == null)
                {
                    continue;
                }

                // Find out if at least one tileset brush uses this mesh.
                foreach (BrushAssetRecord record in tilesetRecord.BrushRecords)
                {
                    TilesetBrush brush = record.Brush as TilesetBrush;

                    // Only consider non-procedural tileset brushes!
                    if (brush != null && brush.tileIndex == i && !brush.IsProcedural)
                    {
                        // Do not delete mesh asset!
                        m = null;
                        ++keep;
                        break;
                    }
                }

                if (m != null)
                {
                    tileset.tileMeshes[i] = null;
                    EditorUtility.SetDirty(tileset);

                    Object.DestroyImmediate(m, true);
                }
                else
                {
                    // Index of last mesh that was kept.
                    lastIndex = i;
                }
            }

            // Were any mesh assets required?
            if (keep == 0)
            {
                // Remove asset altogether.
                AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(tileset.tileMeshAsset));
                tileset.tileMeshAsset = null;
            }
            else
            {
                // Shrink tile mesh map if possible.
                Array.Resize(ref tileset.tileMeshes, lastIndex + 1);

                // Re-import mesh asset.
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tileset.tileMeshAsset));
            }

            DesignerWindow.RepaintWindow();
        }
Пример #6
0
        /// <summary>
        /// Delete tileset and associated assets.
        /// </summary>
        /// <remarks>
        /// <para>Can only delete tileset assets of type <see cref="Tileset"/>
        /// or <see cref="AutotileTileset"/>.</para>
        /// </remarks>
        /// <param name="tileset">The tileset.</param>
        /// <param name="flags">Optional deletion flags.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="tileset"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// If attempting to delete an unsuported type of tileset.
        /// </exception>
        /// <exception cref="System.Exception">
        /// If tileset record was not found for specified tileset.
        /// </exception>
        public static void DeleteTileset(Tileset tileset, DeleteTilesetFlag flags = 0)
        {
            if (tileset == null)
            {
                throw new ArgumentNullException("tileset");
            }

            Type tilesetType = tileset.GetType();

            if (tilesetType != typeof(Tileset) && tilesetType != typeof(AutotileTileset))
            {
                throw new ArgumentException("This utility function cannot delete tileset of type '" + tilesetType.FullName + "'", "tileset");
            }

            var tilesetRecord = BrushDatabase.Instance.FindTilesetRecord(tileset);

            if (tilesetRecord == null)
            {
                throw new Exception("Tileset record was not found for '" + tileset.name + "'");
            }

            var autotileTileset = tileset as AutotileTileset;

            string assetPath           = tilesetRecord.AssetPath;
            string assetFolderPath     = assetPath.Substring(0, assetPath.LastIndexOf("/"));
            string assetFolderPathBase = assetFolderPath + "/";
            int    slashCount          = assetFolderPathBase.CountSubstrings('/');

            // Note: Only delete assets where:
            //  - Asset path begins with base path of tileset asset.
            //  - Asset path includes the same number of slashes (to avoid deleting
            //    those that are nested within folders).

            // Delete associated texture?
            if (autotileTileset != null && (flags & DeleteTilesetFlag.DeleteTexture) == DeleteTilesetFlag.DeleteTexture && autotileTileset.AtlasTexture != null)
            {
                string t = AssetDatabase.GetAssetPath(tileset.AtlasTexture);
                if (t.StartsWith(assetFolderPathBase) && slashCount == t.CountSubstrings('/'))
                {
                    AssetDatabase.DeleteAsset(t);
                }
            }

            // Delete associated material?
            if ((flags & DeleteTilesetFlag.DeleteMaterial) == DeleteTilesetFlag.DeleteMaterial && tileset.AtlasMaterial != null)
            {
                string t = AssetDatabase.GetAssetPath(tileset.AtlasMaterial);
                if (t.StartsWith(assetFolderPathBase) && slashCount == t.CountSubstrings('/'))
                {
                    AssetDatabase.DeleteAsset(t);
                }
            }

            // Delete associated mesh assets?
            if ((flags & DeleteTilesetFlag.DeleteMeshAssets) == DeleteTilesetFlag.DeleteMeshAssets && tileset.tileMeshAsset != null)
            {
                string t = AssetDatabase.GetAssetPath(tileset.tileMeshAsset);
                if (t.StartsWith(assetFolderPathBase) && slashCount == t.CountSubstrings('/'))
                {
                    AssetDatabase.DeleteAsset(t);
                }
            }

            // Delete tileset and contained brush assets.
            AssetDatabase.DeleteAsset(assetPath);

            // Delete tileset folder if it is empty.
            if (IsDirectoryEmpty(Directory.GetCurrentDirectory() + "/" + assetFolderPath))
            {
                AssetDatabase.DeleteAsset(assetFolderPath);
            }

            ToolUtility.RepaintBrushPalette();
            DesignerWindow.RepaintWindow();
        }