예제 #1
0
 private void GetDirSetting(string relPath)
 {
     if (!string.IsNullOrEmpty(relPath))
     {
         string path = AMTool.GetAbsPath(relPath);
         if (!Directory.Exists(path))
         {
             return;
         }
         Dictionary <string, TextureSetting> dict = new Dictionary <string, TextureSetting>();
         TextureSetting root = TextureSettings.Find(t => t.RelPath.Equals(relPath));
         if (root == null)
         {
             var setting = new TextureSetting();
             setting.RelPath = relPath;
             dict.Add(path, setting);
             TextureSettings.Add(dict[path]);
         }
         else
         {
             AMTool.GetCurrentSetting(root, dict);
         }
         AMTool.LoadDirSetting(path, dict);
     }
 }
예제 #2
0
파일: Checker.cs 프로젝트: atom-chen/luxa
        static void Open()
        {
            //var window = GetWindow<Checker>();
            List <string> fs    = new List <string>();
            var           guids = Selection.assetGUIDs;

            for (int i = 0; i < guids.Length; i++)
            {
                string path = AssetDatabase.GUIDToAssetPath(guids[i]);
                fs.AddRange(Directory.GetFiles(path, "*.*", SearchOption.AllDirectories));
            }
            fs.RemoveAll(f => {
                string ext = Path.GetExtension(f);
                return(ext.Equals(".meta") || ext.Equals(".fbx") || ext.Equals(".FBX") ||
                       ext.Equals(".mat") || ext.Equals(".prefab"));
            });
            Dictionary <string, string> dict = new Dictionary <string, string>();

            foreach (var item in fs)
            {
                string name = Path.GetFileName(item);
                if (!dict.ContainsKey(name))
                {
                    dict.Add(name, item);
                }
            }
            foreach (var item in dict)
            {
                fs.Remove(item.Value);
            }

            Debug.LogError(AMTool.List2String(fs));
        }
예제 #3
0
        private void CheckValidRootPath()
        {
            var valids = ValidRootPaths;

            TextureSettings.RemoveAll(s =>
            {
                string relPath = AMTool.GetUnityPath(s.Path);
                return(!valids.Contains(relPath));
            });
        }
예제 #4
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();
            }
        }
예제 #5
0
        public void SetMenuTree(OdinMenuTree tree)
        {
            TextureImpoterCfg.Instance.Load();
            var texImporterView = new TextureImpoterView();

            tree.Add(TAB_TEXTURE, texImporterView, EditorIcons.SettingsCog);
            var dict = AMTool.GetDictionary(TextureImpoterCfg.Instance.TextureSettings);

            foreach (var item in dict)
            {
                string path = item.Key.Replace(Application.dataPath, TAB_TEXTURE);
                tree.Add(path, item.Value);
            }

            tree.Selection.SelectionChanged -= OnSelectionItemChange;
            tree.Selection.SelectionChanged += OnSelectionItemChange;
        }
예제 #6
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();
        }
예제 #7
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);
            }
        }