Beispiel #1
0
        void OnGUI()
        {
            newMeshSize = EditorGUILayout.Vector3IntField("Size", newMeshSize);
            isFill      = EditorGUILayout.Toggle("Fill", isFill);

            paletteSelected = (ColorPalette)EditorGUILayout.ObjectField("Color Palette", paletteSelected, typeof(ColorPalette), false);

            if (paletteSelected != null)
            {
                EditorGUILayout.LabelField("Preview");
                ColorPaletteDrawer.DrawColorPalette(paletteSelected);
            }

            if (GUILayout.Button("Create"))
            {
                if (paletteSelected == null)
                {
                    string path = EditorUtility.SaveFilePanelInProject("Save new Color Palette", "ColorPalette", "asset", "");
                    if (path != string.Empty)
                    {
                        paletteSelected = ScriptableObject.CreateInstance <ColorPalette>();
                        paletteSelected.AddColor(Color.white);
                        AssetDatabase.CreateAsset(paletteSelected, path);
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                    }
                }

                if (paletteSelected != null)
                {
                    InstanciateNewVoxelMesh();
                    Close();
                }
            }
        }
Beispiel #2
0
 void GUIColorPalette()
 {
     foldoutColor = EditorGUILayout.Foldout(foldoutColor, "Color Palette");
     if (!foldoutColor)
     {
         return;
     }
     if (voxelMesh != null && voxelMesh.ColorPalette != null)
     {
         ColorPalette palette = (ColorPalette)EditorGUILayout.ObjectField("Color Palette", voxelMesh.ColorPalette, typeof(ColorPalette), false);
         if (palette != null && palette != voxelMesh.ColorPalette)
         {
             voxelMesh.ColorPalette = palette;
             voxelMesh.Refresh();
         }
         int colorSelected = voxelMesh.voxelTemplate.colorId;
         ColorPaletteDrawer.DrawColorPalette(voxelMesh.ColorPalette, ref colorSelected);
         if (voxelMesh.voxelTemplate.colorId != colorSelected)
         {
             Repaint();
         }
         voxelMesh.voxelTemplate.colorId = colorSelected;
     }
 }
Beispiel #3
0
        public static void DrawPaletteGUI(ColorPalette palette, ref int idColor)
        {
            if (palette == null)
            {
                return;
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Add PNG"))
            {
                string path = EditorUtility.OpenFilePanel("Open Palette Color", Application.dataPath, "png");
                if (path.Length != 0)
                {
                    Texture2D texture = ReadPNGFile(path);
                    palette.LoadFromTexture(texture);
                }
            }


            if (GUILayout.Button("Replace PNG"))
            {
                string path = EditorUtility.OpenFilePanel("Open Palette Color", Application.dataPath, "png");
                if (path.Length != 0)
                {
                    Texture2D texture = ReadPNGFile(path);
                    palette.LoadFromTexture(texture, true);
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Color Palette", EditorStyles.boldLabel);

            ColorPaletteDrawer.DrawColorPalette(palette, ref idColor);

            EditorGUILayout.BeginHorizontal();

            Color color = palette.GetColor(idColor);

            Color colorModified = EditorGUILayout.ColorField(color);

            if (colorModified != color)
            {
                palette.SetColor(colorModified, idColor);
                EditorUtility.SetDirty(palette);
            }

            if (GUILayout.Button("+"))
            {
                palette.AddColor(color);
                idColor = palette.colors.Count - 1;
                EditorUtility.SetDirty(palette);
            }
            if (GUILayout.Button("-"))
            {
                palette.RemoveColor(idColor);
                if (idColor >= palette.colors.Count && palette.colors.Count > 0)
                {
                    idColor = palette.colors.Count - 1;
                }
                EditorUtility.SetDirty(palette);
            }
            EditorGUILayout.EndHorizontal();
        }