// ---------------------------------------------------------------------------
    // Save preferences to state scriptable object
    // ---------------------------------------------------------------------------
    public static void Save_Palette_Items(bool forceSave = false)
    {
        // Get or create a scriptable object to store the interface state data
        Get_Reference_To_Scriptable_Object();

        // If palette data has changed or if forcing a save "from loading new prefabs with button"
        if (MAST_Palette.GetPrefabArray() != state.prefabs || forceSave)
        {
            // Delete any previous palette items same in the "MAST/Etc/Temp" folder
            string paletteImagePath = MAST_Asset_Loader.GetMASTRootFolder() + "/Etc/Temp";
            if (Directory.Exists(paletteImagePath))
            {
                Directory.Delete(paletteImagePath, true);
            }
            Directory.CreateDirectory(paletteImagePath);

            // Save prefabs
            state.prefabs = MAST_Palette.GetPrefabArray();

            // Define palette item tooltip array
            string[] paletteItemTooltip = new string[MAST_Palette.GetGUIContentArray().Length];

            // Get texture path to save palette images
            string texturePath = MAST_Asset_Loader.GetMASTRootFolder() + "/Etc/Temp/temp_palette_image_";

            // Loop through each item in the palette
            for (int i = 0; i < MAST_Palette.GetGUIContentArray().Length; i++)
            {
                // Get the tooltip from the palette GUIContent
                paletteItemTooltip[i] = MAST_Palette.GetGUIContentArray()[i].tooltip;

                // Encode this palette item image to PNG then save to disk
                byte[] bytes = MAST_Palette.GetTexture2DArray()[i].EncodeToPNG();
                File.WriteAllBytes(texturePath + i.ToString("000") + ".png", bytes);
            }

            // Save palette item tooltips and images (converted to byte arrays)
            state.paletteItemTooltip = paletteItemTooltip;
        }

        // Save state changes to disk
        Save_Changes_To_Disk();
    }
예제 #2
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();
    }