private static ParserColorResult extractColor(string text) { try { int start = text.IndexOf("fill=\"") + 7; int end = text.IndexOf("\"", start); string colorString = text.Substring(start, end - start); return(new ParserColorResult(null, ColorUtils.HexToColor(colorString), true)); } catch (System.Exception) { return(new ParserColorResult(null, Color.white, false)); } }
public static ColorPalette Import(Uri uri) { ColorPalette colorPalette = new ColorPalette(); colorPalette.name = uri.AbsolutePath; WebClient client = new WebClient(); using (Stream stream = client.OpenRead(uri)) { using (StreamReader reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) { if (line.Contains("href") && line.Contains("h1")) { int startIndex = line.IndexOf(">", line.IndexOf("<h1>") + 4) + 1; colorPalette.name = line.Substring(startIndex, line.IndexOf("</a>") - startIndex); } if (line.Contains("var global_hex_colors")) { string hexColorsString = line.Substring(line.IndexOf("'") + 1, line.LastIndexOf("'") - line.IndexOf("'") - 1); string[] hexColorArray = hexColorsString.Split(','); foreach (string hexColor in hexColorArray) { colorPalette.colorInfoList.Add(new ColorInfo(null, ColorUtils.HexToColor(hexColor))); } } } } } 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); }
public static ColorPalette Import(Uri uri) { ColorPalette colorPalette = new ColorPalette(); colorPalette.name = uri.AbsolutePath; WWW www = new WWW(uri.AbsoluteUri); while (!www.isDone) { ; } if (!string.IsNullOrEmpty(www.error)) { throw new UnityException("Error getting palette from the website: " + uri.AbsoluteUri + ". Please contact us at [email protected]\n" + www.error); } foreach (string line in www.text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)) { if (line.Contains("screenshot-title") && line.Contains("h1")) { colorPalette.name = line.Substring(line.IndexOf(">") + 1, line.IndexOf("<", line.IndexOf(">")) - line.IndexOf(">") - 1); } if (line.Contains("<a style=\"background-color:")) { string hexColorString = line.Substring(line.IndexOf("#") + 1, 6); colorPalette.colorInfoList.Add(new ColorInfo(null, ColorUtils.HexToColor(hexColorString))); } } 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); }