public static void checkKeyboardShortcuts(Event keyEvent) { YuME_mapEditor.eraseToolOverride = false; YuME_mapEditor.pickToolOverride = false; if (keyEvent.shift && !keyEvent.control && !keyEvent.alt) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.eraseToolOverride = true; } } else if (keyEvent.control && !keyEvent.alt && !keyEvent.shift) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.pickToolOverride = true; } } if (keyEvent.type == EventType.KeyDown) { switch (keyEvent.keyCode) { case KeyCode.Escape: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.defaultTools; YuME_mapEditor.currentBrushType = YuME_mapEditor.brushTypes.standardBrush; break; case KeyCode.Equals: Event.current.Use(); YuME_mapEditor.gridHeight += YuME_mapEditor.globalScale; break; case KeyCode.Minus: Event.current.Use(); YuME_mapEditor.gridHeight -= YuME_mapEditor.globalScale; break; case KeyCode.LeftBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.LeftArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.DownArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y -= 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.UpArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y += 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.Return: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); YuME_mapEditor.setTileBrush(0); YuME_mapEditor.brushSize = Vector3.one; YuME_mapEditor.selectedTiles.Clear(); SceneView.RepaintAll(); } else { Event.current.Use(); YuME_mapEditor.selectedTiles.Clear(); SceneView.RepaintAll(); } break; case KeyCode.Z: Event.current.Use(); YuME_mapEditor.tileRotation -= 90f; break; case KeyCode.X: Event.current.Use(); YuME_mapEditor.tileRotation += 90f; break; case KeyCode.E: if (keyEvent.shift) { YuME_mapEditor.gridHeight -= YuME_mapEditor.globalScale * YuME_mapEditor.editorPreferences.gridLayerHeightScaler; } else { YuME_mapEditor.gridHeight += YuME_mapEditor.globalScale * YuME_mapEditor.editorPreferences.gridLayerHeightScaler; } break; case KeyCode.I: Event.current.Use(); YuME_tileFunctions.isolateTilesToggle(); break; case KeyCode.C: Event.current.Use(); YuME_tileFunctions.flipVertical(); break; case KeyCode.V: Event.current.Use(); YuME_tileFunctions.flipHorizontal(); break; case KeyCode.B: Event.current.Use(); YuME_mapEditor.tileRotationX -= 90f; break; case KeyCode.N: Event.current.Use(); YuME_mapEditor.tileRotationX += 90f; break; case KeyCode.Space: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.selectTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.defaultTools) { Event.current.Use(); YuME_tileFunctions.selectAllTiles(); } break; case KeyCode.R: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { Event.current.Use(); YuME_mapEditor.randomRotationMode = !YuME_mapEditor.randomRotationMode; } break; } if (!YuME_mapEditor.editorPreferences.useAlternativeKeyShortcuts) { switch (keyEvent.keyCode) { case KeyCode.A: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; break; case KeyCode.S: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.pickTool; break; case KeyCode.D: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.eraseTool; break; } } else { switch (keyEvent.keyCode) { case KeyCode.G: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; break; case KeyCode.H: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.pickTool; break; case KeyCode.J: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.eraseTool; break; } } } }
// ---------------------------------------------------------------------------------------------------- // ----- Draw Scene Tools // ---------------------------------------------------------------------------------------------------- static void OnSceneGUI(SceneView sceneView) { if (toolEnabled) { // ---------------------------------------------------------------------------------------------------- // ----- Draw Scene Editor Tools // ---------------------------------------------------------------------------------------------------- if (selectedTool > 0 && toolEnabled) { controlId = GUIUtility.GetControlID(FocusType.Passive); updateSceneMousePosition(); checkTilePositionIsValid(sceneView.position); YuME_sceneGizmoFunctions.drawBrushGizmo(); } // ---------------------------------------------------------------------------------------------------- // ----- Draw Editor Tool Bar // ---------------------------------------------------------------------------------------------------- YuME_editorSceneUI.drawToolUI(sceneView); // ---------------------------------------------------------------------------------------------------- // ----- Check Keyboard and Mouse Shortcuts // ---------------------------------------------------------------------------------------------------- YuME_keyboardShortcuts.checkKeyboardShortcuts(Event.current); YuME_mouseShorcuts.checkMouseShortcuts(Event.current); foreach (GameObject selected in selectedTiles) { if (selected != null) { YuME_sceneGizmoFunctions.drawSceneGizmoCube(selected.transform.position, Vector3.one, Color.green); } } // ---------------------------------------------------------------------------------------------------- // ----- Momenteray handling of the editor tool bar // ---------------------------------------------------------------------------------------------------- switch (selectedTool) { case toolIcons.defaultTools: YuME_brushFunctions.destroyBrushTile(); break; case toolIcons.brushTool: YuME_brushFunctions.createBrushTile(); selectedTiles.Clear(); break; case toolIcons.pickTool: YuME_brushFunctions.destroyBrushTile(); selectedTiles.Clear(); break; case toolIcons.eraseTool: YuME_brushFunctions.destroyBrushTile(); selectedTiles.Clear(); break; case toolIcons.selectTool: YuME_brushFunctions.destroyBrushTile(); break; case toolIcons.copyTool: YuME_customBrushFunctions.createCopyBrush(false); selectedTool = toolIcons.brushTool; break; case toolIcons.moveTool: YuME_customBrushFunctions.createCopyBrush(true); selectedTool = toolIcons.brushTool; break; case toolIcons.trashTool: YuME_tileFunctions.trashTiles(); selectedTool = previousSelectedTool; break; case toolIcons.customBrushTool: YuME_customBrushFunctions.createCustomBrush(); selectedTool = previousSelectedTool; break; case toolIcons.showGizmos: showGizmos = !showGizmos; YuTools_Utils.disableTileGizmo(showGizmos); selectedTool = previousSelectedTool; break; case toolIcons.gridUpTool: if (Event.current.alt) { gridHeight += 0.25f; } else { gridHeight++; } selectedTool = previousSelectedTool; break; case toolIcons.gridDownTool: if (Event.current.alt) { gridHeight -= 0.25f; } else { gridHeight--; } selectedTool = previousSelectedTool; break; case toolIcons.rotateTool: tileRotation += 90f; selectedTool = previousSelectedTool; break; case toolIcons.flipHorizontalTool: YuME_tileFunctions.flipHorizontal(); selectedTool = previousSelectedTool; break; case toolIcons.flipVerticalTool: YuME_tileFunctions.flipVertical(); selectedTool = previousSelectedTool; break; case toolIcons.isolateTool: YuME_tileFunctions.isolateTilesToggle(); selectedTool = previousSelectedTool; break; case toolIcons.isolateLayerTool: YuME_tileFunctions.isolateLayerToggle(); selectedTool = previousSelectedTool; break; case toolIcons.layerUp: currentLayer++; selectedTool = previousSelectedTool; break; case toolIcons.layerDown: currentLayer--; selectedTool = previousSelectedTool; break; } // ---------------------------------------------------------------------------------------------------- // ----- Check Scene View Inputs for Drawing, Picking etc. // ---------------------------------------------------------------------------------------------------- if (selectedTool > toolIcons.defaultTools) { if ((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && Event.current.button == 0 && Event.current.alt == false && Event.current.shift == false && Event.current.control == false && allowTileRedraw) { switch (selectedTool) { case toolIcons.brushTool: switch (currentBrushType) { case brushTypes.standardBrush: addTiles(); break; case brushTypes.customBrush: YuME_customBrushFunctions.pasteCustomBrush(tilePosition); break; case brushTypes.copyBrush: YuME_customBrushFunctions.pasteCopyBrush(tilePosition); break; } break; case toolIcons.pickTool: YuME_tileFunctions.pickTile(tilePosition); break; case toolIcons.eraseTool: eraseTiles(); break; case toolIcons.selectTool: YuME_tileFunctions.selectTile(tilePosition); break; } allowTileRedraw = false; } else if ((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && Event.current.button == 0 && Event.current.alt == false && Event.current.shift == true && Event.current.control == false && allowTileRedraw) { switch (selectedTool) { case toolIcons.brushTool: eraseTiles(); break; } allowTileRedraw = false; } else if ((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) && Event.current.button == 0 && Event.current.alt == false && Event.current.shift == false && Event.current.control == true && allowTileRedraw) { switch (selectedTool) { case toolIcons.brushTool: YuME_tileFunctions.pickTile(tilePosition); break; case toolIcons.selectTool: YuME_tileFunctions.deSelectTile(tilePosition); break; } allowTileRedraw = false; } HandleUtility.AddDefaultControl(controlId); } if (showGizmos) { if (selectedTiles.Count > 0) { foreach (GameObject tile in selectedTiles) { YuME_sceneGizmoFunctions.handleInfo data; data.tileName = tile.name; data.layer = tile.transform.parent.name; data.grid = tile.transform.position.y; YuME_sceneGizmoFunctions.drawTileInfo(tile.transform.position, data); } } } // ---------------------------------------------------------------------------------------------------- // ----- Scene Housekeeping // ---------------------------------------------------------------------------------------------------- YuME_brushFunctions.updateBrushPosition(); repaintSceneView(); previousSelectedTool = selectedTool; } }
public static void checkKeyboardShortcuts(Event keyEvent) { YuME_mapEditor.eraseToolOverride = false; YuME_mapEditor.pickToolOverride = false; if (keyEvent.shift && !keyEvent.control && !keyEvent.alt) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.eraseToolOverride = true; } } else if (keyEvent.control && !keyEvent.alt && !keyEvent.shift) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.pickToolOverride = true; } } if (keyEvent.type == EventType.keyDown) { switch (keyEvent.keyCode) { case KeyCode.Escape: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.defaultTools; break; case KeyCode.A: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; break; case KeyCode.S: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.pickTool; break; case KeyCode.D: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.eraseTool; break; case KeyCode.Equals: Event.current.Use(); YuME_mapEditor.gridHeight++; break; case KeyCode.Minus: Event.current.Use(); YuME_mapEditor.gridHeight--; break; case KeyCode.LeftBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.LeftArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.DownArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y -= 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.UpArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y += 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.Return: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); YuME_mapEditor.setTileBrush(0); YuME_mapEditor.brushSize = Vector3.one; SceneView.RepaintAll(); } break; case KeyCode.Z: Event.current.Use(); YuME_mapEditor.tileRotation -= 90f; break; case KeyCode.X: Event.current.Use(); YuME_mapEditor.tileRotation += 90f; break; case KeyCode.I: Event.current.Use(); YuME_tileFunctions.isolateTilesToggle(); break; case KeyCode.C: Event.current.Use(); YuME_tileFunctions.flipVertical(); break; case KeyCode.V: Event.current.Use(); YuME_tileFunctions.flipHorizontal(); break; case KeyCode.Space: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.selectTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.defaultTools) { Event.current.Use(); YuME_tileFunctions.selectAllTiles(); } break; } } }