Exemplo n.º 1
0
        public void onButtonPrintColorNameClicked()
        {
            ColorPalette colorPalette = ColorPaletteData.Singleton.colorPaletteList[smileyPaletteIndex];
            ColorInfo    colorInfo    = colorPalette.getColorFromName("Mouth");

            Debug.Log(colorInfo);
        }
Exemplo n.º 2
0
        public void onButtonPrintColorIndexClicked()
        {
            ColorPalette colorPalette = ColorPaletteData.Singleton.colorPaletteList[smileyPaletteIndex];
            ColorInfo    colorInfo    = colorPalette.colorInfoList[0];

            Debug.Log(colorInfo);
        }
Exemplo n.º 3
0
        public ColorInfo Copy()
        {
            ColorInfo colorInfo = new ColorInfo();

            colorInfo.name  = name;
            colorInfo.color = color;
            return(colorInfo);
        }
Exemplo n.º 4
0
        public ColorInfo getColorFromName(string colorName)
        {
            ColorInfo colorInfo = colorInfoList.Where(x => x.name.Equals(colorName)).FirstOrDefault();

            if (colorInfo == null)
            {
                throw new Exception("Could not find a color named '" + colorName + "' in the palette '" + name + "'");
            }

            return(colorInfo);
        }
Exemplo n.º 5
0
        public void onButtonInfoClicked()
        {
            ColorPalette colorPalette = ColorPaletteData.Singleton.colorPaletteList[smileyPaletteIndex];

            Debug.Log("Palette name: " + colorPalette.name);
            for (int i = 0; i < colorPalette.colorInfoList.Count; i++)
            {
                ColorInfo colorInfo = colorPalette.colorInfoList[i];
                Debug.Log("Color: " + colorInfo.name + " - " + colorInfo.color);
            }
        }
Exemplo n.º 6
0
        public static Rect DrawCustomSwatch(ColorInfo colorInfo, int size)
        {
            Rect rect = EditorGUILayout.GetControlRect(false, size, EditorStyles.colorField, GUILayout.Width(size));

            GUI.enabled = false;
            GUI.Button(rect, new GUIContent("", colorInfo.ToString()));
            GUI.enabled = true;
            EditorGUIUtility.DrawColorSwatch(rect, colorInfo.color);

            return(rect);
        }
Exemplo n.º 7
0
        public static ColorPalette Import(string filePath)
        {
            ColorPalette colorPalette = new ColorPalette();

            colorPalette.name = Path.GetFileNameWithoutExtension(filePath);

            using (StreamReader reader = new StreamReader(filePath))
            {
                string    line      = "";
                ColorInfo colorInfo = new ColorInfo();

                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("  m_Name:") && string.IsNullOrEmpty(colorPalette.name))
                    {
                        line = line.Replace("m_Name:", string.Empty).Trim();
                        colorPalette.name = line;
                    }

                    if (line.StartsWith("  - m_Name:"))
                    {
                        colorInfo = new ColorInfo();

                        line           = line.Replace("- m_Name:", string.Empty).Trim();
                        colorInfo.name = line;
                    }

                    if (line.StartsWith("    m_Color:"))
                    {
                        line            = line.Replace("m_Color:", string.Empty).Trim();
                        colorInfo.color = extractColor(line);

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

            if (colorPalette.colorInfoList == null || colorPalette.colorInfoList.Count == 0)
            {
                throw new UnityException("Error parsing the color preset file at path: " + filePath + ". Are you sure you selected a valid file?");
            }

            return(colorPalette);
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        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);
        }