Esempio n. 1
0
        void CreateNewPalette()
        {
            string relativePath = "";
            string absolutePath = EditorUtility.SaveFilePanel("Save Palette", "Assets/", "New Palette", "asset");

            if (absolutePath.StartsWith(Application.dataPath))
            {
                relativePath = "Assets" + absolutePath.Substring(Application.dataPath.Length);
            }

            if (relativePath.Length != 0)
            {
                PaintPalette asset = ScriptableObject.CreateInstance <PaintPalette>();
                asset.palette = paintObjects;
                AssetDatabase.CreateAsset(asset, relativePath);
                AssetDatabase.SaveAssets();
                palettes.Add(asset);
                EditorUtility.FocusProjectWindow();
                Selection.activeObject = asset;
                activePalette          = asset;
                creatingNewPalette     = false;

                Debug.Log("<color=cyan>[Prefab Painter] </color>Palette saved.");
            }

            else
            {
                Debug.Log("<color=cyan>[Prefab Painter] </color>Selected path is invalid.");
            }
        }
Esempio n. 2
0
        void AddMenuItemForPalette(GenericMenu menu, string menuPath, PaintPalette palette)
        {
            bool paletteSelected;

            if (activePalette == null)
            {
                paletteSelected = false;
            }
            else
            {
                if (activePalette.Equals(palette))
                {
                    paletteSelected = true;
                }
                else
                {
                    paletteSelected = false;
                }
            }

            if (creatingNewPalette)
            {
                paletteSelected = false;
            }
            menu.AddItem(new GUIContent(menuPath), paletteSelected, OnPaletteSelected, palette);
        }
Esempio n. 3
0
 void LoadPalette(PaintPalette palette)
 {
     listSize     = palette.palette.Count;
     paintObjects = palette.palette;
     foreach (PaintObject brush in paintObjects)
     {
         brush.gameObjectEditor = null;
     }
 }
Esempio n. 4
0
        void CreateNewPalette()
        {
            PaintPalette asset = ScriptableObject.CreateInstance <PaintPalette>();

            asset.palette = paintObjects;
            string path = AssetDatabase.GenerateUniqueAssetPath("Assets/prefabpainter_palette.asset");

            AssetDatabase.CreateAsset(asset, path);
            AssetDatabase.SaveAssets();
            palettes.Add(asset);
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = asset;
            activePalette          = asset;
            creatingNewPalette     = false;
        }
Esempio n. 5
0
        void LoadPalette(PaintPalette palette)
        {
            listSize     = palette.palette.Count;
            paintObjects = palette.palette;
            bool missingPrefabs = false;

            for (int i = 0; i < listSize; i++)
            {
                if (paintObjects[i].GetGameObject() == null)
                {
                    missingPrefabs = true;
                }
            }

            if (missingPrefabs)
            {
                Debug.Log("<color=cyan>[Prefab Painter] </color>One or more prefabs could not be loaded.");
            }
        }
Esempio n. 6
0
 void OnNewPaletteSelected()
 {
     creatingNewPalette = true;
     activePalette      = null;
     LoadEmptyPalette();
 }
Esempio n. 7
0
 void OnPaletteSelected(object palette)
 {
     LoadPalette((PaintPalette)palette);
     activePalette      = (PaintPalette)palette;
     creatingNewPalette = false;
 }
Esempio n. 8
0
 void OverridePalette(PaintPalette palette)
 {
     palette.palette = paintObjects;
 }
Esempio n. 9
0
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal("Toolbar", GUILayout.ExpandWidth(true));
            if (GUILayout.Button("Load", "ToolbarButton"))
            {
                string path = EditorUtility.OpenFilePanel("Select Palette", "", "asset");
                path = path.Replace(Application.dataPath, "Assets");
                if (path.Length != 0)
                {
                    activePalette = (PaintPalette)AssetDatabase.LoadAssetAtPath(path, typeof(PaintPalette));
                    LoadPalette(activePalette);
                    if (!palettes.Contains(activePalette))
                    {
                        palettes.Add(activePalette);
                    }
                }
                Debug.Log("<color=cyan>[Prefab Painter] </color>Palette loaded.");
            }
            if (activePalette != null)
            {
                GUILayout.Label(new GUIContent("Active: " + activePalette.name), "ToolbarButton");
            }
            else
            {
                GUILayout.Label(new GUIContent("Active: none"), "ToolbarButton");
            }
            GUILayout.Space(5f);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(new GUIContent("", saveIcon, "Save active prefabs as palette."), "ToolbarButton"))
            {
                if (activePalette != null && palettes.Contains(activePalette))
                {
                    OverridePalette(activePalette);
                }
                else
                {
                    CreateNewPalette();
                }
            }
            if (GUILayout.Button(new GUIContent("", deleteIcon, "Remove currently loaded palette."), "ToolbarButton"))
            {
                Debug.Log("Remove Palette");
            }
            if (GUILayout.Button(new GUIContent("Palettes", "Load in a palette."), "ToolbarPopup"))
            {
                GenericMenu menu = new GenericMenu();
                if (palettes.Count > 0)
                {
                    for (int i = 0; i < palettes.Count; i++)
                    {
                        AddMenuItemForPalette(menu, palettes[i].name, palettes[i]);
                    }
                }
                menu.AddItem(new GUIContent("New Palette"), creatingNewPalette, OnNewPaletteSelected);
                menu.AddItem(new GUIContent("Clear List"), false, OnClearList);
                menu.ShowAsContext();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);

            float tempSize    = brushSize;
            int   tempDensity = brushDensity;

            BrushSettingsFold = BeginFold("Brush Settings", BrushSettingsFold);
            if (BrushSettingsFold)
            {
                paintMask = EditorGUILayout.MaskField(
                    new GUIContent("Paint Layer", "On which layer the tool will paint."), paintMask,
                    layerNames.ToArray());
                brushSize      = EditorGUILayout.FloatField("Brush Size", brushSize);
                brushDensity   = EditorGUILayout.IntField("Brush Density", brushDensity);
                paintGroupName = EditorGUILayout.TextField("Paint Group Name", paintGroupName);
            }
            EndFold();

            listSize = Mathf.Max(0, listSize);
            for (int i = 0; i < paintObjects.Count; i++)
            {
                PaintObject.Display(paintObjects[i]);
            }
            if (GUILayout.Button("Add Prefab"))
            {
                listSize++;
            }
            if (GUILayout.Button("Remove Prefab") && listSize != 0)
            {
                listSize--;
            }
            EditorGUILayout.Space();
            CheckForChanges(tempSize, tempDensity);
            EditorGUILayout.EndScrollView();
        }
Esempio n. 10
0
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal("Toolbar", GUILayout.ExpandWidth(true));
            if (GUILayout.Button("Load", "ToolbarButton"))
            {
                string path = EditorUtility.OpenFilePanel("Select Palette", "", "asset");
                path = path.Replace(Application.dataPath, "Assets");
                if (path.Length != 0)
                {
                    activePalette = (PaintPalette)AssetDatabase.LoadAssetAtPath(path, typeof(PaintPalette));
                    LoadPalette(activePalette);
                    if (!palettes.Contains(activePalette))
                    {
                        palettes.Add(activePalette);
                    }
                    Debug.Log("<color=cyan>[Prefab Painter] </color>Palette loaded.");
                }
            }
            if (activePalette != null)
            {
                GUILayout.Label(new GUIContent("Active: " + activePalette.name), "ToolbarButton");
            }
            else
            {
                GUILayout.Label(new GUIContent("Active: none"), "ToolbarButton");
            }
            GUILayout.Space(5f);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(new GUIContent("", saveIcon, "Save active prefabs as palette."), "ToolbarButton"))
            {
                if (activePalette != null && palettes.Contains(activePalette))
                {
                    if (displayOverrideWarning)
                    {
                        switch (EditorUtility.DisplayDialogComplex("Override palette", "Saving the current palette will override the currently active palette which is '" + activePalette.name + "'.", "Okay", "Cancel", "Okay and do not show again"))
                        {
                        case 0:
                            OverridePalette(activePalette);
                            break;

                        case 1:
                            break;

                        case 2:
                            OverridePalette(activePalette);
                            displayOverrideWarning = false;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        OverridePalette(activePalette);
                    }
                }
                else
                {
                    CreateNewPalette();
                }
            }
            if (GUILayout.Button(new GUIContent("", deleteIcon, "Remove currently loaded palette."), "ToolbarButton"))
            {
                Debug.Log("Remove Palette");
            }
            if (GUILayout.Button(new GUIContent("Palettes", "Load in a palette."), "ToolbarPopup"))
            {
                GenericMenu menu = new GenericMenu();
                if (palettes.Count > 0)
                {
                    for (int i = 0; i < palettes.Count; i++)
                    {
                        if (palettes[i] != null)
                        {
                            AddMenuItemForPalette(menu, palettes[i].name, palettes[i]);
                        }
                    }
                }
                menu.AddItem(new GUIContent("New Palette"), creatingNewPalette, OnNewPaletteSelected);
                menu.AddItem(new GUIContent("Clear List"), false, OnClearList);
                menu.ShowAsContext();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);

            float tempSize    = brushSize;
            int   tempDensity = brushDensity;

            BrushSettingsFold = BeginFold("Brush Settings", BrushSettingsFold);
            if (BrushSettingsFold)
            {
                paintMask = EditorGUILayout.MaskField(
                    new GUIContent("Paint Layer", "On which layer the tool will paint."), paintMask,
                    layerNames.ToArray());
                brushSize      = EditorGUILayout.FloatField("Brush Size", brushSize);
                brushDensity   = EditorGUILayout.IntField("Brush Density", brushDensity);
                paintGroupName = EditorGUILayout.TextField("Paint Group Name", paintGroupName);
            }
            EndFold();

            listSize = Mathf.Max(0, listSize);

            DisplayPrefabs(paintObjects);
            if (Event.current.type == EventType.Layout && selectedPrefab != null)
            {
                displayPrefabSettings = true;
            }

            if (displayPrefabSettings)
            {
                selectedPrefab.displaySettings();
            }

            EditorGUILayout.Space();
            GUILayout.Space(75f + prefabListHeight);
            CheckForChanges(tempSize, tempDensity);
            EditorGUILayout.EndScrollView();
        }
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal("Toolbar", GUILayout.ExpandWidth(true));

            if (GUILayout.Button("Load", "ToolbarButton"))
            {
                string path = EditorUtility.OpenFilePanel("Select Palette", "", "asset");
                path = path.Replace(Application.dataPath, "Assets");

                if (path.Length != 0)
                {
                    activePalette = (PaintPalette)AssetDatabase.LoadAssetAtPath(path, typeof(PaintPalette));
                    LoadPalette(activePalette);
                    if (!palettes.Contains(activePalette))
                    {
                        palettes.Add(activePalette);
                    }
                    Debug.Log("<color=cyan>[Prefab Painter] </color>Palette loaded.");
                }
            }

            if (activePalette != null)
            {
                GUILayout.Label(new GUIContent("Active: " + activePalette.name), "ToolbarButton");
            }
            else
            {
                GUILayout.Label(new GUIContent("Active: none"), "ToolbarButton");
            }
            GUILayout.Space(5f);
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(new GUIContent("", saveIcon, "Save active prefabs as palette."), "ToolbarButton"))
            {
                if (activePalette != null && palettes.Contains(activePalette))
                {
                    if (displayOverrideWarning)
                    {
                        switch (EditorUtility.DisplayDialogComplex("Override palette", "Saving the current palette will override the currently active palette which is '" + activePalette.name + "'.", "Okay", "Cancel", "Okay and do not show again"))
                        {
                        case 0:
                            OverridePalette(activePalette);
                            break;

                        case 1:
                            break;

                        case 2:
                            OverridePalette(activePalette);
                            displayOverrideWarning = false;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        OverridePalette(activePalette);
                    }
                }
                else
                {
                    CreateNewPalette();
                }
            }
            if (GUILayout.Button(new GUIContent("", deleteIcon, "Remove currently loaded palette."), "ToolbarButton"))
            {
                Debug.Log("Remove Palette");
            }

            if (GUILayout.Button(new GUIContent("Palettes", "Load in a palette."), "ToolbarPopup"))
            {
                GenericMenu menu = new GenericMenu();
                if (palettes.Count > 0)
                {
                    for (int i = 0; i < palettes.Count; i++)
                    {
                        if (palettes[i] != null)
                        {
                            AddMenuItemForPalette(menu, palettes[i].name, palettes[i]);
                        }
                    }
                }
                menu.AddItem(new GUIContent("New Palette"), creatingNewPalette, OnNewPaletteSelected);
                menu.AddItem(new GUIContent("Clear List"), false, OnClearList);
                menu.ShowAsContext();
            }
            EditorGUILayout.EndHorizontal();
            selectedTab = GUILayout.Toolbar(selectedTab, new string[] { "Painting", "Palettes", "Settings" });

            switch (selectedTab)
            {
            case 0:
                DrawPaintingTab();
                break;

            default:
                break;
            }
        }