Example #1
0
        private void CreateAutotileTileset(string tilesetName)
        {
            // Ensure that autotile artwork is re-expanded before proceeding to avoid
            // ignoring changes that have been made to user input.
            this.ExpandAutotileArtwork(s_BorderSize);

            // Create folder for autotile brush assets.
            string tilesetDirectoryName = tilesetName + " Autotile";
            string tilesetDirectoryPath = AssetDatabase.GenerateUniqueAssetPath(BrushUtility.GetBrushAssetPath() + tilesetDirectoryName);

            Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/" + tilesetDirectoryPath);

            // Create material for tileset.
            var atlasTexture  = EditorInternalUtility.SavePngAsset(tilesetDirectoryPath + "/atlas.png", this.atlasTexture);
            var atlasMaterial = BrushUtility.CreateTilesetMaterial(atlasTexture, this.enableAlphaBlending);

            AssetDatabase.CreateAsset(atlasMaterial, tilesetDirectoryPath + "/atlas.mat");
            AssetDatabase.ImportAsset(tilesetDirectoryPath + "/atlas.mat");

            // Calculate metrics for tileset.
            var tilesetMetrics = new TilesetMetrics(atlasTexture, this.tileWidth, this.tileHeight, s_BorderSize, s_Delta);

            // Create tileset.
            var autotileTileset = ScriptableObject.CreateInstance <AutotileTileset>();

            autotileTileset.Initialize(s_SelectedAutotileLayout, s_InnerJoins, atlasMaterial, atlasTexture, tilesetMetrics);
            autotileTileset.rawTexture      = this.autotileTexture;
            autotileTileset.procedural      = true;
            autotileTileset.ForceClampEdges = s_EnableClampEdges;

            Object.DestroyImmediate(this.atlasTexture);
            this.atlasTexture = null;

            // Save tileset and its material to asset file.
            string assetPath = tilesetDirectoryPath + "/" + tilesetName + ".asset";

            AssetDatabase.CreateAsset(autotileTileset, assetPath);

            AssetDatabase.ImportAsset(assetPath);

            // Ensure that changes are persisted immediately.
            AssetDatabase.SaveAssets();

            // Make sure that "Create Brushes" tab is shown.
            TilesetDesigner.s_SelectedTab = 0;
            ToolUtility.ShowTilesetInDesigner(autotileTileset);

            ToolUtility.RepaintBrushPalette();
        }
Example #2
0
        private void CreateTileset(string tilesetName)
        {
            // Create folder for atlas assets.
            string atlasFolder = AssetDatabase.GenerateUniqueAssetPath(BrushUtility.GetBrushAssetPath() + tilesetName);

            Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/" + atlasFolder);

            // Create material for tileset.
            var atlasMaterial = BrushUtility.CreateTilesetMaterial(this.tilesetTexture, this.alpha);

            AssetDatabase.CreateAsset(atlasMaterial, atlasFolder + "/atlas.mat");
            AssetDatabase.ImportAsset(atlasFolder + "/atlas.mat");

            // Use edge correction preset?
            if (this.edgeCorrectionPreset != EdgeCorrectionPreset.Custom)
            {
                this.borderSize = 0;
                this.delta      = (this.edgeCorrectionPreset == EdgeCorrectionPreset.InsetUVs) ? 0.5f : 0f;
            }

            // Calculate metrics for tileset.
            this.RecalculateMetrics();

            // Create tileset.
            var tileset = ScriptableObject.CreateInstance <Tileset>();

            tileset.Initialize(atlasMaterial, this.tilesetTexture, this.tilesetMetrics);
            tileset.procedural = this.procedural;

            // Save tileset and its material to asset file.
            string assetPath = atlasFolder + "/" + tilesetName + ".asset";

            AssetDatabase.CreateAsset(tileset, assetPath);
            AssetDatabase.ImportAsset(assetPath);

            // Ensure that changes are persisted immediately.
            AssetDatabase.SaveAssets();

            // Make sure that "Create Brushes" tab is shown.
            TilesetDesigner.s_SelectedTab = 0;
            ToolUtility.ShowTilesetInDesigner(tileset);

            ToolUtility.RepaintBrushPalette();
        }