private void DrawAtlasDetailsGUI() { bool invalidateMetrics = false; this.clearPreviews = false; GUILayout.BeginHorizontal(); { EditorGUI.BeginChangeCheck(); { this.DrawAtlasTextureField(); GUILayout.Space(15f); this.DrawAtlasParametersGUI(); GUILayout.Space(20f); this.DrawEdgeCorrectionGUI(); GUILayout.FlexibleSpace(); } invalidateMetrics = EditorGUI.EndChangeCheck(); } GUILayout.EndHorizontal(); // Metrics must be recalculated if any changes have been made. if (this.clearPreviews || invalidateMetrics) { AutotileExpanderUtility.ApplyTileSizeConstraints(s_SelectedAutotileLayout, this.autotileTextureUncompressed, s_InnerJoins, ref this.tileWidth, ref this.tileHeight, ref s_BorderSize); this.RecalculateMetrics(); // Previews only need to be refreshed when tile size or atlas is changed. if (this.clearPreviews) { this.ClearExpandedAutotileArtwork(); } } }
private void RecalculateTileSize() { if (this.autotileTextureUncompressed == null) { return; } AutotileExpanderUtility.EstimateTileSize(s_SelectedAutotileLayout, this.autotileTextureUncompressed, s_InnerJoins, ref this.tileWidth, ref this.tileHeight); this.ExpandAutotileArtwork(); }
/// <summary> /// Apply constraints to tile width, height and border inputs. /// </summary> private void ApplyAutotileConstraintsToInputs() { AutotileExpanderUtility.ApplyTileSizeConstraints( layout: this.autotileTileset.AutotileLayout, artwork: this.inputNewAutotileArtworkUncompressed, innerJoins: this.autotileTileset.HasInnerJoins, tileWidth: ref this.inputTileWidth, tileHeight: ref this.inputTileHeight, border: ref this.inputBorderSize ); }
private void DrawAtlasTextureField() { EditorGUI.BeginChangeCheck(); this.inputNewAutotileArtwork = RotorzEditorGUI.AutotileArtworkField(this.inputNewAutotileArtwork, this.autotileTileset.AutotileLayout, this.autotileTileset.HasInnerJoins); if (EditorGUI.EndChangeCheck()) { this.LoadUncompressedAutotileArtwork(this.inputNewAutotileArtwork); // Recalculate tile size and expand autotile artwork. if (this.inputNewAutotileArtworkUncompressed != null) { AutotileExpanderUtility.EstimateTileSize(this.autotileTileset.AutotileLayout, this.inputNewAutotileArtworkUncompressed, this.autotileTileset.HasInnerJoins, ref this.inputTileWidth, ref this.inputTileHeight); this.ExpandAutotileArtwork(); } } }
/// <summary> /// Refreshes atlas details if necessary. /// </summary> /// <remarks> /// <para>These details are shown on the user interface to provide the user with an /// indication of atlas usage.</para> /// </remarks> private void RefreshAtlasDetails() { if (!this.invalidateAtlasDetails) { return; } this.invalidateAtlasDetails = false; // No details to show when no autotile artwork is specified if (this.inputNewAutotileArtwork /*Uncompressed*/ == null) { this.atlasDetails = null; return; } var autotileExpanderUtility = new AutotileExpanderUtility( layout: this.autotileTileset.AutotileLayout, autotileArtwork: this.inputNewAutotileArtworkUncompressed, tileWidth: this.inputTileWidth, tileHeight: this.inputTileHeight, innerJoins: this.autotileTileset.HasInnerJoins, border: this.inputBorderSize, clampEdges: false ); int atlasWidth; int atlasHeight; int atlasUnused; autotileExpanderUtility.CalculateMetrics(out atlasWidth, out atlasHeight, out atlasUnused); int atlasUnusedPercentage = 100 * atlasUnused / (atlasWidth * atlasHeight); this.atlasDetails = string.Format( /* 0: width of atlas texture in pixels * 1: height of atlas texture in pixels * 2: percentage of unused area of atlas texture */ TileLang.Text("Output Atlas: {0}x{1} Unused: {2}%"), atlasWidth, atlasHeight, atlasUnusedPercentage ); }
/// <summary> /// Expand autotile atlas. /// </summary> /// <param name="borderSize">Border size in pixels.</param> private void ExpandAutotileArtwork(int borderSize = 0) { this.ClearExpandedAutotileAtlas(); this.ApplyAutotileConstraintsToInputs(); if (this.inputNewAutotileArtworkUncompressed != null) { this.expandedAutotileAtlas = AutotileExpanderUtility.ExpandAutotileArtwork(this.autotileTileset.AutotileLayout, this.inputNewAutotileArtworkUncompressed, this.inputTileWidth, this.inputTileHeight, this.autotileTileset.HasInnerJoins, borderSize, this.inputClampEdges); } int atlasWidth = 0; int atlasHeight = 0; if (this.expandedAutotileAtlas != null) { atlasWidth = this.expandedAutotileAtlas.width; atlasHeight = this.expandedAutotileAtlas.height; } this.inputTilesetMetrics.Calculate(atlasWidth, atlasHeight, this.inputTileWidth, this.inputTileHeight, borderSize, this.inputDelta); }
private void ExpandAutotileArtwork(int borderSize = 0) { this.ClearExpandedAutotileArtwork(); AutotileExpanderUtility.ApplyTileSizeConstraints(s_SelectedAutotileLayout, this.autotileTextureUncompressed, s_InnerJoins, ref this.tileWidth, ref this.tileHeight, ref s_BorderSize); if (this.autotileTextureUncompressed != null) { this.atlasTexture = AutotileExpanderUtility.ExpandAutotileArtwork(s_SelectedAutotileLayout, this.autotileTextureUncompressed, this.tileWidth, this.tileHeight, s_InnerJoins, borderSize, s_EnableClampEdges); this.atlasTexture.hideFlags = HideFlags.HideAndDontSave; } int atlasWidth = 0, atlasHeight = 0; if (this.atlasTexture != null) { atlasWidth = this.atlasTexture.width; atlasHeight = this.atlasTexture.height; } this.metrics.Calculate(atlasWidth, atlasHeight, this.tileWidth, this.tileHeight, borderSize, s_Delta); }
private void RecalculateMetrics() { if (this.autotileTextureUncompressed != null) { var autotileExpanderUtility = new AutotileExpanderUtility(s_SelectedAutotileLayout, this.autotileTextureUncompressed, this.tileWidth, this.tileHeight, s_InnerJoins, s_BorderSize, false); autotileExpanderUtility.CalculateMetrics(out this.metricAtlasWidth, out this.metricAtlasHeight, out this.metricAtlasUnused); this.metricAtlasUnusedPercentage = 100 * this.metricAtlasUnused / (this.metricAtlasWidth * this.metricAtlasHeight); this.metricSummary.text = string.Format( /* 0: width of atlas texture in pixels * 1: height of atlas texture in pixels * 2: percentage of unused area of atlas texture */ TileLang.Text("Output Atlas: {0}x{1} Unused: {2}%"), this.metricAtlasWidth, this.metricAtlasHeight, this.metricAtlasUnusedPercentage ); } else { this.metricAtlasUnusedPercentage = this.metricAtlasUnused = this.metricAtlasHeight = this.metricAtlasWidth = 0; this.metricSummary.text = string.Empty; } }