// Update paint area public static void UpdatePaintArea() { // If painting area if (paintingArea) { // Get current mouse position on grid Vector3 paintAreaEnd = MAST_Placement_Helper.GetPositionOnGridClosestToMousePointer(); paintAreaEnd.y = MAST_Settings.gui.grid.gridHeight * MAST_Settings.gui.grid.xzUnitSize + MAST_Const.grid.yOffsetToAvoidTearing; // Make sure paint area start is at the current grid height, incase the grid was moved paintAreaStart.y = MAST_Settings.gui.grid.gridHeight * MAST_Settings.gui.grid.xzUnitSize + MAST_Const.grid.yOffsetToAvoidTearing; // Get dimensions of paint area Vector3 scale = new Vector3( Mathf.Abs((paintAreaStart.x - paintAreaEnd.x) / 10f) + 0.1f, 1, Mathf.Abs((paintAreaStart.z - paintAreaEnd.z) / 10f) + 0.1f); // Update paint area visualizer position to be between the start and end points paintAreaVisualizer.transform.position = (paintAreaStart + paintAreaEnd) / 2; // Update paint area visualizer x and z scale paintAreaVisualizer.transform.localScale = scale; } }
// Complete paint area public static void CompletePaintArea() { // Get current mouse position on grid Vector3 paintAreaEnd = MAST_Placement_Helper.GetPositionOnGridClosestToMousePointer(); paintAreaEnd.y = MAST_Settings.gui.grid.gridHeight * MAST_Settings.gui.grid.xzUnitSize + MAST_Const.grid.yOffsetToAvoidTearing; // If selected Prefab can be scaled if (MAST_Placement_Helper.GetScalable()) { // Place the prefab GameObject placedPrefab = MAST_Placement_Place.PlacePrefabInScene(); // Move prefab centerpoint between both paint areas placedPrefab.transform.position = (paintAreaStart + paintAreaEnd) / 2; // Scale prefab X and Z to match paint area Vector3 scale = new Vector3( Mathf.Abs(paintAreaStart.x - paintAreaEnd.x) + 1f, 1, Mathf.Abs(paintAreaStart.z - paintAreaEnd.z) + 1f); placedPrefab.transform.localScale = scale; } // If selected Prefab cannot be scaled else { // Get base of rows and columns "lowest value" float xBase = paintAreaStart.x < paintAreaEnd.x ? paintAreaStart.x : paintAreaEnd.x; float zBase = paintAreaStart.z < paintAreaEnd.z ? paintAreaStart.z : paintAreaEnd.z; // Get count of rows and columns in paint area int xCount = (int)(Mathf.Abs(paintAreaStart.x - paintAreaEnd.x) / MAST_Settings.gui.grid.xzUnitSize); int zCount = (int)(Mathf.Abs(paintAreaStart.z - paintAreaEnd.z) / MAST_Settings.gui.grid.xzUnitSize); // Loop through each grid space in the area for (int x = 0; x <= xCount; x++) { for (int z = 0; z <= zCount; z++) { // Set visualizer position MAST_Placement_Visualizer.GetGameObject().transform.position = new Vector3(xBase + (x * MAST_Settings.gui.grid.xzUnitSize), MAST_Settings.gui.grid.gridHeight * MAST_Settings.gui.grid.xzUnitSize, zBase + (z * MAST_Settings.gui.grid.xzUnitSize)); // Add Prefab to scene MAST_Placement_Place.PlacePrefabInScene(); } } } // Delete painting area DeletePaintArea(); }
// 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); } } } }