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(); }
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(); }
private static bool OnOpenAsset(int instanceID, int line) { var asset = EditorUtility.InstanceIDToObject(instanceID); var brush = asset as Brush; if (brush != null) { ToolUtility.ShowBrushInDesigner(brush); return(true); } var tileset = asset as Tileset; if (tileset != null) { ToolUtility.ShowTilesetInDesigner(tileset); return(true); } return(false); }
protected override void OnHeaderGUI() { if (!this.hasInitialized) { this.hasInitialized = true; // Find out whether brush asset is accessible via brush database. var record = BrushDatabase.Instance.FindRecord(target as Brush); this.hasRecord = (record != null); } if (this.hasRecord) { var brush = target as Brush; GUILayout.BeginHorizontal(RotorzEditorStyles.Instance.InspectorBigTitle); Rect previewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(64), GUILayout.Height(65)); if (Event.current.type == EventType.Repaint) { RotorzEditorStyles.Instance.Box.Draw(new Rect(previewPosition.x - 2, previewPosition.y - 2, 68, 68), GUIContent.none, false, false, false, false); previewPosition = new Rect(previewPosition.x, previewPosition.y, 64, 64); RotorzEditorGUI.DrawBrushPreview(previewPosition, brush); } GUILayout.BeginVertical(); { GUILayout.Label(brush.name, EditorStyles.largeLabel); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); var tilesetBrush = brush as TilesetBrush; if (tilesetBrush != null) { EditorGUI.BeginDisabledGroup(tilesetBrush.Tileset == null); if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Goto Tileset")), EditorStyles.miniButton)) { ToolUtility.ShowTilesetInDesigner(tilesetBrush.Tileset); GUIUtility.ExitGUI(); } EditorGUI.EndDisabledGroup(); } if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Show in Designer")), EditorStyles.miniButton)) { ToolUtility.ShowBrushInDesigner(brush); GUIUtility.ExitGUI(); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } else { // Nope, assume default header! base.OnHeaderGUI(); } }
protected override void OnHeaderGUI() { if (!this.hasInitialized) { this.hasInitialized = true; // Find out whether brush asset is accessible via brush database. var record = BrushDatabase.Instance.FindTilesetRecord(target as Tileset); this.hasRecord = (record != null); } if (this.hasRecord) { var tileset = target as Tileset; GUILayout.BeginHorizontal(RotorzEditorStyles.Instance.InspectorBigTitle); Rect previewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(64), GUILayout.Height(65)); if (Event.current.type == EventType.Repaint && ExtraEditorGUI.VisibleRect.Overlaps(previewPosition)) { RotorzEditorStyles.Instance.Box.Draw(new Rect(previewPosition.x - 2, previewPosition.y - 2, 68, 68), GUIContent.none, false, false, false, false); previewPosition = new Rect(previewPosition.x, previewPosition.y, 64, 64); var previewAsset = tileset.AtlasTexture ?? target; var tilesetPreviewTexture = AssetPreviewCache.GetAssetPreview(previewAsset); if (!tilesetPreviewTexture) { if (AssetPreview.IsLoadingAssetPreview(previewAsset.GetInstanceID())) { this.Repaint(); } tilesetPreviewTexture = AssetPreview.GetMiniThumbnail(previewAsset); } GUI.DrawTexture(previewPosition, tilesetPreviewTexture); } GUILayout.BeginVertical(); { GUILayout.Label(tileset.name, EditorStyles.largeLabel); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Show in Designer")), EditorStyles.miniButton)) { ToolUtility.ShowTilesetInDesigner(tileset); GUIUtility.ExitGUI(); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } else { // Nope, assume default header! base.OnHeaderGUI(); } }