Esempio n. 1
0
    // -----------------------------------------------------------------------
    // Get a random prefab from the same category as the selected prefab
    // -----------------------------------------------------------------------
    private static void GetRandomPrefabInCategory(int categoryID)
    {
        // Create a list to hold all viable replacement prefabs
        List <int> replacementPrefabIndexList = new List <int>();

        // Define MAST component script variable outside the foreach loop
        MAST_Prefab_Component mastScript;

        // Loop through each prefab in the palette
        for (int prefabIndex = 0; prefabIndex < MAST_Palette.GetPrefabArray().Length; prefabIndex++)
        {
            // Get the MAST component script attached to this prefab
            mastScript = MAST_Palette.GetPrefabArray()[prefabIndex].GetComponent <MAST_Prefab_Component>();

            // Wrap within a try/catch incase a MAST component script isn't attached to a prefab
            try
            {
                // If prefab category ID matches and prefab is replaceable, add it to replacement prefab list
                if (mastScript.categoryID == categoryID)
                {
                    if (mastScript.randomizer.replaceable)
                    {
                        replacementPrefabIndexList.Add(prefabIndex);
                    }
                }
            }
            catch
            {
                // Do nothing with an error.  No MAST script was attached, so no categoryID
            }
        }

        // Get a random number between 0 and the total amount of replacement prefabs - 1
        int replacementPrefabIndex = (int)Random.Range(0, replacementPrefabIndexList.Count);

        // Select the new prefab
        MAST_Palette.selectedItemIndex = replacementPrefabIndexList[replacementPrefabIndex];
        MAST_Placement_Interface.ChangeSelectedPrefab();
    }
Esempio n. 2
0
    // Handle SceneView GUI
    private void SceneviewGUI(SceneView sceneView)
    {
        bool scrollWheelUsed = false;

        // If SHIFT key is held down
        if (Event.current.shift)
        {
            // If mouse scrollwheel was used
            if (Event.current.type == EventType.ScrollWheel)
            {
                // If scrolling wheel down
                if (Event.current.delta.y > 0)
                {
                    // Select next prefab and cycle back to top of prefabs if needed
                    MAST_Palette.selectedItemIndex++;
                    if (MAST_Palette.selectedItemIndex >= MAST_Palette.GetPrefabArray().Length)
                    {
                        MAST_Palette.selectedItemIndex = 0;
                    }

                    scrollWheelUsed = true;
                }

                // If scrolling wheel dupown
                else if (Event.current.delta.y < 0)
                {
                    // Select previous prefab and cycle back to bottom of prefabs if needed
                    MAST_Palette.selectedItemIndex--;
                    if (MAST_Palette.selectedItemIndex < 0)
                    {
                        MAST_Palette.selectedItemIndex = MAST_Palette.GetPrefabArray().Length - 1;
                    }

                    scrollWheelUsed = true;
                }
            }
        }

        // If successfully scrolled wheel
        if (scrollWheelUsed)
        {
            // If no draw tool is selected, then select the draw single tool
            if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == -1)
            {
                MAST_Settings.gui.toolbar.selectedDrawToolIndex = 0;
                MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawSingle);
            }

            // If erase draw tool isn't selected, change the visualizer prefab
            if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4)
            {
                MAST_Placement_Interface.ChangeSelectedPrefab();
            }

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

            // Keep mouseclick from selecting other objects
            GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
            Event.current.Use();
        }
    }
Esempio n. 3
0
    private void DisplayPaletteGUIPopulated()
    {
        GUILayout.BeginVertical("MAST Toolbar BG");  // Begin toolbar vertical layout

        GUILayout.BeginHorizontal();

        // ---------------------------------------------
        // Calculate Palette SelectionGrid size
        // ---------------------------------------------

        // Verical scroll view for palette items
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

        // Get scrollview width and height of scrollview if is resized
        float scrollViewWidth = EditorGUIUtility.currentViewWidth - scrollBarWidth - toolBarIconSize - 20;

        int   rowCount         = Mathf.CeilToInt(MAST_Palette.GetGUIContentArray().Length / (float)MAST_Interface_Data_Manager.state.columnCount);
        float scrollViewHeight = rowCount * ((scrollViewWidth) / MAST_Interface_Data_Manager.state.columnCount);

        // ---------------------------------------------
        // Get palette background image
        // ---------------------------------------------
        string paletteGUISkin = null;

        switch (MAST_Settings.gui.palette.bgColor)
        {
        case MAST_GUI_ScriptableObject.PaleteBGColor.Dark:
            paletteGUISkin = "MAST Palette Item Dark";
            break;

        case MAST_GUI_ScriptableObject.PaleteBGColor.Gray:
            paletteGUISkin = "MAST Palette Item Gray";
            break;

        case MAST_GUI_ScriptableObject.PaleteBGColor.Light:
            paletteGUISkin = "MAST Palette Item Light";
            break;
        }

        EditorGUI.BeginChangeCheck();

        // ---------------------------------------------
        // Draw Palette SelectionGrid
        // ---------------------------------------------

        int newSelectedPaletteItemIndex = GUILayout.SelectionGrid(
            MAST_Palette.selectedItemIndex,
            MAST_Palette.GetGUIContentArray(),
            MAST_Interface_Data_Manager.state.columnCount,
            paletteGUISkin,
            GUILayout.Width((float)scrollViewWidth),
            GUILayout.Height(scrollViewHeight)
            );

        // If changes to UI value ocurred, update the grid
        if (EditorGUI.EndChangeCheck())
        {
            // If palette item was deselected by being clicked again
            if (newSelectedPaletteItemIndex == MAST_Palette.selectedItemIndex)
            {
                MAST_Palette.selectedItemIndex = -1;

                // If erase draw tool isn't selected, remove the draw tool and visualizer
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4)
                {
                    MAST_Settings.gui.toolbar.selectedDrawToolIndex = -1;
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.None);
                }
            }

            // If palette item selection has changed
            else
            {
                MAST_Palette.selectedItemIndex = newSelectedPaletteItemIndex;

                // If no draw tool is selected, then select the draw single tool
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex == -1)
                {
                    MAST_Settings.gui.toolbar.selectedDrawToolIndex = 0;
                    MAST_Placement_Interface.ChangePlacementMode(MAST_Placement_Interface.PlacementMode.DrawSingle);
                }

                // If erase draw tool isn't selected, change the visualizer prefab
                if (MAST_Settings.gui.toolbar.selectedDrawToolIndex != 4)
                {
                    MAST_Placement_Interface.ChangeSelectedPrefab();
                }
            }
        }

        EditorGUILayout.EndScrollView();

        GUILayout.EndHorizontal();

        // Palette Column Count Slider
        MAST_Interface_Data_Manager.state.columnCount =
            (int)GUILayout.HorizontalSlider(MAST_Interface_Data_Manager.state.columnCount, 1, 10);

        GUILayout.Space(toolBarIconSize / 10);

        GUILayout.EndVertical();
    }