Пример #1
0
        public static void ProcessImageFormat(string path, int maxSize, TextureFormat iosFormat, TextureFormat androidFormat, bool isMinMap)
        {
            string[] extends = new string[] { ".png.meta", ".tga.meta", ".jpg.meta" };

            EditorUtils.ProcessDir(path, extends, (file, param) => {
                bool hasFound         = false;
                List <string> content = new List <string>();
                StreamReader stream   = new StreamReader(file);

                string line;
                while ((line = stream.ReadLine()) != null)
                {
                    if (line.IndexOf("enableMipMap:") != -1)
                    {
                        line     = "    enableMipMap: " + Convert.ToInt32(isMinMap);
                        hasFound = true;
                    }
                    string targetLine = string.Empty;
                    if (line.IndexOf("buildTargetSettings:") != -1)
                    {
                        line = "  buildTargetSettings: []";
                        while ((targetLine = stream.ReadLine()) != null && (targetLine.IndexOf("- buildTarget:") != -1))
                        {
                            stream.ReadLine();
                            stream.ReadLine();
                            stream.ReadLine();
                        }
                        hasFound = true;
                    }

                    if (line.IndexOf("buildTargetSettings: []") != -1)
                    {
                        line = "  buildTargetSettings:";
                        content.Add(line);
                        line = "  - buildTarget: iPhone";
                        content.Add(line);
                        line = "    maxTextureSize: " + maxSize;
                        content.Add(line);
                        line = "    textureFormat: " + (int)iosFormat;
                        content.Add(line);
                        line = "    compressionQuality: 50";
                        content.Add(line);
                        line = "  - buildTarget: Android";
                        content.Add(line);
                        line = "    maxTextureSize: " + maxSize;
                        content.Add(line);
                        line = "    textureFormat: " + (int)androidFormat;
                        content.Add(line);
                        line = "    compressionQuality: 50";
                        content.Add(line);
                        line     = targetLine;
                        hasFound = true;
                    }
                    content.Add(line);
                }
                stream.Close();

                if (hasFound)
                {
                    File.Delete(file);
                    StreamWriter writer = new StreamWriter(file);
                    foreach (string s in content)
                    {
                        writer.WriteLine(s);
                    }
                    writer.Close();
                }
            });

            AssetDatabase.Refresh();

            Debug.Log(string.Format("<color=#00FF00>[{0}]资源压缩格式更新完成!</color>", path));
        }