Esempio n. 1
0
        public static ColorPalette Import(string filePath)
        {
            ColorPalette colorPalette = new ColorPalette();

            colorPalette.name = Path.GetFileNameWithoutExtension(filePath);

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

                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Contains("fill="))
                    {
                        ParserColorResult colorResult = extractColor(line);
                        if (colorResult.success)
                        {
                            colorPalette.colorInfoList.Add(new ColorInfo(colorResult.name, colorResult.color));
                        }
                    }
                }
            }

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

            return(colorPalette);
        }
Esempio n. 2
0
        public static ColorPalette Import(string filePath)
        {
            ColorPalette colorPalette = new ColorPalette();

            colorPalette.name = Path.GetFileNameWithoutExtension(filePath);

            byte[] data = File.ReadAllBytes(filePath);
            if (data.Length < 12 || data[0] != 'A' || data[1] != 'S' || data[2] != 'E' || data[3] != 'F')
            {
                throw new UnityException("The file " + filePath + " doesn't seem to be in Adobe Swatch Exchange (ASE) format.");
            }

            UInt32 blocks = GetInt32(data, 8);

            int offset = 12;

            for (int b = 0; b < blocks; b++)
            {
                UInt16 blockType = GetInt16(data, offset);
                offset += sizeof(UInt16);

                UInt32 blockLength = GetInt32(data, offset);
                offset += sizeof(UInt32);

                switch (blockType)
                {
                case 0xC001:                 // Group Start Block (ignored)
                    break;

                case 0xC002:                 // Group End Block (ignored)
                    break;

                case 0x0001:                 // Color
                    ParserColorResult colorResult = ReadColor(data, offset, b);
                    if (colorResult.success)
                    {
                        colorPalette.colorInfoList.Add(new ColorInfo(colorResult.name, colorResult.color));
                    }
                    break;

                default:
                    throw new UnityException("Warning: Block " + b + " is of an unknown type 0x" + blockType.ToString("X") + " (file corrupt?)");
                }

                offset += (int)blockLength;
            }

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

            return(colorPalette);
        }
Esempio n. 3
0
        public static ColorPalette Import(string filePath)
        {
            ColorPalette colorPalette = new ColorPalette();

            colorPalette.name = Path.GetFileNameWithoutExtension(filePath);

            bool nextLineIsColors = false;

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

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

                    if (nextLineIsColors)
                    {
                        ParserColorResult colorResult = extractColor(line);
                        if (colorResult.success)
                        {
                            colorPalette.colorInfoList.Add(new ColorInfo(colorResult.name, colorResult.color));
                        }
                    }

                    if (line.Trim().Equals("#"))
                    {
                        nextLineIsColors = true;
                    }
                }
            }

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

            return(colorPalette);
        }