// ---------------------------------------------------------------------------
    // 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();
    }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
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();
        }
    }