Ejemplo n.º 1
0
    private void EnterEditMode()
    {
        //Debug.Log("Interface - Enter Edit Mode");

        // Don't allow this method to run twice
        if (!inPlayMode)
        {
            return;
        }

        // Load interface data back from saved state
        MAST_Interface_Data_Manager.Load_Interface_State();
        MAST_Grid_Manager.ChangeGridVisibility();

        // Restore the interface saved state
        MAST_Interface_Data_Manager.Restore_Palette_Items();

        // Change placement mode back to what was saved
        MAST_Placement_Interface.ChangePlacementMode(
            (MAST_Placement_Interface.PlacementMode)MAST_Settings.gui.toolbar.selectedDrawToolIndex);

        // Repaint all views
        UnityEditorInternal.InternalEditorUtility.RepaintAllViews();

        inPlayMode = false;
    }
Ejemplo n.º 2
0
    // ---------------------------------------------------------------------------
    // Clean-up
    // ---------------------------------------------------------------------------
    private void CleanUpInterface()
    {
        //Debug.Log("Cleaning Up Interface");

        // Remove SceneView delegate
        #if UNITY_2019_1_OR_NEWER
        SceneView.duringSceneGui -= this.OnScene;
        #else
        SceneView.onSceneGUIDelegate -= this.OnScene;
        #endif

        // Delete placement grid
        MAST_Grid_Manager.DestroyGrid();

        // Deselect palette item and delete visualizer
        MAST_Palette.selectedItemIndex = -1;
        MAST_Placement_Visualizer.RemoveVisualizer();

        // Deselect draw tool and change placement mode to none
        MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
        MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);

        // Cancel any drawing or painting
        drawing  = false;
        painting = false;
        erasing  = false;
        MAST_Placement_PaintArea.DeletePaintArea();
    }
Ejemplo n.º 3
0
 // ---------------------------------------------------------------------------
 // Runs every frame
 // ---------------------------------------------------------------------------
 private void Update()
 {
     // If Settings window is open and changes to UI value ocurred,
     // update the grid and repaint all views incase needed
     if (Settings != null)
     {
         if (Settings.PreferencesChanged())
         {
             MAST_Grid_Manager.UpdateGridSettings();
             UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
         }
     }
 }
Ejemplo n.º 4
0
    // ---------------------------------------------------------------------------
    // Clean-up
    // ---------------------------------------------------------------------------
    private void CleanUpInterface()
    {
        //Debug.Log("Cleaning Up Interface");

        // Delete placement grid
        MAST_Grid_Manager.DestroyGrid();

        // Deselect palette item and delete visualizer
        MAST_Palette.selectedItemIndex = -1;
        MAST_Placement_Visualizer.RemoveVisualizer();

        // Deselect draw tool and change placement mode to none
        MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
        MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);

        // Cancel any drawing or painting
        drawing  = false;
        painting = false;
        erasing  = false;
        MAST_Placement_PaintArea.DeletePaintArea();
    }
Ejemplo n.º 5
0
    // ---------------------------------------------------------------------------
    // Save and Restore MAST Interface variables to keep state on play
    // ---------------------------------------------------------------------------
    private void ExitEditMode()
    {
        //Debug.Log("Interface - Exit Edit Mode");

        // Don't allow this method to run twice
        if (inPlayMode)
        {
            return;
        }

        // If the grid exists
        if (MAST_Grid_Manager.gridExists)
        {
            // Destroy the grid so it doesn't show while playing
            MAST_Grid_Manager.DestroyGrid();

            // Make sure the grid is restored after returning to editor
            MAST_Grid_Manager.gridExists = true;
        }

        inPlayMode  = true;
        isCleanedUp = false;
    }
Ejemplo n.º 6
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();
    }
Ejemplo n.º 7
0
    // ---------------------------------------------------------------------------
    // MAST Window is Enabled
    // ---------------------------------------------------------------------------
    private void OnEnable()
    {
        //Debug.Log("Interface - On Enable");

        // Initialize Preference Manager
        MAST_Settings.Initialize();

        // Initialize the MAST State Manager
        MAST_Interface_Data_Manager.Initialize();


        // Set up deletegates so that OnScene is called automatically
        #if UNITY_2019_1_OR_NEWER
        SceneView.duringSceneGui -= this.OnScene;
        SceneView.duringSceneGui += this.OnScene;
        #else
        SceneView.onSceneGUIDelegate -= this.OnScene;
        SceneView.onSceneGUIDelegate += this.OnScene;
        #endif

        // Set up deletegates for exiting editor mode and returning to editor mode from play mode
        MAST_PlayModeStateListener.onExitEditMode  -= this.ExitEditMode;
        MAST_PlayModeStateListener.onExitEditMode  += this.ExitEditMode;
        MAST_PlayModeStateListener.onEnterEditMode -= this.EnterEditMode;
        MAST_PlayModeStateListener.onEnterEditMode += this.EnterEditMode;

        // Set scene to be updated by mousemovement
        wantsMouseMove = true;

        // If Enabled in Editor Mode
        if (!inPlayMode)
        {
            // Load icon textures
            if (iconGridToggle == null)
            {
                LoadImages();
            }

            // Load custom gui styles
            if (guiSkin == null)
            {
                guiSkin = MAST_Asset_Loader.GetGUISkin();
            }

            // Load interface data back from saved state
            MAST_Interface_Data_Manager.Load_Interface_State();

            // Create a new grid if needed
            if (MAST_Interface_Data_Manager.state.gridExists)
            {
                MAST_Grid_Manager.gridExists = true;
                MAST_Grid_Manager.ChangeGridVisibility();
            }

            // Change placement mode back to what was saved
            MAST_Placement_Interface.ChangePlacementMode(
                (MAST_Placement_Interface.PlacementMode)MAST_Settings.gui.toolbar.selectedDrawToolIndex);

            // TODO:  Reselect item in palette
            //MAST_Palette.selectedItemIndex = newSelectedPaletteItemIndex;

            // If palette images were lost due to serialization, load the palette from saved state
            if (MAST_Palette.ArePaletteImagesLost())
            {
                MAST_Interface_Data_Manager.Restore_Palette_Items();
            }
        }

        // If Enabled in Run Mode
        else
        {
            // Nothing so far, because everything is being triggered in ExitEditMode event method
        }
    }
Ejemplo n.º 8
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);
    }