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(""); } }
private void PopulatePresetMenu(ICustomPopupContext <string> context) { var popup = context.Popup; popup.AddOption(TileLang.ParticularText("Preset Name", "Default: 3D"), context, "F:3D"); popup.AddOption(TileLang.ParticularText("Preset Name", "Default: 2D"), context, "F:2D"); var presets = TileSystemPresetUtility.GetPresets(); if (presets.Length == 0) { return; } popup.AddSeparator(); var presetGroups = presets .OrderBy(preset => preset.name) .GroupBy(preset => TileSystemPresetUtility.IsUserPreset(preset)) .ToArray(); for (int i = 0; i < presetGroups.Length; ++i) { if (i != 0) { popup.AddSeparator(); } foreach (var preset in presetGroups[i]) { popup.AddOption(preset.name, context, TileSystemPresetUtility.GetPresetGUID(preset)); } } }
/// <summary> /// Set the currently selected preset. /// </summary> /// <param name="presetGuid">Name of preset.</param> private void SetSelectedPreset(string presetGuid) { this.selectedPreset = null; // Figure out a valid preset GUID. if (presetGuid != "F:3D" && presetGuid != "F:2D") { this.selectedPreset = TileSystemPresetUtility.LoadPresetFromGUID(presetGuid); if (this.selectedPreset == null) { presetGuid = TileSystemPresetUtility.DefaultPresetGUID; } } // Persist current preset selection. s_SelectedPresetGuid.Value = presetGuid; // Preserve user input for tile system name! string preserveSystemName = this.currentPreset.SystemName; // Update the new tile system configuration from the selected preset. switch (presetGuid) { case "F:3D": this.currentPreset.SetDefaults3D(); this.currentPreset.name = TileLang.ParticularText("Preset Name", "Default: 3D"); this.newPresetName = ""; break; case "F:2D": this.currentPreset.SetDefaults2D(); this.currentPreset.name = TileLang.ParticularText("Preset Name", "Default: 2D"); this.newPresetName = ""; break; default: EditorUtility.CopySerialized(this.selectedPreset, this.currentPreset); this.newPresetName = this.currentPreset.name; break; } // Remove input focus from any control but most specifically "Preset Name". GUIUtility.keyboardControl = 0; if (this.currentPresetInspector.HasModifiedTileSystemName) { this.currentPreset.SystemName = preserveSystemName; } else { this.AutoAddPostfixToName(); } }
protected override void OnHeaderGUI() { Rect position = GUILayoutUtility.GetRect(0, 46); if (Event.current.type == EventType.Repaint) { GUI.skin.box.Draw(position, GUIContent.none, false, false, false, false); GUI.DrawTexture(new Rect(7, 7, 32, 32), RotorzEditorStyles.Skin.Icon_PresetTileSystem); string headerText = targets.Length == 1 ? string.Format( /* 0: name of tile system preset */ TileLang.Text("{0} (Tile System Preset)"), target.name ) : string.Format( /* 0: quantity of selected tile system presets */ TileLang.Text("{0} Tile System Presets"), targets.Length ); EditorStyles.largeLabel.Draw(new Rect(48, 7, position.width - 48, position.height), headerText, false, false, false, false); } Rect menuPosition = new Rect(position.width - 25, 7, 22, 16); if (GUI.Button(menuPosition, RotorzEditorStyles.Skin.SmallGearButton, GUIStyle.none)) { this.ShowContextMenu(menuPosition); GUIUtility.ExitGUI(); } EditorGUI.BeginDisabledGroup(targets.Length != 1); { using (var content = ControlContent.Basic( TileLang.ParticularText("Action", "Create Tile System") )) { Vector2 createButtonSize = EditorStyles.miniButton.CalcSize(content); Rect createButtonPosition = new Rect(position.width - createButtonSize.x - 5, 24, createButtonSize.x, createButtonSize.y); if (GUI.Button(createButtonPosition, content, EditorStyles.miniButton)) { var tileSystemGO = TileSystemPresetUtility.CreateTileSystemFromPreset((TileSystemPreset)target); Selection.activeObject = tileSystemGO; Undo.RegisterCreatedObjectUndo(tileSystemGO, content.LabelContent.text); } } } EditorGUI.EndDisabledGroup(); GUILayout.Space(5); }
private void OnButton_Create() { this.currentPreset.SystemName = this.currentPreset.SystemName.Trim(); // Validate inputs first. if (string.IsNullOrEmpty(this.currentPreset.SystemName)) { EditorUtility.DisplayDialog( TileLang.ParticularText("Error", "Name was not specified"), TileLang.Text("Please specify name for tile system."), TileLang.ParticularText("Action", "Close") ); GUIUtility.ExitGUI(); } // Do not allow user to create useless system. if (this.currentPreset.Rows < 1 || this.currentPreset.Columns < 1) { EditorUtility.DisplayDialog( TileLang.Text("Error"), TileLang.Text("A tile system must contain at least 1 cell."), TileLang.ParticularText("Action", "Close") ); GUIUtility.ExitGUI(); return; } // Create tile system using preset and select it ready for immediate usage. var tileSystemGO = TileSystemPresetUtility.CreateTileSystemFromPreset(this.currentPreset); Selection.activeObject = tileSystemGO; // Register undo event. Undo.IncrementCurrentGroup(); Undo.RegisterCreatedObjectUndo(tileSystemGO, TileLang.ParticularText("Action", "Create Tile System")); if (this.TileSystemCreated != null) { this.TileSystemCreated(tileSystemGO.GetComponent <TileSystem>()); } this.Close(); }
private void OnButton_SavePreset() { // Remove focus from input control. GUIUtility.keyboardControl = 0; this.newPresetName = this.newPresetName.Trim(); // Name must be specified for preset! if (string.IsNullOrEmpty(this.newPresetName)) { EditorUtility.DisplayDialog( TileLang.ParticularText("Error", "One or more inputs were invalid"), TileLang.ParticularText("Error", "Name was not specified"), TileLang.ParticularText("Action", "Close") ); } else if (!TileSystemPresetUtility.IsValidPresetName(this.newPresetName)) { EditorUtility.DisplayDialog( TileLang.ParticularText("Error", "Invalid name for the asset"), TileLang.ParticularText("Error", "Can only use alphanumeric characters (A-Z a-z 0-9), hyphens (-), underscores (_) and spaces.\n\nName must begin with an alphanumeric character."), TileLang.ParticularText("Action", "Close") ); } else { if (this.selectedPreset != null && this.newPresetName == this.selectedPreset.name) { TileSystemPresetUtility.OverwritePreset(this.currentPreset, this.selectedPreset); } else { var newPreset = TileSystemPresetUtility.CreatePreset(this.currentPreset, this.newPresetName); this.SetSelectedPreset(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(newPreset))); } } }