Example #1
0
        private void CheckValidRootPath()
        {
            var valids = ValidRootPaths;

            TextureSettings.RemoveAll(s =>
            {
                string relPath = AMTool.GetUnityPath(s.Path);
                return(!valids.Contains(relPath));
            });
        }
Example #2
0
        /// <summary>
        /// 按照配置重新导入资源
        /// </summary>
        public override void DoHandle()
        {
            base.DoHandle();

            if (!IsActive)
            {
                return;
            }

            List <string>  files  = AMTool.GetTextures(Path);
            TextureSetting parent = Parent as TextureSetting;

            if (Parent == null || Parent.IsNull)
            {
                IsOverride &= true;
            }
            for (int i = 0; i < files.Count; i++)
            {
                string          refPath  = AMTool.GetUnityPath(files[i]);
                TextureImporter importer = AssetImporter.GetAtPath(refPath) as TextureImporter;
                //importer.ClearPlatformTextureSettings(STANDALONE);
                //importer.ClearPlatformTextureSettings(ANDROID);
                //importer.ClearPlatformTextureSettings(IPHONE);
                TextureImporterSettings importerSetting = new TextureImporterSettings();
                importer.ReadTextureSettings(importerSetting);

                importer.textureType         = TextureType;
                importer.npotScale           = TextureNPOT;
                importer.isReadable          = IsReadable;
                importer.alphaIsTransparency = IsTransparency;
                importer.mipmapEnabled       = GenerateMipmap;
                importer.wrapMode            = WrapMode;
                importer.filterMode          = Filter;
                importer.anisoLevel          = AnisoLevel;

                importer.SetPlatformTextureSettings(STANDALONE, WindowMaxSize, WindowImporterFormat, CompressionQuality, false);
                importer.SetPlatformTextureSettings(ANDROID, AndroidMaxSize, AndroidImporterFormat, CompressionQuality, false);
                importer.SetPlatformTextureSettings(IPHONE, IOSMaxSize, IOSImporterFormat, CompressionQuality, false);

                importer.SaveAndReimport();
                EditorUtility.DisplayProgressBar("按配置导入纹理", refPath, (i + 1f) / files.Count);
            }
            foreach (var item in Children)
            {
                item.DoHandle();
            }
        }
Example #3
0
        //-------特殊导入方案
        /// <summary>
        /// 检查当前设置是否适合包含的资源
        /// </summary>
        public void CheckSettingIllegel()
        {
            Dictionary <string, TextureSetting> dict = AMTool.GetDictionary(TextureSettings);
            float         count          = 0;
            StringBuilder nullBuilder    = new StringBuilder();
            StringBuilder illegelBuilder = new StringBuilder();

            foreach (var item in dict)
            {
                EditorUtility.DisplayProgressBar("检查", item.Value.RelPath, count++ / dict.Count);
                if (item.Value.Children.Count > 0 || !item.Value.IsActive)
                {
                    continue;
                }

                bool hasAlpha = item.Value.AndroidImporterFormat == TextureImporterFormat.ETC2_RGBA8 ||
                                item.Value.IOSImporterFormat == TextureImporterFormat.PVRTC_RGBA4;
                string[] fs = Directory.GetFiles(AMTool.GetAbsPath(item.Value.RelPath), "*.*", SearchOption.TopDirectoryOnly);
                foreach (var f in fs)
                {
                    if (Path.GetExtension(f).Equals(".meta"))
                    {
                        continue;
                    }

                    string          relPath  = AMTool.GetUnityPath(f);
                    TextureImporter importer = AssetImporter.GetAtPath(relPath) as TextureImporter;
                    if (importer == null)
                    {
                        nullBuilder.AppendLine(relPath);
                        continue;
                    }
                    if (importer.DoesSourceTextureHaveAlpha() == hasAlpha)
                    {
                        continue;
                    }

                    illegelBuilder.AppendLine(relPath);
                }
            }
            Debug.LogError(illegelBuilder.ToString());
            Debug.LogError("---------------TextureImporter-NULL----------------");
            Debug.LogError(nullBuilder.ToString());
            EditorUtility.ClearProgressBar();
        }
Example #4
0
        /// <summary>
        /// 加载目录树形结构
        /// </summary>
        public static void LoadDirSetting <T>(string parent, Dictionary <string, T> dict) where T : DirectorySetting <T>, new()
        {
            if (dict != null && dict.Count == 0)
            {
                Debug.LogError("字典中必须包含根节点的数据!");
                return;
            }

            //---对子对象进行操作
            List <string> ds = new List <string>();

            ds.AddRange(Directory.GetDirectories(parent, "*", SearchOption.TopDirectoryOnly));
            ds = AMTool.StandardlizeList(ds);
            if (dict.ContainsKey(parent))
            {
                //移除不存在目录
                HashSet <string> hash0 = new HashSet <string>(dict.Keys);
                hash0.ExceptWith(ds);
                foreach (var path in hash0)
                {
                    dict[parent].Children.Remove(dict[path]);
                }
            }

            //处理新增目录
            HashSet <string> hash = new HashSet <string>(ds);

            hash.ExceptWith(dict.Keys);
            foreach (var path in hash)
            {
                var setting = new T();
                setting.RelPath = AMTool.GetUnityPath(path);
                setting.Parent  = dict[parent];
                dict[parent].Children.Add(setting);
                dict.Add(path, setting);
                LoadDirSetting(path, dict);
            }
        }