コード例 #1
0
    // 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;
        }
    }
コード例 #2
0
    // 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();
    }
    // Check if a GameObject already exists here and if neither can be placed inside others
    private static bool GameObjectAlreadyHere()
    {
        // Get array containing all Colliders within 1.5f square box at placement position
        Collider[] colliders =
            Physics.OverlapBox(
                MAST_Placement_Visualizer.GetGameObject().transform.position,
                new Vector3(0.75f, 0.75f, 0.75f));

        // Loop through each GameObject inside or colliding with this OverlapBox
        foreach (Collider collider in colliders)
        {
            // If the nearby GameObject has a parent
            if (collider.gameObject.transform.parent != null)
            {
                // Get Parent GameObject for the GameObject containing this Collider
                GameObject nearObject = collider.gameObject.transform.parent.gameObject;

                // If near GameObject is not the visualizer itself
                if (nearObject.name != "MAST_Visualizer")
                {
                    // If the placed GameObject shares the same Position as the near GameObject
                    if (nearObject.transform.position ==
                        MAST_Placement_Visualizer.GetGameObject().transform.position)
                    {
                        //TODO:  Add rotation check as well

                        // Get the MAST Component script of the near GameObject
                        MAST_Prefab_Component nearComponent = nearObject.GetComponent <MAST_Prefab_Component>();

                        // If neither the GameObject nor placed GameObject can be placed inside others
                        if (!MAST_Placement_Helper.GetPlaceInsideOthers() && !nearComponent.placeInsideOthers)
                        {
                            // Return true "Not safe to place"
                            return(true);
                        }
                    }
                }
            }
        }
        // Return false "Safe to place"
        return(false);
    }
コード例 #4
0
    // Rotate the visualizer or whatever object is selected
    public static GameObject RotateObject()
    {
        GameObject gameObject = GetObjectToManipulate(MAST_Placement_Visualizer.GetGameObject());

        if (gameObject != null)
        {
            // Make this an Undo point, just before rotating the existing object
            if (allowUndoRegistering)
            {
                Undo.RegisterCompleteObjectUndo(gameObject.transform, "Rotated GameObject");
                allowUndoRegistering = false;
            }


            // TODO:  Add code to see if local space rotation allows this rotation
            //        This is different from world space


            // OnScene Change Target Axis Icon Button
            switch (rotateAxis)
            {
            case Axis.X:
                gameObject.transform.Rotate(MAST_Placement_Helper.GetRotationFactor().x, 0f, 0f, Space.World);
                break;

            case Axis.Y:
                gameObject.transform.Rotate(0f, MAST_Placement_Helper.GetRotationFactor().y, 0f, Space.World);
                break;

            case Axis.Z:
                gameObject.transform.Rotate(0f, 0f, MAST_Placement_Helper.GetRotationFactor().z, Space.World);
                break;
            }

            // Remember this rotation for future prefab placement
            currentRotation = gameObject.transform.rotation;
        }

        // Return rotated GameObject
        return(gameObject);
    }
コード例 #5
0
    // 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);
                }
            }
        }
    }
コード例 #6
0
    // -----------------------------------------------------------------------
    // Generate new random values for placement
    // -----------------------------------------------------------------------
    public static void GenerateNewRandomSeed()
    {
        // ---------------------
        // Replace Prefab
        // ---------------------
        if (MAST_Placement_Helper.Randomizer.GetReplaceable())
        {
            GetRandomPrefabInCategory(MAST_Placement_Helper.GetCategoryID());
        }

        // ---------------------
        // Randomize Position
        // ---------------------

        // Create X position
        position.x =
            Random.Range(MAST_Placement_Helper.Randomizer.Position.GetMin().x,
                         MAST_Placement_Helper.Randomizer.Position.GetMax().x);

        // Create Y position
        position.y =
            Random.Range(MAST_Placement_Helper.Randomizer.Position.GetMin().y,
                         MAST_Placement_Helper.Randomizer.Position.GetMax().y);

        // Create Z position
        position.z =
            Random.Range(MAST_Placement_Helper.Randomizer.Position.GetMin().z,
                         MAST_Placement_Helper.Randomizer.Position.GetMax().z);

        // ---------------------
        // Randomize Rotation
        // ---------------------

        // Create X rotation
        if (MAST_Placement_Helper.Randomizer.Rotation.GetAngle().x == 0f)
        {
            rotation.x = 0f;
        }
        else
        {
            rotation.x = Mathf.Floor(Random.Range(0f, 360f)
                                     / MAST_Placement_Helper.Randomizer.Rotation.GetAngle().x)
                         * MAST_Placement_Helper.Randomizer.Rotation.GetAngle().x;
        }

        // Create Y rotation
        if (MAST_Placement_Helper.Randomizer.Rotation.GetAngle().y == 0f)
        {
            rotation.y = 0f;
        }
        else
        {
            rotation.y = Mathf.Floor(Random.Range(0f, 360f)
                                     / MAST_Placement_Helper.Randomizer.Rotation.GetAngle().y)
                         * MAST_Placement_Helper.Randomizer.Rotation.GetAngle().y;
        }

        // Create Z rotation
        if (MAST_Placement_Helper.Randomizer.Rotation.GetAngle().z == 0f)
        {
            rotation.z = 0f;
        }
        else
        {
            rotation.z = Mathf.Floor(Random.Range(0f, 360f)
                                     / MAST_Placement_Helper.Randomizer.Rotation.GetAngle().z)
                         * MAST_Placement_Helper.Randomizer.Rotation.GetAngle().z;
        }

        // ---------------------
        // Randomize Scale
        // ---------------------

        // Create X scale
        scale.x =
            Random.Range(MAST_Placement_Helper.Randomizer.Scale.GetMin().x,
                         MAST_Placement_Helper.Randomizer.Scale.GetMax().x);

        // XYZ lock on, set Y scale to match X scale
        if (MAST_Placement_Helper.Randomizer.Scale.GetLock() == MAST_Placement_ScriptableObject.AxisLock.XYZ)
        {
            scale.y = scale.x;
        }

        // XYZ lock off, create Y scale
        else
        {
            scale.y =
                Random.Range(MAST_Placement_Helper.Randomizer.Scale.GetMin().y,
                             MAST_Placement_Helper.Randomizer.Scale.GetMax().y);
        }

        // XYZ or XZ lock on, set Z scale to match X scale
        if (MAST_Placement_Helper.Randomizer.Scale.GetLock() != MAST_Placement_ScriptableObject.AxisLock.NONE)
        {
            scale.z = scale.x;
        }

        // XYZ and XZ locks off, create Z scale
        else
        {
            scale.z =
                Random.Range(MAST_Placement_Helper.Randomizer.Scale.GetMin().z,
                             MAST_Placement_Helper.Randomizer.Scale.GetMax().z);
        }
    }
コード例 #7
0
 // See if new selected Prefab will allow the saved rotation
 private static bool IsSavedRotationValidForVisualizer()
 {
     // If there is a saved rotation
     if (MAST_Placement_Manipulate.GetCurrentRotation() != null)
     {
         // If the current saved rotation is allowed by the prefab
         //   (If allowed rotation divides evenly into current rotation)
         //       or (Both allowed and current rotations are set to 0)
         if (((int)(MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.x % MAST_Placement_Helper.GetRotationFactor().x) == 0) ||
             (int)MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.x == 0 && (int)MAST_Placement_Helper.GetRotationFactor().x == 0)
         {
             if (((int)(MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.y % MAST_Placement_Helper.GetRotationFactor().y) == 0) ||
                 (int)MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.y == 0 && (int)MAST_Placement_Helper.GetRotationFactor().y == 0)
             {
                 if (((int)(MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.z % MAST_Placement_Helper.GetRotationFactor().z) == 0) ||
                     (int)MAST_Placement_Manipulate.GetCurrentRotation().eulerAngles.z == 0 && (int)MAST_Placement_Helper.GetRotationFactor().z == 0)
                 {
                     // Return true, since saved rotation is allowed
                     return(true);
                 }
             }
         }
     }
     // Return false, since saved rotation is not allowed
     return(false);
 }