public static GameObject PlacePrefabInScene() { // Make sure target parent is referenced ReferenceTargetParent(); if (MAST_Placement_Visualizer.visualizerOnGrid && MAST_Placement_Visualizer.GetGameObject() != null && MAST_Placement_Visualizer.GetGameObject() != null) { // If drawing continuous and an object was just drawn here, exit without drawing if (MAST_Placement_Interface.placementMode == MAST_Placement_Interface.PlacementMode.DrawContinuous) { if (lastPosition == MAST_Placement_Visualizer.GetGameObject().transform.position) { return(null); } } // If GameObject already exists here, exit without placing the block if (GameObjectAlreadyHere()) { return(null); } // Instantiate the prefab GameObject newPrefab = (GameObject)PrefabUtility.InstantiatePrefab(MAST_Palette.GetSelectedPrefab()); // Correct GameObject transform and name "to remove (clone)" newPrefab.transform.rotation = MAST_Placement_Visualizer.GetGameObject().transform.rotation; newPrefab.transform.localScale = MAST_Placement_Visualizer.GetGameObject().transform.localScale; newPrefab.transform.position = MAST_Placement_Visualizer.GetGameObject().transform.position; newPrefab.name = MAST_Palette.GetSelectedPrefab().name; // Make new prefab child of the target parent newPrefab.transform.parent = targetParent.transform; // Add MAST script to GameObject if it was missing it if (!newPrefab.GetComponent <MAST_Prefab_Component>()) { newPrefab.AddComponent <MAST_Prefab_Component>(); } // Randomize the seed after placement if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 3) { MAST_Placement_Randomizer.GenerateNewRandomSeed(); } // Save this GameObject position lastPosition = MAST_Placement_Visualizer.GetGameObject().transform.position; // Make this an Undo point, just after placing the prefab Undo.RegisterCreatedObjectUndo(newPrefab, "Placed new Prefab"); // Return with newly created GameObject return(newPrefab); } return(null); }
// Moves the visualizer prefab to a position based on the current mouse position public static void UpdateVisualizerPosition() { // If a tool is selected if (MAST_Placement_Interface.placementMode != MAST_Placement_Interface.PlacementMode.None) { // If visualizer exists if (visualizerGameObject != null) { // Update visualizer position from pointer location on grid visualizerGameObject.transform.position = MAST_Placement_Helper.GetPositionOnGridClosestToMousePointer(); // If Eraser tool is not selected if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4) { // Apply position offset visualizerGameObject.transform.position += MAST_Placement_Helper.GetOffsetPosition(); // If Randomizer is selected if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 3) { // If Prefab in randomizable, apply Randomizer to transform if (MAST_Placement_Helper.Randomizer.GetRandomizable()) { visualizerGameObject = MAST_Placement_Randomizer.ApplyRandomizerToTransform( visualizerGameObject, MAST_Placement_Manipulate.GetCurrentRotation()); } } } // Set visualizer visibility based on if mouse over grid if (pointerInSceneview) { visualizerGameObject.SetActive(visualizerOnGrid); } } } }
public bool ProcessHotkeys() { // Set change made to false bool changeMade = false; // Get current event Event currentEvent = Event.current; // Get the control's ID int controlID = GUIUtility.GetControlID(FocusType.Passive); // If a key is pressed if (Event.current.GetTypeForControl(controlID) == EventType.KeyDown) { // Toggle grid visibility if (KeysPressed(currentEvent, MAST_Settings.hotkey.toggleGridKey, MAST_Settings.hotkey.toggleGridMod)) { MAST_Grid_Manager.gridExists = !MAST_Grid_Manager.gridExists; MAST_Grid_Manager.ChangeGridVisibility(); changeMade = true; } // Move grid up if (KeysPressed(currentEvent, MAST_Settings.hotkey.moveGridUpKey, MAST_Settings.hotkey.moveGridUpMod)) { MAST_Grid_Manager.MoveGridUp(); changeMade = true; } // Move grid down if (KeysPressed(currentEvent, MAST_Settings.hotkey.moveGridDownKey, MAST_Settings.hotkey.moveGridDownMod)) { MAST_Grid_Manager.MoveGridDown(); changeMade = true; } // Deselect prefab in palette or draw tool if (KeysPressed(currentEvent, MAST_Settings.hotkey.deselectPrefabKey, MAST_Settings.hotkey.deselectPrefabMod)) { // Deselect palette item and draw tool MAST_Palette.selectedItemIndex = -1; MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None); changeMade = true; } // Draw single if (KeysPressed(currentEvent, MAST_Settings.hotkey.drawSingleKey, MAST_Settings.hotkey.drawSingleMod)) { // If Draw Single isn't selected, select it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 0) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = 0; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawSingle); } else { // If Draw Single was selected, deselect it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 0) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None); } } changeMade = true; } // Draw Continuous if (KeysPressed(currentEvent, MAST_Settings.hotkey.drawContinuousKey, MAST_Settings.hotkey.drawContinuousMod)) { // If Draw Continuous isn't selected, select it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 1) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = 1; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawContinuous); } else { // If Draw continuous was selected, deselect it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 1) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None); } } changeMade = true; } // Paint square if (KeysPressed(currentEvent, MAST_Settings.hotkey.paintSquareKey, MAST_Settings.hotkey.paintSquareMod)) { // If Paint Square isn't selected, select it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 2) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = 2; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.PaintArea); } else { // If Paint Square was selected, deselect it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 2) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None); } } changeMade = true; } // Toggle randomizer if (KeysPressed(currentEvent, MAST_Settings.hotkey.randomizerKey, MAST_Settings.hotkey.randomizerMod)) { // If Randomizer isn't selected, select it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 3) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = 3; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Randomize); } else { // If Randomizer was selected, deselect it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 3) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None); } } changeMade = true; } // Toggle erase if (KeysPressed(currentEvent, MAST_Settings.hotkey.eraseKey, MAST_Settings.hotkey.eraseMod)) { // If Erase isn't selected, select it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = 4; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Erase); } else { // If Erase was selected, deselect it if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == 4) { MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1; MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None); } } changeMade = true; } // New random seed if (KeysPressed(currentEvent, MAST_Settings.hotkey.newRandomSeedKey, MAST_Settings.hotkey.newRandomSeedMod)) { MAST_Placement_Randomizer.GenerateNewRandomSeed(); changeMade = true; } // Rotate prefab if (KeysPressed(currentEvent, MAST_Settings.hotkey.rotatePrefabKey, MAST_Settings.hotkey.rotatePrefabMod)) { MAST_Placement_Manipulate.RotateObject(); changeMade = true; } // Flip prefab if (KeysPressed(currentEvent, MAST_Settings.hotkey.flipPrefabKey, MAST_Settings.hotkey.flipPrefabMod)) { MAST_Placement_Manipulate.FlipObject(); changeMade = true; } } return(changeMade); }
// --------------------------------------------------------------------------- #region Change Placement Mode // --------------------------------------------------------------------------- public static void ChangePlacementMode(PlacementMode newPlacementMode) { // Get new selected Draw Tool placementMode = newPlacementMode; // Remove any previous visualizer MAST_Placement_Visualizer.RemoveVisualizer(); // -------------------------------- // Create Visualizer // -------------------------------- // If changed tool to Nothing or Eraser if (placementMode == PlacementMode.None || placementMode == PlacementMode.Erase) { // Deselect any item in the palette MAST_Palette.selectedItemIndex = -1; // If changed tool to Eraser if (placementMode == PlacementMode.Erase) { // Create eraser visualizer ChangePrefabToEraser(); } // If changed tool to Nothing, remove the visualizer else { MAST_Placement_Visualizer.RemoveVisualizer(); } } // If changed tool to Draw Single, Draw Continuous, Paint Area, or Randomizer else { // If a palette item is selected if (MAST_Palette.selectedItemIndex != -1) { // Create visualizer from selected item in the palette ChangeSelectedPrefab(); // If changed tool to Randomizer if (placementMode == PlacementMode.Randomize) { // Make a new random seed MAST_Placement_Randomizer.GenerateNewRandomSeed(); } } } // If Draw Continuous nor Paint Area tools are selected if (placementMode != PlacementMode.DrawContinuous && placementMode != PlacementMode.PaintArea) { // Delete last saved position MAST_Placement_Place.lastPosition = Vector3.positiveInfinity; // Remove any paint area visualization MAST_Placement_PaintArea.DeletePaintArea(); } }