Exemplo n.º 1
0
 /// <summary>
 /// Raised to draw options GUI for custom tools.
 /// </summary>
 /// <remarks>
 /// <para>This method will be invoked multiple times when handling different
 /// GUI events. Please refer to the Unity documentation for further information
 /// regarding custom GUIs: <a href="http://docs.unity3d.com/Documentation/Components/gui-ExtendingEditor.html">Extending the Editor</a>.</para>
 /// <para>Horizontal and vertical scroll bars will be shown automatically if your
 /// custom tool options interface exceeds window size.</para>
 /// </remarks>
 /// <example>
 /// <para>The following source code demonstrates how to define a user interface
 /// with two buttons.</para>
 /// <para><img src="../art/custom_OnToolOptionsGUI.png" alt="Example of custom tool options GUI"/></para>
 /// <code language="csharp"><![CDATA[
 /// public override void OnToolOptionsGUI()
 /// {
 ///     GUILayout.BeginHorizontal();
 ///     {
 ///         GUILayout.Label("Special Action: ");
 ///
 ///         if (GUILayout.Button("A")) {
 ///             // Do something!
 ///         }
 ///
 ///         if (GUILayout.Button("B")) {
 ///             // Do something!
 ///         }
 ///     }
 ///     GUILayout.EndHorizontal();
 /// }
 /// ]]></code>
 /// </example>
 public virtual void OnToolOptionsGUI()
 {
     if (!this.HasAdvancedToolOptionsGUI)
     {
         GUILayout.Label(TileLang.Text("Tool has no parameters"), EditorStyles.miniLabel);
     }
 }
        /// <inheritdoc/>
        protected override void DoGUI()
        {
            GUILayout.Space(10);

            GUILayout.BeginHorizontal();

            GUILayout.Space(69);
            GUI.DrawTexture(new Rect(10, 10, 59, 52), RotorzEditorStyles.Skin.Caution);

            GUILayout.BeginVertical(this.paddedAreaStyle);
            {
                GUILayout.BeginVertical();
                {
                    RotorzEditorGUI.Title(TileLang.ParticularText("Action", "Cleanup Non-Procedural Meshes"));
                    GUILayout.Space(5);
                    GUILayout.Label(this.headingText, RotorzEditorStyles.Instance.BoldLabel);
                    GUILayout.Space(7);
                    GUILayout.Label(TileLang.Text("Mesh assets are generated for non-procedural tileset brushes and often not needed after brushes are deleted.\n\nMeshes not referenced by at least one tileset brush can be removed. Mesh will be missing for previously painted tiles."), EditorStyles.wordWrappedLabel);
                    GUILayout.Space(5);
                }
                GUILayout.EndVertical();

                GUILayout.FlexibleSpace();
            }
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            this.OnGUI_ButtonStrip();
        }
        /// <summary>
        /// Display user interface to force refresh all plops associated with a tile system.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="system"/> is <c>null</c>.
        /// </exception>
        internal static void Command_RefreshPlops(TileSystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            if (!EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Action", "Refresh Plops"),
                    string.Format(
                        /* 0: name of tile system */
                        TileLang.Text("Do you want to force refresh all plops associated with '{0}'?"),
                        system.name
                        ),
                    TileLang.ParticularText("Action", "Yes"),
                    TileLang.ParticularText("Action", "No")
                    ))
            {
                return;
            }

            // Refresh all plops which are associated with tile system.
            foreach (var plop in UnityEngine.Resources.FindObjectsOfTypeAll <PlopInstance>())
            {
                if (plop.Owner == system && plop.Brush != null)
                {
                    PlopUtility.RefreshPlop(system, plop);
                }
            }
        }
        internal static void DeleteBrush(Brush brush, bool selectParentTileset)
        {
            var brushRecord = BrushDatabase.Instance.FindRecord(brush);

            if (brushRecord == null)
            {
                return;
            }

            RotorzEditorGUI.ClearControlFocus();

            if (EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Action", "Delete Brush"),
                    string.Format(
                        /* 0: name of brush */
                        TileLang.Text("Deleting a brush that has been previously used in a tile system may cause damage to that tile system.\n\n'{0}'\n\nDo you really want to delete this brush?"),
                        brushRecord.DisplayName
                        ),
                    TileLang.ParticularText("Action", "Yes"),
                    TileLang.ParticularText("Action", "No")
                    ))
            {
                // Determine whether tileset should be selected in designer.
                var designerWindow = RotorzWindow.GetInstance <DesignerWindow>();
                if (designerWindow != null && ReferenceEquals(brushRecord.Brush, designerWindow.SelectedObject))
                {
                    designerWindow.SelectedObject = selectParentTileset && brushRecord.Brush is TilesetBrush
                        ? (brushRecord.Brush as TilesetBrush).Tileset
                        : null;
                }

                BrushUtility.DeleteBrush(brushRecord.Brush);
            }
        }
        /// <summary>
        /// Display user interface to clear a tile system.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="system"/> is <c>null</c>.
        /// </exception>
        internal static void Command_Clear(TileSystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            if (!EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Action", "Clear Tiles"),
                    string.Format(
                        /* 0: name of tile system */
                        TileLang.Text("Do you really want to clear all tiles from '{0}'?"),
                        system.name
                        ),
                    TileLang.ParticularText("Action", "Yes"),
                    TileLang.ParticularText("Action", "No")
                    ))
            {
                return;
            }

            // Register undo event.
            Undo.RegisterFullObjectHierarchyUndo(system.gameObject, TileLang.ParticularText("Action", "Clear Tiles"));
            // Erase all tiles from selected system.
            system.EraseAllTiles();
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        public override void OnExtendedPropertiesGUI()
        {
            var emptyBrush = Brush as EmptyBrush;

            using (var content = ControlContent.WithTrailableTip(
                       TileLang.ParticularText("Property", "Always Add Container"),
                       TileLang.Text("Add tile container object even when not needed by brush.")
                       )) {
                emptyBrush.alwaysAddContainer = EditorGUILayout.ToggleLeft(content, emptyBrush.alwaysAddContainer);
                ExtraEditorGUI.TrailingTip(content);
            }

            using (var content = ControlContent.WithTrailableTip(
                       TileLang.ParticularText("Property", "Add Collider"),
                       TileLang.Text("Automatically adds box collider to painted tile.")
                       )) {
                emptyBrush.addCollider = EditorGUILayout.ToggleLeft(content, emptyBrush.addCollider);
                if (emptyBrush.addCollider)
                {
                    ++EditorGUI.indentLevel;
                    emptyBrush.colliderType = (ColliderType)EditorGUILayout.EnumPopup(emptyBrush.colliderType);
                    --EditorGUI.indentLevel;
                }
                ExtraEditorGUI.TrailingTip(content);
            }
        }
        private bool ValidateInputs(string brushName, Brush targetBrush)
        {
            if (!this.ValidateUniqueAssetName(brushName))
            {
                return(false);
            }

            if (targetBrush == null)
            {
                EditorUtility.DisplayDialog(
                    TileLang.Text("Target brush was not specified"),
                    TileLang.Text("Select the brush that you would like to create an alias of."),
                    TileLang.ParticularText("Action", "Close")
                    );
                return(false);
            }

            var targetBrushDescriptor = BrushUtility.GetDescriptor(targetBrush.GetType());

            if (targetBrushDescriptor == null || !targetBrushDescriptor.SupportsAliases)
            {
                EditorUtility.DisplayDialog(
                    TileLang.Text("Unable to create alias brush"),
                    string.Format(
                        /* 0: class of target brush */
                        TileLang.Text("No alias designer was registered for '{0}'"),
                        targetBrush.GetType().FullName
                        ),
                    TileLang.ParticularText("Action", "Close")
                    );
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var idProperty    = property.FindPropertyRelative("id");
            var labelProperty = property.FindPropertyRelative("label");

            float initialLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 64;

            if (ProjectSettings.Instance.ShowCategoryIds)
            {
                using (var content = ControlContent.Basic(
                           labelText: string.Format(
                               /* 0: category id */
                               TileLang.Text("Id: {0}"),
                               idProperty.intValue
                               )
                           )) {
                    position = EditorGUI.PrefixLabel(position, content);
                }
            }

            labelProperty.stringValue = EditorGUI.TextField(position, labelProperty.stringValue);

            EditorGUIUtility.labelWidth = initialLabelWidth;
        }
        /// <inheritdoc/>
        protected override void DoEnable()
        {
            this.titleContent = new GUIContent(string.Format(
                                                   /* 0: name of product */
                                                   TileLang.Text("Preferences - {0}"),
                                                   ProductInfo.Name
                                                   ));
            this.InitialSize = this.minSize = new Vector2(500, 342);
            this.maxSize     = new Vector2(500, 10000);

            this.wantsMouseMove = true;

            this.tabs = new GUIContent[] {
                ControlContent.Basic(TileLang.ParticularText("Preferences|TabLabel", "Tools")),
                ControlContent.Basic(TileLang.ParticularText("Preferences|TabLabel", "Painting")),
                ControlContent.Basic(TileLang.ParticularText("Preferences|TabLabel", "Grid")),
                ControlContent.Basic(TileLang.ParticularText("Preferences|TabLabel", "Misc"))
            };

            this.scrolling = new Vector2[this.tabs.Length];

            this.toolsAdaptor = new GenericListAdaptor <ToolBase>(ToolManager.Instance.toolsInUserOrder, this.DrawAvailableToolEntry, 22);

            this.GatherLocaleOptions();
        }
        private void DrawPaintingTab()
        {
            RtsPreferences.EraseEmptyChunksPreference.Value = (EraseEmptyChunksPreference)EditorGUILayout.EnumPopup(TileLang.Text("Erase empty chunks"), RtsPreferences.EraseEmptyChunksPreference);

            ExtraEditorGUI.SeparatorLight();

            RtsPreferences.ToolPreferredNozzleIndicator.Value = (NozzleIndicator)EditorGUILayout.EnumPopup(TileLang.Text("Preferred nozzle indicator"), RtsPreferences.ToolPreferredNozzleIndicator);
            ++EditorGUI.indentLevel;
            {
                RtsPreferences.ToolWireframeColor.Value = EditorGUILayout.ColorField(TileLang.ParticularText("RenderMode", "Wireframe"), RtsPreferences.ToolWireframeColor);
                RtsPreferences.ToolShadedColor.Value    = EditorGUILayout.ColorField(TileLang.ParticularText("RenderMode", "Shaded"), RtsPreferences.ToolShadedColor);
            }
            --EditorGUI.indentLevel;

            ExtraEditorGUI.SeparatorLight();

            RtsPreferences.ToolImmediatePreviews.Value = EditorGUILayout.ToggleLeft(TileLang.Text("Display immediate previews"), RtsPreferences.ToolImmediatePreviews);
            EditorGUI.BeginDisabledGroup(!RtsPreferences.ToolImmediatePreviews);
            ++EditorGUI.indentLevel;
            {
                RtsPreferences.ToolImmediatePreviewsTintColor.Value = EditorGUILayout.ColorField(TileLang.Text("Preview Tint"), RtsPreferences.ToolImmediatePreviewsTintColor);

                RtsPreferences.ToolImmediatePreviewsSeeThrough.Value = EditorGUILayout.Toggle(TileLang.Text("See-through previews"), RtsPreferences.ToolImmediatePreviewsSeeThrough);
                ExtraEditorGUI.TrailingTip(TileLang.Text("Hold control when painting to temporarily see-through."));
            }
            --EditorGUI.indentLevel;
            EditorGUI.EndDisabledGroup();
        }
        /// <inheritdoc/>
        protected override void DoEnable()
        {
            this.wantsMouseMove = true;

            this.titleContent = new GUIContent(TileLang.Text("Tools"));
            this.minSize      = new Vector2(255, 80);
        }
Exemplo n.º 12
0
        private static string SaveBuildSceneAs()
        {
            string currentScenePath = EditorApplication.currentScene.Replace("Assets/", Application.dataPath + "/");
            int    fileNameIndex    = currentScenePath.LastIndexOf('/');

            // Prompt user to save built scene.
            string outputPath;

            while (true)
            {
                // Prompt user to save scene.
                outputPath = EditorUtility.SaveFilePanel(
                    title: TileLang.ParticularText("Action", "Save Built Scene"),
                    directory: currentScenePath.Substring(0, fileNameIndex),
                    defaultName: currentScenePath.Substring(fileNameIndex + 1).Replace(".unity", "_build.unity"),
                    extension: "unity"
                    );
                // Make output path relative to project.
                outputPath = outputPath.Replace(Application.dataPath, "Assets");

                // Attempt to save scene.
                if (!string.IsNullOrEmpty(outputPath))
                {
                    if (outputPath == EditorApplication.currentScene)
                    {
                        if (EditorUtility.DisplayDialog(
                                TileLang.Text("Error"),
                                TileLang.ParticularText("Error", "Cannot overwrite current scene with built scene."),
                                TileLang.ParticularText("Action", "Choose Other"),
                                TileLang.ParticularText("Action", "Cancel")
                                ))
                        {
                            continue;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    // Ensure that built scene will be placed within "Assets" directory.
                    else if (outputPath.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }

                // Allow user to retry!
                if (!EditorUtility.DisplayDialog(
                        TileLang.Text("Error"),
                        TileLang.ParticularText("Error", "Was unable to save built scene.\n\nWould you like to specify an alternative filename?"),
                        TileLang.ParticularText("Action", "Yes"),
                        TileLang.ParticularText("Action", "No")
                        ))
                {
                    return(null);
                }
            }

            return(outputPath);
        }
        public override void OnInspectorGUI()
        {
            bool  initialWideMode   = EditorGUIUtility.wideMode;
            float initialLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.wideMode = true;
            RotorzEditorGUI.UseExtendedLabelWidthForLocalization();

            this.serializedObject.Update();

            this.propertyExpandTilesetCreatorSection.boolValue = RotorzEditorGUI.FoldoutSection(
                foldout: this.propertyExpandTilesetCreatorSection.boolValue,
                label: TileLang.Text("Brush and Tileset Creator"),
                callback: this.DrawCreatorSection,
                paddedStyle: RotorzEditorStyles.Instance.InspectorSectionPadded
                );

            this.propertyExpandBrushCategoriesSection.boolValue = RotorzEditorGUI.FoldoutSection(
                foldout: this.propertyExpandBrushCategoriesSection.boolValue,
                label: TileLang.Text("Brush Categories"),
                callback: this.DrawCategoriesSections,
                paddedStyle: RotorzEditorStyles.Instance.InspectorSectionPadded
                );

            EditorGUIUtility.wideMode   = initialWideMode;
            EditorGUIUtility.labelWidth = initialLabelWidth;

            this.serializedObject.ApplyModifiedProperties();
        }
        /// <inheritdoc/>
        protected override void DoGUI()
        {
            this.hasDrawnGUI = true;

            if (this.tileSystem == null)
            {
                return;
            }

            GUISkin skin = GUI.skin;

            GUILayout.Space(15f);

            ExtraEditorGUI.AbovePrefixLabel(TileLang.ParticularText("Property", "Prefab Output Path:"));
            GUILayout.BeginHorizontal();
            {
                this.PrefabOutputPath = RotorzEditorGUI.RelativeAssetPathTextField(GUIContent.none, this.PrefabOutputPath, ".prefab");
                if (GUILayout.Button("...", GUILayout.Width(40)))
                {
                    GUIUtility.keyboardControl = 0;
                    this.PrefabOutputPath      = this.DoSelectPrefabPath(
                        TileLang.ParticularText("Action", "Save Prefab Output"),
                        TileLang.Text("Specify path for prefab output"),
                        this.PrefabOutputPath
                        );
                }
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.Space();

            ExtraEditorGUI.AbovePrefixLabel(TileLang.ParticularText("Property", "Data Output Path:"));
            GUILayout.BeginHorizontal();
            {
                this.DataOutputPath = RotorzEditorGUI.RelativeAssetPathTextField(GUIContent.none, this.DataOutputPath, ".asset");
                if (GUILayout.Button("...", GUILayout.Width(40)))
                {
                    GUIUtility.keyboardControl = 0;
                    this.DataOutputPath        = this.DoSelectAssetPath(
                        TileLang.ParticularText("Action", "Save Data Output"),
                        TileLang.Text("Specify path for mesh output"),
                        this.DataOutputPath
                        );
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();
            ExtraEditorGUI.Separator(marginBottom: 10);

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                this.OnGUI_Buttons();
                GUILayout.Space(5f);
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(8f);
        }
Exemplo n.º 15
0
        private static void DropDownSpacingCoordinate(Rect position, SnapAxis axis)
        {
            s_DropDownSnapAxis = axis;

            var menu = new EditorMenu();

            menu.AddCommand(TileLang.Text("Fraction of Cell Size"))
            .Checked(axis.GridType == SnapGridType.Fraction)
            .Action(DoSelectSpacingType, SnapGridType.Fraction);

            menu.AddCommand(TileLang.Text("Custom Size"))
            .Checked(axis.GridType == SnapGridType.Custom)
            .Action(DoSelectSpacingType, SnapGridType.Custom);

            menu.AddSeparator();

            foreach (int fractionValue in new int[] { 1, 2, 4, 8, 16 })
            {
                menu.AddCommand(string.Format("{0} \u2044 {1}", 1, fractionValue))
                .Action(s_DropDownSnapAxis.SetFraction, fractionValue);
            }

            menu.AddSeparator();

            foreach (float decimalValue in new float[] { 0.1f, 0.25f, 0.5f, 1f, 2f })
            {
                menu.AddCommand(string.Format("{0}", decimalValue))
                .Action(s_DropDownSnapAxis.SetCustomSize, decimalValue);
            }

            menu.ShowAsDropdown(position);
        }
 private void OnButton_DeletePreset()
 {
     if (this.selectedPreset == null)
     {
         EditorUtility.DisplayDialog(
             TileLang.Text("Error"),
             TileLang.ParticularText("Error", "Cannot delete a default preset."),
             TileLang.ParticularText("Action", "Close")
             );
     }
     else if (EditorUtility.DisplayDialog(
                  TileLang.ParticularText("Action", "Delete Preset"),
                  string.Format(
                      /* 0: name of the preset */
                      TileLang.ParticularText("Error", "Do you want to delete the preset '{0}'?"),
                      this.currentPreset.name
                      ),
                  TileLang.ParticularText("Action", "Yes"),
                  TileLang.ParticularText("Action", "No")
                  ))
     {
         // Remove the selected preset asset.
         TileSystemPresetUtility.DeletePreset(this.selectedPreset);
         // Select the default preset.
         this.SetSelectedPreset("");
     }
 }
Exemplo n.º 17
0
        private void DrawProceduralField(TilesetBrush brush, Tileset tileset)
        {
            using (var content = ControlContent.WithTrailableTip(
                       TileLang.ParticularText("Property", "Procedural"),
                       TileLang.Text("Allows individual atlas brushes to override property of tileset.")
                       )) {
                // Need to make width of "Procedural" popup shorter.
                GUILayout.BeginHorizontal(GUILayout.Width(200));
                InheritYesNo newProcedural = (InheritYesNo)EditorGUILayout.EnumPopup(content, brush.procedural);
                if (newProcedural != brush.procedural)
                {
                    brush.procedural = newProcedural;

                    if (!brush.IsProcedural)
                    {
                        // Ensure that required procedural mesh exists!
                        if (BrushUtility.EnsureTilesetMeshExists(tileset, brush.tileIndex))
                        {
                            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tileset.tileMeshAsset));
                        }
                    }
                }

                Rect position = GUILayoutUtility.GetLastRect();
                GUI.Label(new Rect(position.x + position.width, position.y, 100, position.height), "= " + (brush.IsProcedural ? TileLang.Text("Procedural") : TileLang.Text("Non-Procedural")), EditorStyles.miniLabel);

                GUILayout.EndHorizontal();

                ExtraEditorGUI.TrailingTip(content);
            }
        }
Exemplo n.º 18
0
        private void DrawStatusPanel()
        {
            var tileSystem = target as TileSystem;

            Handles.BeginGUI();

            if (tileSystem.IsEditable)
            {
                string title = tileSystem.name;
                if (tileSystem.Locked)
                {
                    title += " <color=yellow><b>(" + TileLang.ParticularText("Status", "Locked") + ")</b></color>";
                }

                Rect position = new Rect(0, Screen.height - 21 - 42, 380, 42);
                GUI.Window(0, position, this._statusPanelWindowFunction, title, RotorzEditorStyles.Instance.StatusWindow);
                GUI.UnfocusWindow();
            }
            else
            {
                Rect position = new Rect(5, Screen.height - 42 - 40, 380, 40);
                EditorGUI.HelpBox(position, TileLang.Text("Tile system has been built and can no longer be edited."), MessageType.Warning);
            }

            Handles.EndGUI();
        }
Exemplo n.º 19
0
        /// <inheritdoc/>
        public override void OnGUI()
        {
            GUILayout.Label(TileLang.Text("Create brush whose tiles have no visual representation."), EditorStyles.wordWrappedLabel);
            GUILayout.Space(10f);

            this.DrawBrushNameField();
        }
Exemplo n.º 20
0
        private void DrawTilesetBrushInfoSection()
        {
            var tileset = this.TilesetBrush.Tileset;

            GUILayout.BeginVertical();

            if (this.TilesetRecord == null)
            {
                GUILayout.Label(TileLang.Text("Error: No tileset associated with brush."));
                return;
            }

            float restoreLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            GUILayout.Space(10);

            this.DrawTilesetBrushInfo();

            GUILayout.Space(10);

            this.DrawTilesetBrushInfoActions();

            EditorGUIUtility.labelWidth = restoreLabelWidth;

            GUILayout.EndVertical();
        }
Exemplo n.º 21
0
        private bool ValidateInputs(string tilesetName)
        {
            if (!this.ValidateAssetName(tilesetName))
            {
                return(false);
            }

            foreach (var tilesetRecord in BrushDatabase.Instance.TilesetRecords)
            {
                if (tilesetRecord.DisplayName == tilesetName)
                {
                    EditorUtility.DisplayDialog(
                        TileLang.Text("Tileset already exists"),
                        TileLang.Text("Please specify unique name for tileset."),
                        TileLang.ParticularText("Action", "OK")
                        );
                    return(false);
                }
            }

            if (this.tilesetTexture == null)
            {
                EditorUtility.DisplayDialog(
                    TileLang.Text("Texture was not specified"),
                    TileLang.Text("Texture must be specified before creating tileset."),
                    TileLang.ParticularText("Action", "OK")
                    );
                return(false);
            }

            return(true);
        }
        private void DoBuild()
        {
            this.PrefabOutputPath = this.PrefabOutputPath.Trim();
            this.DataOutputPath   = this.DataOutputPath.Trim();

            string resolvedPrefabPath = this.GetResolvedPrefabPath();
            string resolvedDataPath   = this.GetResolvedDataPath();

            if (this.ValidateAssetPath("prefab", resolvedPrefabPath) && this.ValidateAssetPath("data asset", resolvedDataPath))
            {
                // Confirm action with user if prefab and/or data asset already exist.
                bool outputPrefabAlreadyExists = File.Exists(Path.Combine(Directory.GetCurrentDirectory(), resolvedPrefabPath));
                bool outputDataAlreadyExists   = File.Exists(Path.Combine(Directory.GetCurrentDirectory(), resolvedDataPath));
                if (outputPrefabAlreadyExists || outputDataAlreadyExists)
                {
                    if (!EditorUtility.DisplayDialog(
                            TileLang.Text("Warning, Output prefab or data asset already exists!"),
                            TileLang.Text("Do you really want to overwrite?"),
                            TileLang.ParticularText("Action", "Yes"),
                            TileLang.ParticularText("Action", "No")
                            ))
                    {
                        return;
                    }
                }

                BuildUtility.BuildPrefab(this.TileSystem, resolvedDataPath, resolvedPrefabPath);
                this.Close();
            }
        }
Exemplo n.º 23
0
        private void OnButton_Replace()
        {
            // Verify inputs!
            if (this.sourceBrush == null)
            {
                EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Error", "No source brush specified"),
                    TileLang.Text("Please select source brush to find tiles with."),
                    TileLang.ParticularText("Action", "Close")
                    );
                return;
            }

            if (this.sourceBrush == this.replacementBrush)
            {
                EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Error", "Source and replacement brushes are the same"),
                    TileLang.ParticularText("Error", "Cannot find and replace with same brush."),
                    TileLang.ParticularText("Action", "Close")
                    );
                return;
            }

            // Perform find and replace.
            if (this.OnFindReplace != null)
            {
                this.OnFindReplace(this.targetSystems, this.sourceBrush, this.replacementBrush);
            }
        }
        private void OptimizeProceduralMeshes(TileSystem system)
        {
            // StripBrushReferences - Can still be stripped because they are not needed
            //                        to paint procedural meshes :-)

            if (system.pregenerateProcedural)
            {
                this.ReportProgress(TileLang.Text("Generating procedural tiles..."));
                this.PregenerateProceduralMeshes(system);
            }
            else
            {
                // Find out if tile system contains any procedural tiles.
                bool containsProceduralTiles = this.DoesContainProceduralTiles(system.Chunks);

                // Automatically downgrade stripping options if needed.
                if (containsProceduralTiles)
                {
                    // Only proceed if stripping options will actually be reduced.
                    // Note: For more accurate log message!
                    if (system.StripSystemComponent || system.StripChunkMap || system.StripChunks || system.StripTileData)  // || system.StripBrushReferences)
                    {
                        this.ReduceStrippingOptionsForProceduralMeshGeneration(system);
                    }
                }
                else
                {
                    // Remove redundant procedural mesh components.
                    this.DestroyGeneratedProceduralMeshes(system);
                }
            }
        }
        /// <summary>
        /// Occurs when header GUI is rendered and for GUI event handling.
        /// </summary>
        /// <remarks>
        /// <para>This means that your <see cref="OnFixedHeaderGUI"/> implementation might
        /// be called several times per frame (one call per event).</para>
        /// <para>The default implementation allows users to:</para>
        /// <list type="bullet">
        ///     <item>Rename brush</item>
        ///     <item>Mark brush as "static"</item>
        ///     <item>Mark brush as "smooth"</item>
        ///     <item>Hide brush</item>
        ///     <item>Set layer and tag for painted tiles</item>
        ///     <item>Categorize brush</item>
        /// </list>
        /// </remarks>
        public override void OnFixedHeaderGUI()
        {
            GUILayout.Space(6);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(90);

                EditorGUIUtility.labelWidth = 80;
                this.DrawTilesetNameField();

                GUILayout.Label(
                    TileLang.PluralText(
                        /* 0: quantity of brushes */
                        "Contains 1 brush",
                        "Contains {0} brushes",
                        this.tilesetRecord.BrushRecords.Count
                        ),
                    RotorzEditorStyles.Instance.LabelMiddleLeft
                    );

                Rect menuPosition = GUILayoutUtility.GetRect(GUIContent.none, RotorzEditorStyles.Instance.LabelMiddleLeft, GUILayout.Width(45));
                this.DrawMenuButton(new Rect(menuPosition.x, 2, 44, 26), TileLang.Text("Tileset Menu"));

                this.DrawHelpButton();
            }
            GUILayout.EndHorizontal();

            EditorGUIUtility.labelWidth = 125;

            ExtraEditorGUI.SeparatorLight(marginTop: 7, marginBottom: 0, thickness: 3);

            this.DrawTabs();
        }
Exemplo n.º 26
0
        /// <inheritdoc/>
        protected override void DoGUI()
        {
            GUILayout.Space(10);

            GUILayout.BeginVertical(this.paddedArea1Style);
            RotorzEditorGUI.Title(TileLang.ParticularText("Action", "Refresh Tiles"));
            GUILayout.Space(5);
            GUILayout.Label(TileLang.Text("Tiles are replaced if obvious changes are detected. You can force refresh all tiles if necessary."), EditorStyles.wordWrappedLabel);

            ExtraEditorGUI.SeparatorLight(marginTop: 5, marginBottom: 5, thickness: 3);

            GUILayout.BeginVertical(this.paddedArea2Style);
            s_ForceRefreshTiles = EditorGUILayout.ToggleLeft(TileLang.ParticularText("Property", "Force refresh all tiles"), s_ForceRefreshTiles);

            GUILayout.Space(2);
            EditorGUI.indentLevel += 2;
            if (!s_ForceRefreshTiles)
            {
                s_UpdateProcedural = EditorGUILayout.ToggleLeft(TileLang.ParticularText("Property", "Update procedural tiles"), s_UpdateProcedural);
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.ToggleLeft(TileLang.ParticularText("Property", "Update procedural tiles"), true);
                EditorGUI.EndDisabledGroup();
            }
            EditorGUI.indentLevel -= 2;
            GUILayout.Space(2);
            s_PreserveManualOffset = EditorGUILayout.ToggleLeft(TileLang.ParticularText("Property", "Preserve manual offsets"), s_PreserveManualOffset);
            GUILayout.Space(2);
            s_PreserveFlags = EditorGUILayout.ToggleLeft(TileLang.ParticularText("Property", "Preserve painted user flags"), s_PreserveFlags);
            GUILayout.EndVertical();
            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();

            EditorGUILayout.HelpBox(TileLang.Text("Some manual changes may be lost when refreshing tiles."), MessageType.Warning, true);

            GUILayout.Space(8);

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(TileLang.ParticularText("Action", "Refresh"), ExtraEditorStyles.Instance.BigButtonPadded))
            {
                this.OnButtonRefresh();
                GUIUtility.ExitGUI();
            }
            GUILayout.Space(3);
            if (GUILayout.Button(TileLang.ParticularText("Action", "Cancel"), ExtraEditorStyles.Instance.BigButtonPadded))
            {
                this.Close();
                GUIUtility.ExitGUI();
            }
            GUILayout.Space(5);
            GUILayout.EndHorizontal();

            GUILayout.Space(8);
        }
Exemplo n.º 27
0
        /// <inheritdoc/>
        public override void OnGUI()
        {
            GUILayout.Label(
                TileLang.Text("Two-dimensional tile brushes can be created from a tileset."),
                EditorStyles.wordWrappedLabel
                );
            GUILayout.Space(10f);

            this.DrawTilesetNameField();

            GUILayout.Space(5f);

            EditorGUI.BeginChangeCheck();
            {
                GUILayout.BeginHorizontal();
                {
                    this.DrawAtlasTextureField();
                    GUILayout.Space(7f);
                    this.DrawAtlasParametersGUI();
                    GUILayout.Space(20f);
                    this.DrawEdgeCorrectionGUI();
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndHorizontal();
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.RecalculateMetrics();
            }

            // Display warning message if another similar tileset already exists.
            if (!string.IsNullOrEmpty(this.otherTilesetName))
            {
                EditorGUILayout.HelpBox(string.Format(
                                            /* 0: name of the similar tileset */
                                            TileLang.Text("Another similar tileset '{0}' exists that uses the same atlas texture."),
                                            this.otherTilesetName
                                            ), MessageType.Warning, true);
            }

            // Display warning message if texture is not power-of-two.
            if (this.tilesetTexture != null && (!Mathf.IsPowerOfTwo(this.tilesetTexture.width) || !Mathf.IsPowerOfTwo(this.tilesetTexture.height) || this.tilesetTexture.width != this.tilesetTexture.height))
            {
                EditorGUILayout.HelpBox(TileLang.Text("Texture is not power of two and/or is not square."), MessageType.Warning, true);
            }

            ExtraEditorGUI.SeparatorLight(marginTop: 12, marginBottom: 5, thickness: 3);

            if (this.tilesetPreviewUtility == null)
            {
                this.tilesetPreviewUtility = new TilesetPreviewUtility(this.Context);
            }

            if (!this.tilesetPreviewUtility.DrawTilePreviews(this.tilesetTexture, this.tilesetMetrics))
            {
                GUILayout.Label(TileLang.Text("No previews to display..."));
            }
        }
        /// <inheritdoc/>
        protected internal override void EndExtendedProperties()
        {
            ShowExtendedOrientation = RotorzEditorGUI.FoldoutSection(ShowExtendedOrientation,
                                                                     label: TileLang.Text("Automatic Orientations"),
                                                                     callback: this.OnExtendedGUI_Coalescing
                                                                     );

            base.EndExtendedProperties();
        }
        /// <summary>
        /// Display user interface for repairing broken and dirty tiles in a tile system.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="system"/> is <c>null</c>.
        /// </exception>
        internal static void Command_Repair(TileSystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            system.UpdateProceduralTiles(true);

            // First check tile system for broken tiles.
            int count = system.ScanBrokenTiles(RepairAction.JustCount);

            if (count == 0)
            {
                EditorUtility.DisplayDialog(
                    TileLang.ParticularText("Action", "Repair Tiles"),
                    string.Format(
                        /* 0: name of tile system */
                        TileLang.Text("No broken tiles were detected in '{0}'."),
                        system.name
                        ),
                    TileLang.ParticularText("Action", "Close")
                    );
                return;
            }

            int choice = EditorUtility.DisplayDialogComplex(
                TileLang.ParticularText("Action", "Repair Tiles"),
                string.Format(

                    /* 0: name of tile system
                     * 1: quantity of broken tiles */
                    TileLang.Text("Detected {1} broken tiles where associated game object is missing.\n\nThis usually occurs when tiles are deleted manually. Use erase tool (or erase functionality of paint tool) instead of deleting tile objects manually.\n\nBroken tiles can often be repaired by force refreshing them, or alternatively erased."),
                    system.name, count
                    ),
                TileLang.ParticularText("Action", "Erase"),
                TileLang.ParticularText("Action", "Cancel"),
                TileLang.ParticularText("Action", "Repair")
                );

            if (choice == 1)
            {
                return;
            }

            Undo.RegisterFullObjectHierarchyUndo(system.gameObject, TileLang.ParticularText("Action", "Repair Tiles"));

            if (choice == 0)
            {
                system.ScanBrokenTiles(RepairAction.Erase);
            }
            else
            {
                system.ScanBrokenTiles(RepairAction.ForceRefresh);
            }
        }
Exemplo n.º 30
0
        /// <inheritdoc/>
        public override void OnGUI()
        {
            GUILayout.Label(
                TileLang.Text("Simple brushes can be created by adding one or more tile variations to the default orientation. Additional orientations can be defined so that tiles are painted based upon neighboring tiles."),
                EditorStyles.wordWrappedLabel
                );
            GUILayout.Space(10f);

            this.DrawBrushNameField();
        }