private void DrawHelpButton() { GUILayout.Space(33); Rect position = new Rect(Window.position.width - 37, 2, 34, 26); using (var helpMenuContent = ControlContent.Basic( RotorzEditorStyles.Skin.ContextHelp, TileLang.ParticularText("Action", "Help") )) { if (EditorInternalUtility.DropdownMenu(position, helpMenuContent, RotorzEditorStyles.Instance.FlatButton)) { var helpMenu = new EditorMenu(); helpMenu.AddCommand(TileLang.ParticularText("Action", "Show Tips")) .Checked(ControlContent.TrailingTipsVisible) .Action(() => { ControlContent.TrailingTipsVisible = !ControlContent.TrailingTipsVisible; }); --position.y; helpMenu.ShowAsDropdown(position); } } }
/// <summary> /// Gets base path for the folder where new brush and tileset assets are created. /// Folder is automatically created if it does not already exist. /// </summary> /// <seealso cref="ProjectSettings.BrushesFolderRelativePath"/> public static string GetBrushAssetPath() { string brushesFolderAssetPath = "Assets/" + ProjectSettings.Instance.BrushesFolderRelativePath; EditorInternalUtility.EnsureThatAssetFolderExists(brushesFolderAssetPath); return(brushesFolderAssetPath + "/"); }
/// <summary> /// Draw selection history navigation buttons in fixed position of designer window. /// </summary> private void DrawHistoryButtons() { Rect backButtonPosition = new Rect(2, 4, 28, 21); Rect forwardButtonPosition = new Rect(backButtonPosition.xMax + 1, backButtonPosition.y, 28, 21); this._recentHistoryButtonPosition = new Rect(forwardButtonPosition.xMax + 1, backButtonPosition.y, 27, 21); EditorGUI.BeginDisabledGroup(!this.History.CanGoBack); if (RotorzEditorGUI.HoverButton(backButtonPosition, s_content_HistoryBackButton, RotorzEditorStyles.Instance.HistoryNavButton)) { this.History.GoBack(); GUIUtility.ExitGUI(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!this.History.CanGoForward); if (RotorzEditorGUI.HoverButton(forwardButtonPosition, s_content_HistoryForwardButton, RotorzEditorStyles.Instance.HistoryNavButton)) { this.History.GoForward(); GUIUtility.ExitGUI(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(this.History.Recent.Count == 0); if (EditorInternalUtility.DropdownMenu(this._recentHistoryButtonPosition, s_content_HistoryRecentButton, RotorzEditorStyles.Instance.HistoryNavButton)) { this.ShowRecentHistoryMenu(); } EditorGUI.EndDisabledGroup(); }
/// <summary> /// Use to draw menu button somewhere within designer window. /// </summary> /// <remarks> /// <para>Custom menu items can be added to menu by providing a custom implementation /// of <see cref="AddItemsToMenu"/>.</para> /// </remarks> /// <param name="position">Position of button in space of editor window.</param> /// <param name="tooltip">Tooltip text.</param> protected void DrawMenuButton(Rect position, string tooltip = null) { using (var content = ControlContent.Basic(RotorzEditorStyles.Skin.GearButton, tooltip)) { if (EditorInternalUtility.DropdownMenu(position, content, RotorzEditorStyles.Instance.FlatButton)) { this.DisplayMenu(new Rect(position.x, position.y, position.width, position.height - 1)); GUIUtility.ExitGUI(); } } }
private void RecalculateMetrics() { int atlasWidth, atlasHeight; EditorInternalUtility.GetImageSize(this.tilesetTexture, out atlasWidth, out atlasHeight); this.tileWidth = Mathf.Clamp(this.tileWidth, 1, atlasWidth); this.tileHeight = Mathf.Clamp(this.tileHeight, 1, atlasHeight); this.tilesetMetrics.Calculate(this.tilesetTexture, this.tileWidth, this.tileHeight, this.borderSize, this.delta); }
/// <summary> /// Calculate metrics for specified tileset. /// </summary> /// <remarks> /// <para>Measurements are relative to original atlas size.</para> /// </remarks> /// <param name="atlas">Atlas texture for tileset.</param> /// <param name="tileWidth">Width of tile in pixels.</param> /// <param name="tileHeight">Height of tile in pixels.</param> /// <param name="borderSize">Border size in pixels.</param> /// <param name="delta">UV delta offset (fraction of pixel).</param> /// <returns> /// A value of <c>true</c> when valid atlas was specified; otherwise a value of <c>false</c>. /// </returns> public bool Calculate(Texture2D atlas, int tileWidth, int tileHeight, int borderSize, float delta) { int atlasWidth, atlasHeight; if (!EditorInternalUtility.GetImageSize(atlas, out atlasWidth, out atlasHeight)) { this.Clear(); return(false); } return(this.Calculate(atlasWidth, atlasHeight, tileWidth, tileHeight, borderSize, delta)); }
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 DrawHelpButton() { using (var content = ControlContent.Basic(RotorzEditorStyles.Skin.ContextHelp)) { Rect position = GUILayoutUtility.GetRect(content, RotorzEditorStyles.Instance.ToolbarButtonPadded); if (EditorInternalUtility.DropdownMenu(position, content, RotorzEditorStyles.Instance.ToolbarButtonPadded)) { var helpMenu = new EditorMenu(); helpMenu.AddCommand(TileLang.ParticularText("Action", "Show Tips")) .Checked(ControlContent.TrailingTipsVisible) .Action(() => { ControlContent.TrailingTipsVisible = !ControlContent.TrailingTipsVisible; }); --position.y; helpMenu.ShowAsDropdown(position); } } }
private void DrawAtlasTextureField() { EditorGUI.BeginChangeCheck(); { this.autotileTexture = RotorzEditorGUI.AutotileArtworkField(this.autotileTexture, s_SelectedAutotileLayout, s_InnerJoins); } if (EditorGUI.EndChangeCheck()) { if (this.autotileTextureUncompressed != null) { Object.DestroyImmediate(this.autotileTextureUncompressed); } this.autotileTextureUncompressed = EditorInternalUtility.LoadTextureUncompressed(this.autotileTexture); this.RecalculateTileSize(); this.RecalculateMetrics(); } }
/// <inheritdoc/> public override void AddItemsToMenu(EditorMenu menu) { base.AddItemsToMenu(menu); menu.AddCommand(TileLang.ParticularText("Action", "Reveal Material")) .Action(() => { EditorInternalUtility.FocusInspectorWindow(); EditorGUIUtility.PingObject(Tileset.AtlasMaterial); Selection.activeObject = Tileset.AtlasMaterial; }); menu.AddCommand(TileLang.ParticularText("Action", "Reveal Texture")) .Action(() => { if (Tileset.AtlasMaterial.mainTexture != null) { EditorInternalUtility.FocusInspectorWindow(); EditorGUIUtility.PingObject(Tileset.AtlasMaterial.mainTexture); Selection.activeObject = Tileset.AtlasMaterial.mainTexture; } }); // Only display "Cleanup Meshes" command when meshes are actually present! if (Tileset.tileMeshes != null && Tileset.tileMeshes.Length != 0) { menu.AddSeparator(); menu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Cleanup Meshes"))) .Action(() => { CleanupTilesetMeshesWindow.ShowWindow(Tileset); }); } menu.AddSeparator(); menu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Delete Tileset"))) .Action(() => { DeleteTilesetWindow.ShowWindow(Tileset); }); }
//!TODO: The following should be refactored so that the tile system is passed in // as the context object rather than using a closure. private EditorMenu BuildContextMenu(TileSystem system) { var contextMenu = new EditorMenu(); contextMenu.AddCommand(TileLang.ParticularText("Action", "Inspect")) .Action(() => { EditorInternalUtility.FocusInspectorWindow(); }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.ParticularText("Action", "Rename")) .Action(() => { this.BeginEditingName(system); }); contextMenu.AddCommand(TileLang.ParticularText("Action", "Lock")) .Checked(system.Locked) .Action(() => { Undo.RecordObject(system, system.Locked ? TileLang.ParticularText("Action", "Unlock Tile System") : TileLang.ParticularText("Action", "Lock Tile System")); system.Locked = !system.Locked; EditorUtility.SetDirty(system); ToolUtility.RepaintScenePalette(); }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh Tiles"))) .Enabled(!system.Locked) .Action(() => { TileSystemCommands.Command_Refresh(system); }); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Repair Tiles"))) .Enabled(!system.Locked) .Action(() => { TileSystemCommands.Command_Repair(system); }); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear Tiles"))) .Enabled(!system.Locked) .Action(() => { TileSystemCommands.Command_Clear(system); }); //contextMenu.AddSeparator(); //contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh Plops"))) // .Enabled(!system.Locked) // .Action(() => { // TileSystemCommands.Command_RefreshPlops(system); // }); //contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear Plops"))) // .Enabled(!system.Locked) // .Action(() => { // TileSystemCommands.Command_ClearPlops(system); // }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.ParticularText("Action", "Delete")) .Enabled(!system.Locked) .Action(() => { Undo.DestroyObjectImmediate(system.gameObject); }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Build Prefab"))) .Action(() => { TileSystemCommands.Command_BuildPrefab(system); }); return(contextMenu); }
private static void SpacingCoordinateField(Rect position, string label, SnapAxis axis) { var fieldStyle = RotorzEditorStyles.Instance.TextFieldRoundEdge; var textStyle = RotorzEditorStyles.Instance.TransparentTextField; var buttonStyle = RotorzEditorStyles.Instance.TextFieldRoundEdgeCancelButtonEmpty; int controlID = EditorGUIUtility.GetControlID(s_SpacingCoordinateFieldHint, FocusType.Passive); int realTextControlID = controlID + 1; // Display prefix label? if (!string.IsNullOrEmpty(label)) { if (Event.current.type == EventType.Repaint) { EditorStyles.label.Draw(new Rect(position.x, position.y, 12, position.height), label, false, false, false, false); } position.x += 12; position.width -= 12; } // Display popup field for alignment selection. Rect alignmentPosition = position; alignmentPosition.y -= 1; alignmentPosition.width = 33; alignmentPosition.height += 1; using (var content = AlignmentContent(label, axis)) { if (EditorInternalUtility.DropdownMenu(alignmentPosition, content, RotorzEditorStyles.Instance.FlatButton)) { DropDownAlignment(alignmentPosition, axis); } } position.x += alignmentPosition.width; position.width -= alignmentPosition.width; EditorGUI.BeginDisabledGroup(axis.Alignment == SnapAlignment.Free); { // Add small amount of padding after control. Rect textPosition = position; textPosition.width -= 3; if (axis.Alignment == SnapAlignment.Free) { // Draw background for text field. if (Event.current.type == EventType.Repaint) { position.width -= buttonStyle.fixedWidth; fieldStyle.Draw(position, false, false, false, false); // Draw end of text field control. position.x += position.width; position.width = buttonStyle.fixedWidth; position.height = buttonStyle.fixedHeight; buttonStyle.Draw(position, false, false, false, false); } } else { using (var fieldPrefixContent = ControlContent.Basic( labelText: axis.GridType == SnapGridType.Fraction ? "1/" : " ", image: RotorzEditorStyles.Skin.DownArrow )) { // Draw background for text field. if (Event.current.type == EventType.Repaint) { position.width -= buttonStyle.fixedWidth; GUI.contentColor = EditorGUIUtility.isProSkin ? Color.black : new Color(0f, 0f, 0f, 0.5f); fieldStyle.Draw(position, fieldPrefixContent, realTextControlID); GUI.contentColor = Color.white; // Draw end of text field control. position.x += position.width; position.width = buttonStyle.fixedWidth; position.height = buttonStyle.fixedHeight; buttonStyle.Draw(position, false, false, false, false); } float prefixWidth = fieldStyle.CalcSize(fieldPrefixContent).x; if (Event.current.GetTypeForControl(controlID) == EventType.MouseDown) { Rect popupPosition = textPosition; popupPosition.width = prefixWidth; if (popupPosition.Contains(Event.current.mousePosition)) { Event.current.Use(); DropDownSpacingCoordinate(popupPosition, axis); } } // Draw actual text field. textPosition.x += prefixWidth; textPosition.y += 1; textPosition.width -= prefixWidth; switch (axis.GridType) { default: case SnapGridType.Fraction: axis.SetFraction(EditorGUI.IntField(textPosition, axis.FractionDenominator, textStyle)); break; case SnapGridType.Custom: axis.SetCustomSize(EditorGUI.FloatField(textPosition, axis.CustomSize, textStyle)); break; } } } } EditorGUI.EndDisabledGroup(); }
private void DoTool(ToolBase tool, bool isMouseEvent, bool wasSceneActiveControl) { var tileSystem = target as TileSystem; this.toolEvent.MousePointerTileIndex = this.toolEvent.LastMousePointerTileIndex; if (!EditorApplication.isPlaying) { // Mark the current scene as being dirty. EditorSceneManager.MarkSceneDirty(tileSystem.gameObject.scene); } // Allow tool to manipulate event data if desired. tool.OnRefreshToolEvent(this.toolEvent, this); ToolUtility.ActiveTileIndex = this.toolEvent.MousePointerTileIndex; // Use currently selected tool! this.DoToolSceneGUI(tool); if (isMouseEvent) { // Tools cannot interact with locked tile systems! if (!tileSystem.Locked) { // Allow tool to respond to all mouse events. bool isSceneActiveControl = GUIUtility.hotControl == this.sceneControlID; if (wasSceneActiveControl || isSceneActiveControl) { tool.OnTool(this.toolEvent, this); switch (this.toolEvent.Type) { case EventType.MouseDown: case EventType.MouseDrag: if (isSceneActiveControl) { Event.current.Use(); } break; case EventType.MouseUp: if (wasSceneActiveControl) { tool.OnToolInactive(this.toolEvent, this); Event.current.Use(); } break; } } else { tool.OnToolInactive(this.toolEvent, this); } } // Force redraw in scene views. SceneView.RepaintAll(); // Force redraw in game views. EditorInternalUtility.RepaintAllGameViews(); } }
private void OnToolSelectorGUI() { GUILayout.Space(6); this.FilterRegisteredTools(); // Calculate metrics. int buttonColumns = Screen.width / 46; if (buttonColumns > this.filteredToolList.Count + 1) { buttonColumns = this.filteredToolList.Count + 1; } // Prepare style for tool button. if (s_ToolButtonStyle == null) { s_ToolButtonStyle = new GUIStyle(RotorzEditorStyles.Instance.ToolButton); } s_ToolButtonStyle.fixedWidth = Mathf.FloorToInt((float)Screen.width / (float)buttonColumns) - 3; // Display tool items. GUILayout.BeginHorizontal(); GUILayout.Space(4); using (var content = ControlContent.Basic( RotorzEditorStyles.Skin.MenuButton, TileLang.ParticularText("Action", "Main Menu") )) { if (EditorInternalUtility.DropdownMenu(content, s_ToolButtonStyle)) { EditorUtility.DisplayPopupMenu(this.menuPosition, "CONTEXT/_RTS_TOOLS_", new MenuCommand(this, 0)); } if (Event.current.type == EventType.Repaint) { this.menuPosition = GUILayoutUtility.GetLastRect(); } } int currentColumn = 1; for (int i = 0; i < this.filteredToolList.Count; ++i) { var tool = this.filteredToolList[i]; // Place tool button at start of new row upon overflowing width of palette. if (currentColumn++ >= buttonColumns) { currentColumn = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(4); } bool selected = ToolManager.Instance.CurrentTool == tool; // Get label for tool button and select icon based upon tool selection. var toolIconTexture = selected ? tool.IconActive : tool.IconNormal; using (var buttonContent = ControlContent.Basic(tool.Label, toolIconTexture)) { // Fallback to 'normal' icon if 'active' icon is not specified. if (selected && toolIconTexture == null) { buttonContent.LabelContent.image = tool.IconNormal; } if (this.ToolButton(buttonContent, selected)) { ToolManager.Instance.CurrentTool = !selected ? tool : null; } } } GUILayout.EndHorizontal(); ExtraEditorGUI.SeparatorLight(marginBottom: 0); this.scrolling = GUILayout.BeginScrollView(this.scrolling); if (ToolManager.Instance.CurrentTool != null) { GUILayout.Space(6); float restoreLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 130; { var tool = ToolManager.Instance.CurrentTool; tool.OnToolOptionsGUI(); if (tool.HasAdvancedToolOptionsGUI) { GUILayout.Space(-2); tool.ShowAdvancedOptionsGUI = GUILayout.Toggle(tool.ShowAdvancedOptionsGUI, TileLang.ParticularText("Section", "Advanced"), RotorzEditorStyles.Instance.FlatToggle); if (tool.ShowAdvancedOptionsGUI) { tool.OnAdvancedToolOptionsGUI(); } } } EditorGUIUtility.labelWidth = restoreLabelWidth; } else { GUILayout.Space(6 + 2); GUILayout.Label(TileLang.Text("No tool selected"), EditorStyles.miniLabel); } GUILayout.Space(3); GUILayout.FlexibleSpace(); GUILayout.EndScrollView(); }