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(); }
/// <summary> /// Duplicate a brush that is described by this descriptor. /// </summary> /// <param name="name">Name for new brush.</param> /// <param name="record">Record for brush that is to be duplicated.</param> public virtual Brush DuplicateBrush(string name, BrushAssetRecord record) { // Duplicate entire asset because brush IS the main asset. if (record.MainAsset == record.Brush) { string newAssetPath = AssetDatabase.GenerateUniqueAssetPath(BrushUtility.GetBrushAssetPath() + name + ".asset"); if (!AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(record.MainAsset), newAssetPath)) { return(null); } // Load the new asset. AssetDatabase.ImportAsset(newAssetPath); return(AssetDatabase.LoadMainAssetAtPath(newAssetPath) as Brush); } return(null); }
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(); }
/// <summary> /// Checks that specified asset name is both valid and unique. /// </summary> /// <remarks> /// <para>Error message dialog is shown if asset name is not valid or unique.</para> /// </remarks> /// <param name="name">Name of asset.</param> /// <returns> /// A value of <c>true</c> when specified asset name is valid; otherwise <c>false</c>. /// </returns> protected bool ValidateUniqueAssetName(string name) { if (!this.ValidateAssetName(name)) { return(false); } // Ensure that asset path does not already exist. string assetPath = BrushUtility.GetBrushAssetPath() + name + ".asset"; if (File.Exists(assetPath)) { EditorUtility.DisplayDialog( TileLang.Text("Asset already exists"), TileLang.Text("Please specify unique name for asset."), TileLang.ParticularText("Action", "OK") ); return(false); } return(true); }