Example #1
0
    // Create the visualizer GameObject
    public static void CreateVisualizer(GameObject selectedPrefab)
    {
        // Exit without creating, if no Prefab is selected in the palette
        if (selectedPrefab == null)
        {
            return;
        }

        // Create a new visualizer
        visualizerGameObject = GameObject.Instantiate(selectedPrefab);

        // Make visualizer transparent
        //visualizerGameObject.transform.MakeVisualizerTransparent();

        // Name it "MAST_Visualizer" incase it needs to be found later for deletion
        visualizerGameObject.name = "MAST_Visualizer";

        // If not selecting the Eraser
        if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4)
        {
            // If saved rotation is valid for the visualizer object, then apply the rotation to it
            if (IsSavedRotationValidForVisualizer())
            {
                visualizerGameObject.transform.rotation = MAST_Placement_Manipulate.GetCurrentRotation();
            }
        }

        // Set the visualizer and all it's children to be unselectable and not shown in the hierarchy
        visualizerGameObject.hideFlags = HideFlags.HideInHierarchy;
    }
Example #2
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);
 }
Example #3
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);
                }
            }
        }
    }
Example #4
0
// ---------------------------------------------------------------------------
    #region Toolbar GUI
// ---------------------------------------------------------------------------
    private void DisplayToolbarGUI()
    {
        // Calculate toolbar icon size
        toolBarIconSize = (position.height / 15.3f) * MAST_Settings.gui.toolbar.scale;

        GUILayout.Space(toolBarIconSize / 10);

        GUILayout.BeginVertical();

        GUILayout.Space(toolBarIconSize / 7.5f);

        // ----------------------------------------------
        // Grid Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Grid Up Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconGridUp, "Move Grid Up"),
                             "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
        {
            MAST_Grid_Manager.MoveGridUp();
        }

        // ------------------------------------
        // Toggle Grid Button
        // ------------------------------------
        EditorGUI.BeginChangeCheck();

        // OnScene Enable/Disable Randomizer Icon Button
        MAST_Grid_Manager.gridExists = GUILayout.Toggle(
            MAST_Grid_Manager.gridExists,
            new GUIContent(iconGridToggle, "Toggle Scene Grid"),
            "MAST Toggle", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize));

        // If randomizer enabled value changed, process the change
        if (EditorGUI.EndChangeCheck())
        {
            MAST_Grid_Manager.ChangeGridVisibility();
        }

        // ------------------------------------
        // Grid Down Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconGridDown, "Move Grid Down"),
                             "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
        {
            MAST_Grid_Manager.MoveGridDown();
        }

        GUILayout.EndVertical();

        GUILayout.Space(toolBarIconSize / 5);

        // ----------------------------------------------
        // Draw Tool Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Add Draw Tool Toggle Group
        // ------------------------------------
        EditorGUI.BeginChangeCheck();

        // Create drawtools SelectionGrid
        int newSelectedDrawToolIndex = GUILayout.SelectionGrid(
            MAST_Settings.gui.toolbar.selectedDrawToolIndex,
            guiContentDrawTool, 1, "MAST Toggle",
            GUILayout.Width(toolBarIconSize),
            GUILayout.Height(toolBarIconSize * 5));

        // If the draw tool was changed
        if (EditorGUI.EndChangeCheck())
        {
            // If the draw tool was clicked again, deselect it
            if (newSelectedDrawToolIndex == MAST_Settings.gui.toolbar.selectedDrawToolIndex)
            {
                MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;

                MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);

                drawing  = false;
                painting = false;
                erasing  = false;
            }

            // If a different draw tool was clicked, change to it
            else
            {
                MAST_Settings.gui.toolbar.selectedDrawToolIndex = newSelectedDrawToolIndex;

                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 1)
                {
                    drawing = false;
                }
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 2)
                {
                    painting = false;
                }
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4)
                {
                    erasing = false;
                }

                switch (MAST_Settings.gui.toolbar.selectedDrawToolIndex)
                {
                // Draw Single Tool selected
                case 0:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawSingle);
                    break;

                // Draw Continuous Tool selected
                case 1:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawContinuous);
                    break;

                // Flood Fill Tool selected
                case 2:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.PaintArea);
                    break;

                // Randomizer Tool selected
                case 3:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Randomize);
                    SceneView.RepaintAll();
                    break;

                // Eraser Tool selected
                case 4:
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.Erase);
                    SceneView.RepaintAll();
                    break;
                }
            }
        }

        GUILayout.EndVertical();

        GUILayout.Space(toolBarIconSize / 5);

        // ----------------------------------------------
        // Manipulate Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Rotate Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconRotate, "Rotate Prefab/Selection"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            MAST_Placement_Manipulate.RotateObject();
        }

        // OnScene Change Rotate Axis Icon Button
        switch (MAST_Placement_Manipulate.GetCurrentRotateAxis())
        {
        case MAST_Placement_Manipulate.Axis.X:
            if (GUILayout.Button(new GUIContent(iconAxisX, "Change Rotate Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleRotateAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Y:
            if (GUILayout.Button(new GUIContent(iconAxisY, "Change Rotate Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleRotateAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Z:
            if (GUILayout.Button(new GUIContent(iconAxisZ, "Change Rotate Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleRotateAxis();
            }
            break;
        }

        GUILayout.Space(toolBarIconSize / 10);

        // ------------------------------------
        // Flip Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconFlip, "Flip Prefab/Selection"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            MAST_Placement_Manipulate.FlipObject();
        }

        // OnScene Change Flip Axis Icon Button
        switch (MAST_Placement_Manipulate.GetCurrentFlipAxis())
        {
        case MAST_Placement_Manipulate.Axis.X:
            if (GUILayout.Button(new GUIContent(iconAxisX, "Change Flip Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleFlipAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Y:
            if (GUILayout.Button(new GUIContent(iconAxisY, "Change Flip Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleFlipAxis();
            }
            break;

        case MAST_Placement_Manipulate.Axis.Z:
            if (GUILayout.Button(new GUIContent(iconAxisZ, "Change Flip Axis"),
                                 "MAST Half Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize / 2)))
            {
                MAST_Placement_Manipulate.ToggleFlipAxis();
            }
            break;
        }

        GUILayout.EndVertical();

        GUILayout.Space(toolBarIconSize / 5);

        // ----------------------------------------------
        // Misc Section
        // ----------------------------------------------
        GUILayout.BeginVertical("MAST Toolbar BG Inset");

        // ------------------------------------
        // Load Palette Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconLoadFromFolder, "Load prefabs from a project folder"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            // Process prefabs for palette and save chosen path for future use
            string chosenPath =
                MAST_Palette.LoadPrefabs(MAST_Interface_Data_Manager.state.lastPrefabPath);

            // If a folder was chosen "Cancel was not clicked"
            if (chosenPath != "")
            {
                // Save the path the user chose and all palette items
                MAST_Interface_Data_Manager.state.lastPrefabPath = chosenPath;
                MAST_Interface_Data_Manager.Save_Palette_Items(true);
                MAST_Interface_Data_Manager.Save_Changes_To_Disk();
            }
        }

        // ------------------------------------
        // Open Tools Window Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconTools, "Tools"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            // If Tools window is closed, show and initialize it
            if (Tools == null)
            {
                Tools = (MAST_Tools_Window)EditorWindow.GetWindow(
                    typeof(MAST_Tools_Window),
                    true, "MAST Tools");

                Tools.minSize = Tools.maxSize = new Vector2(330, 300);
            }

            // If Tools window is open, close it
            else
            {
                EditorWindow.GetWindow(typeof(MAST_Tools_Window)).Close();
            }
        }

        // ------------------------------------
        // Open Settings Window Button
        // ------------------------------------
        if (GUILayout.Button(new GUIContent(iconSettings, "Settings"),
                             "MAST Button", GUILayout.Width(toolBarIconSize), GUILayout.Height(toolBarIconSize)))
        {
            // If Settings window is closed, show and initialize it
            if (Settings == null)
            {
                Settings = (MAST_Settings_Window)EditorWindow.GetWindow(
                    typeof(MAST_Settings_Window),
                    true, "MAST Settings");

                Settings.minSize = Settings.maxSize = new Vector2(330, 300);
                Settings.Initialize();
            }

            // If Settings window is open, close it
            else
            {
                EditorWindow.GetWindow(typeof(MAST_Settings_Window)).Close();
            }
        }

        GUILayout.EndVertical();

        GUILayout.EndVertical();
    }
Example #5
0
    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);
    }