Пример #1
0
        public bool ImportPaletteCollection(string newURL)
        {
            reset();

            analizeURL(newURL);

            WWW html = new WWW(newURL);

            while (!html.isDone)
            {
                if (!string.IsNullOrEmpty(html.error))
                {
                    throw new UnityException("error loading URL: " + html.error);
                }
            }

            Debug.Log("download finished, loaded " + html.bytesDownloaded + " bytes");

            collectionData.paletteURL = newURL;

            HtmlParser parser = new HtmlParser();
            Document   doc    = parser.Parse(html.text);

            //Debug.Log (doc.ToString ());

            PaletteData extracedData = null;

            if (isColourLovers)
            {
                extracedData = PaletteImporter.extractFromColorlovers(doc, this.collectionData.loadPercent);

                if (this.collectionData.loadPercent)
                {
                    for (int i = 0; i < extracedData.percentages.Length; i++)
                    {
                        // totalWidth = 100% this.myData.percentages [i] = x%
                        extracedData.percentages [i] = extracedData.percentages [i] / extracedData.totalWidth;
                    }
                }
                else
                {
                    extracedData.percentages = PaletteData.getDefaultPercentages();
                }
            }
            else if (isPLTTS)
            {
                extracedData = PaletteImporter.extractFromPLTTS(doc, this.collectionData.loadPercent);
            }

/*						if (extracedData != null) {
 *                                                              return CreatePalette (new KeyValuePair<string, PaletteData> (extracedData.name, extracedData));
 *                                              } else {
 *                                                              Debug.Log ("Palette :'" + extracedData.percentages [0] + "' could not be load... is the URL correct? ");
 *                                                              return false;
 *                                              }
 */
            return(this.collectionData.setSize(this.collectionData.palettes.Count + 1,
                                               new KeyValuePair <string, PaletteData> (extracedData.name, extracedData)));
        }
Пример #2
0
        public static PaletteData extractFromPLTTS(Document doc, bool loadPercent)
        {
            int         colorCount   = 0;
            int         percentCount = 0;
            PaletteData palette      = new PaletteData();

            Tag colorBlock = doc.Find(".palette-colors");

            //Debug.Log (colorBlock);

            foreach (Element colorDiv in colorBlock.Children)
            {
                if (!string.IsNullOrEmpty(colorDiv.ToString().Trim()))
                {
                    // can contain empty Elements!

                    //Tag colorTag = (HtmlSharp.Elements.Tags.Div)colorDiv;
                    Tag colorTag = (Tag)colorDiv;

                    string style = colorTag ["style"];
                    foreach (string styleCss in style.Split(';'))
                    {
                        if (loadPercent && styleCss.Contains("width"))
                        {
                            string width = styleCss.Split(':') [1];
                            width = width.Substring(0, width.IndexOf("%"));
                            float widthF = float.Parse(width.Trim());
                            palette.totalWidth += widthF / 100;
                            palette.percentages [percentCount++] = widthF / 100;
                        }
                        else if (styleCss.Contains("background-color"))
                        {
                            string bgColor = styleCss.Split(':') [1];
                            bgColor = bgColor.Trim().Substring(1);
                            palette.colors [colorCount++] = JSONPersistor.HexToColor(bgColor);
                        }
                    }

                    //Debug.Log (style);
                }
            }

            if (!loadPercent)
            {
                palette.percentages = PaletteData.getDefaultPercentages();
            }

            return(palette);
        }
Пример #3
0
        private IEnumerator ImportPaletteFromURL(string newURL)
        {
            analizeURL(newURL);

            WWW html = new WWW(newURL);

            while (!html.isDone)
            {
                if (!string.IsNullOrEmpty(html.error))
                {
                    throw new UnityException("error loading URL: " + html.error);
                }

                //Debug.Log ("downloading Palette " + html.progress + "%");
            }

            Debug.Log("download finished, loaded " + html.bytesDownloaded + " bytes");
            this.myImporterData.paletteURL = newURL;
            string[] splitted    = newURL.Split('/');
            string   paletteName = splitted [splitted.Length - 1];


            HtmlParser parser = new HtmlParser();
            Document   doc    = parser.Parse(html.text);

/*						this.myImporterData.colors = new Color[5];
 *                                              this.myImporterData.percentages = new float[5];
 */
            PaletteData extracedData = null;

            if (isColourLovers)
            {
                extracedData = extractFromColorlovers(doc, this.myImporterData.loadPercent);

                // don't copy directly because of PaletteData vs PaletteImporterData
                this.myImporterData.totalWidth = extracedData.totalWidth;
                this.myImporterData.name       = paletteName;
                this.myImporterData.colors     = extracedData.colors;
                this.myImporterData.alphas     = extracedData.alphas;


                if (this.myImporterData.loadPercent)
                {
                    this.myImporterData.percentages = extracedData.percentages;


                    for (int i = 0; i < this.myImporterData.percentages.Length; i++)
                    {
                        // totalWidth = 100% this.myData.percentages [i] = x%

                        this.myImporterData.percentages [i] = this.myImporterData.percentages [i] / this.myImporterData.totalWidth;
                        //Debug.Log ("totalWidth " + this.myImporterData.totalWidth + " % " + this.myImporterData.percentages [i]);
                    }
                }
                else
                {
                    this.myImporterData.percentages = PaletteData.getDefaultPercentages();
                }
            }
            else if (isPLTTS)
            {
                extracedData = extractFromPLTTS(doc, this.myImporterData.loadPercent);

                this.myImporterData.name        = paletteName;
                this.myImporterData.colors      = extracedData.colors;
                this.myImporterData.percentages = extracedData.percentages;
                this.myImporterData.alphas      = extracedData.alphas;
            }

            yield return(null);
        }