// 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();
    }
Exemplo n.º 2
0
    // Handle object placement
    private void ObjectPlacement()
    {
        // Get mouse events for object placement when in the Scene View
        Event currentEvent = Event.current;

        // Change position of visualizer
        MAST_Placement_Visualizer.UpdateVisualizerPosition();

        switch (MAST_Settings.gui.toolbar.selectedDrawToolIndex)
        {
        // Draw single tool
        case 0:
        // Randomizer tool
        case 3:
            // If left mouse button was clicked
            if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
            {
                // Keep mouseclick from selecting other objects
                GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
                Event.current.Use();

                // Place selected prefab on grid
                MAST_Placement_Place.PlacePrefabInScene();
            }
            break;

        // Draw continuous tool
        case 1:
            // If not already drawing and the left mouse button pressed
            if (!drawing)
            {
                if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
                {
                    // Start drawing
                    drawing = true;

                    // Keep mouseclick from selecting other objects
                    GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
                    Event.current.Use();
                }
            }

            // If drawing and left mouse button not released
            if (drawing)
            {
                // Place selected prefab on grid
                MAST_Placement_Place.PlacePrefabInScene();

                // If left mouse button released
                if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
                {
                    drawing = false;
                }
            }
            break;

        // Paint area tool
        case 2:
            // If not already painting and the left mouse button pressed
            if (!painting)
            {
                if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
                {
                    // Start drawing
                    painting = true;

                    // Start paint area at current mouse location
                    MAST_Placement_PaintArea.StartPaintArea();

                    // Keep mouseclick from selecting other objects
                    GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
                    Event.current.Use();
                }
            }

            // If drawing and left mouse button not released
            if (painting)
            {
                // Update the paint area as the mouse moves
                MAST_Placement_PaintArea.UpdatePaintArea();

                // If left mouse button released
                if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
                {
                    MAST_Placement_PaintArea.CompletePaintArea();
                    painting = false;
                }
            }
            break;

        // Erase tool
        case 4:
            // If not already erasing and the left mouse button pressed
            if (!erasing)
            {
                if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
                {
                    // Start drawing
                    erasing = true;

                    // Keep mouseclick from selecting other objects
                    GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
                    Event.current.Use();
                }
            }

            // If erasing and left mouse button not released
            if (erasing)
            {
                // Place selected prefab on grid
                MAST_Placement_Interface.ErasePrefab();

                // If left mouse button released
                if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
                {
                    erasing = false;
                }
            }
            break;
        }
    }