Esempio n. 1
0
        public void drawInspector()
        {
            if (GUIUtils.DrawHeader("Create palette"))
            {
                GUIUtils.BeginContents();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        m_selectedAlgorithm = (Algorithm)EditorGUILayout.EnumPopup(m_selectedAlgorithm);
                        if (GUILayout.Button("Generate", EditorStyles.miniButton))
                        {
                            GUI.FocusControl(null);
                            generatePalette();
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    m_colorCount = EditorGUILayout.IntSlider("Number of colors", m_colorCount, 1, 25);

                    if (m_selectedAlgorithm == Algorithm.RANDOM_FROM_COLOR)
                    {
                        m_colorReference = EditorGUILayout.ColorField("Base color", m_colorReference);
                        m_colorOffset    = EditorGUILayout.FloatField("Color offset", m_colorOffset);
                    }
                    else if (m_selectedAlgorithm == Algorithm.RANDOM_GOLDEN_RATIO)
                    {
                        m_saturation = EditorGUILayout.Slider("Saturation", m_saturation, 0.0f, 1.0f);
                    }
                    else if (m_selectedAlgorithm == Algorithm.GRADIENT)
                    {
                        m_colorGradient1 = EditorGUILayout.ColorField("From color", m_colorGradient1);
                        m_colorGradient2 = EditorGUILayout.ColorField("To color", m_colorGradient2);
                    }

                    if (m_generatedColorPalette != null)
                    {
                        if (GUI.changed)
                        {
                            generatePalette();
                        }

                        GUILayout.Space(3f);

                        EditorGUILayout.BeginHorizontal();
                        {
                            for (int j = 0; j < m_generatedColorPalette.colorInfoList.Count; j++)
                            {
                                Rect rect = EditorGUILayout.GetControlRect(false, 20f, EditorStyles.colorField, GUILayout.Width(20f));
                                EditorGUIUtility.DrawColorSwatch(rect, m_generatedColorPalette.colorInfoList[j].color);
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        GUILayout.Space(3f);

                        if (GUILayout.Button("Add to my palettes"))
                        {
                            m_paletteData.colorPaletteList.Add(m_generatedColorPalette);
                            m_generatedColorPalette = null;

                            PaletteUtils.SavePalettes(m_paletteData);
                        }
                    }
                }
                GUIUtils.EndContents();
            }
        }
Esempio n. 2
0
        public void drawInspector(ColorPalette colorPalette, ColorPaletteData colorPaletteData)
        {
            colorPalette.name = EditorGUILayout.TextField("Palette name", colorPalette.name);

            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.Space();

                for (int i = 0; i < colorPalette.colorInfoList.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField("#" + ColorUtils.ColorToHex(colorPalette.colorInfoList[i].color), GUILayout.Width(55f));
                        colorPalette.colorInfoList[i].name = EditorGUILayout.TextField(colorPalette.colorInfoList[i].name);

                        colorPalette.colorInfoList[i].color = EditorGUILayout.ColorField(colorPalette.colorInfoList[i].color);

                        GUI.changed = false;

                        if (GUILayout.Button(new GUIContent("+", "duplicate"), EditorStyles.miniButtonLeft, GUILayout.Width(20f)))
                        {
                            colorPalette.colorInfoList.Insert(i + 1, colorPalette.colorInfoList[i].Copy());
                            GUI.FocusControl(null);
                            PaletteUtils.SavePalettes(colorPaletteData);
                            return;
                        }

                        GUI.enabled = i > 0;
                        if (GUILayout.Button(new GUIContent("\u2191", "move up"), EditorStyles.miniButtonMid, GUILayout.Width(20f)))
                        {
                            ColorInfo tmpColor = colorPalette.colorInfoList[i];
                            colorPalette.colorInfoList.RemoveAt(i);
                            colorPalette.colorInfoList.Insert(i - 1, tmpColor);
                            GUI.FocusControl(null);
                        }
                        GUI.enabled = true;

                        GUI.enabled = i < colorPalette.colorInfoList.Count - 1;
                        if (GUILayout.Button(new GUIContent("\u2193", "move down"), EditorStyles.miniButtonMid, GUILayout.Width(20f)))
                        {
                            ColorInfo tmpColor = colorPalette.colorInfoList[i];
                            colorPalette.colorInfoList.RemoveAt(i);
                            colorPalette.colorInfoList.Insert(i + 1, tmpColor);
                            GUI.FocusControl(null);
                        }
                        GUI.enabled = true;

                        GUI.enabled = colorPalette.colorInfoList.Count > 1;
                        if (GUILayout.Button(new GUIContent("-", "delete"), EditorStyles.miniButtonRight, GUILayout.Width(20f)))
                        {
                            colorPalette.colorInfoList.RemoveAt(i);
                            GUI.FocusControl(null);
                            PaletteUtils.SavePalettes(colorPaletteData);
                            return;
                        }
                        GUI.enabled = true;

                        if (GUI.changed)
                        {
                            PaletteUtils.SavePalettes(colorPaletteData);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.Space();
            }
            EditorGUILayout.EndVertical();
        }
        public static ColorPalette Import(Uri uri)
        {
            ColorPalette colorPalette = new ColorPalette();

            colorPalette.name = uri.AbsolutePath;

            if (uri.AbsolutePath.Contains("/pattern/template/"))
            {
                throw new UnityException("Sorry, we do not support getting 'pattern templates' from colourLovers.com.");
            }
            else if (uri.AbsolutePath.Contains("/shape/"))
            {
                throw new UnityException("Sorry, we do not support getting 'shapes' from colourLovers.com.");
            }
            else if (uri.AbsolutePath.Contains("/color/"))
            {
                throw new UnityException("Sorry, we do not support getting 'simple colors' from colourLovers.com.");
            }

            WebClient client = new WebClient();

            using (Stream stream = client.OpenRead(uri))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    string    line;
                    ColorInfo colorInfo = new ColorInfo();

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Contains("feature-detail") && line.Contains("h1"))
                        {
                            colorPalette.name = line.Substring(line.IndexOf("<h1>") + 4, line.IndexOf("</h1>") - line.IndexOf("<h1>") - 4);
                        }

                        if (line.Contains("<h3 class=\"left mr-10"))
                        {
                            string textToFind = "<h3 class=\"left mr-10\" style=\"height: 20px;\">";
                            string name       = line.Substring(line.IndexOf(textToFind) + textToFind.Length);
                            name = name.Substring(name.IndexOf(">") + 1);
                            name = name.Substring(0, name.IndexOf("</a>"));

                            colorInfo      = new ColorInfo();
                            colorInfo.name = name;
                        }

                        if (line.Contains("right-col big-number-label") && line.Contains("RGB"))
                        {
                            string   rgbColorsString = line.Substring(line.IndexOf("<h4>") + 4, line.IndexOf("</h4>") - line.IndexOf("<h4>") - 4);
                            string[] rgbColorArray   = rgbColorsString.Split(',');

                            colorInfo.color = new Color(int.Parse(rgbColorArray[0]) / 255f, int.Parse(rgbColorArray[1]) / 255f, int.Parse(rgbColorArray[2]) / 255f);

                            colorPalette.colorInfoList.Add(colorInfo);
                        }
                    }
                }
            }

            if (colorPalette.colorInfoList == null || colorPalette.colorInfoList.Count == 0)
            {
                throw new UnityException("Error getting palette from the website: " + uri.AbsoluteUri + ". Please contact us at [email protected] :D");
            }

            return(colorPalette);
        }