private void ConvertDebug()
 {
     for (int i = 0; i < _config.Count; i++)
     {
         TexData td = _config[i];
         if (td.bModify)
         {
             td.bModify = false;
             td.color   = Color.gray;
             StringBuilder sb = new StringBuilder();
             sb.Append(td.mipmap);
             sb.Append(" ");
             sb.Append(td.rw);
             sb.Append(" ");
             sb.Append("Android:");
             sb.Append(" ");
             sb.Append(td.android.maxTextureSize);
             sb.Append(" ");
             sb.Append(td.android.format);
             sb.Append(" ");
             sb.Append(td.android.compressionQuality);
             sb.Append(" ");
             sb.Append("Ios:");
             sb.Append(" ");
             sb.Append(td.ios.maxTextureSize);
             sb.Append(" ");
             sb.Append(td.ios.format);
             sb.Append(" ");
             sb.Append(td.ios.compressionQuality);
             sb.Append(" ");
             Debug.Log(sb.ToString());
         }
     }
 }
        void Init()
        {
            _config       = new List <TexData>();
            _filterConfig = new List <TexData>();
            _filterTexs   = new List <string>();
            texDir        = "";
            matDir        = "";
            TexData td = new TexData("ROOT", -1, 0);

            _config.Add(td);
            bTexOkFilter = true;

            size64 = size128 = size256 = size512 = size1024 = sizeother = true;

            //multi operation
            bMipMap = bRw = false;
            //antFmt = AndroidFormat.ETC2_RGBA8;
            //iosFmt = IosFormat.PVRTC_RGBA4;

            if (m_TreeViewState == null)
            {
                m_TreeViewState = new TreeViewState();
            }

            var treeModel = new TreeModel <TexData>(_config);

            m_TreeView = new TexInfoTreeView(m_TreeViewState, treeModel);
        }
        void DrawItem(List <TexData> texDatas, Color itemBg)
        {
            for (int i = 0; i < texDatas.Count; i++)
            {
                GUILayout.BeginHorizontal();
                Color   oldc = GUI.backgroundColor;
                TexData td   = texDatas[i];
                td.bModify = GUILayout.Toggle(td.bModify, " ", GUILayout.Width(20));
                td.mipmap  = GUILayout.Toggle(td.mipmap, "MipMap", GUILayout.Width(80));
                td.rw      = GUILayout.Toggle(td.rw, "R/W Enabled", GUILayout.Width(100));
                GUILayout.Label(string.Format("{0}x{1}", td.texture.width, td.texture.height), GUILayout.Width(70));

                GUILayout.Label("ANDROID:", GUILayout.Width(70));
                TexSize ts = (TexSize)EditorGUILayout.EnumPopup((TexSize)td.android.maxTextureSize, GUILayout.Width(80));
                td.android.maxTextureSize = (int)ts;
                td.android.format         = (TextureImporterFormat)EditorGUILayout.EnumPopup((AndroidFormat)td.android.format, GUILayout.Width(90));
                CompressQuality cq = (CompressQuality)EditorGUILayout.EnumPopup((CompressQuality)td.android.compressionQuality, GUILayout.Width(60));
                td.android.compressionQuality = (int)cq;

                GUILayout.Label("IOS:", GUILayout.Width(30));
                TexSize ts1 = (TexSize)EditorGUILayout.EnumPopup((TexSize)td.ios.maxTextureSize, GUILayout.Width(80));
                td.ios.maxTextureSize = (int)ts1;
                td.ios.format         = (TextureImporterFormat)EditorGUILayout.EnumPopup((IosFormat)td.ios.format, GUILayout.Width(90));
                CompressQuality cq1 = (CompressQuality)EditorGUILayout.EnumPopup((CompressQuality)td.ios.compressionQuality, GUILayout.Width(60));
                td.ios.compressionQuality = (int)cq1;


                var align = GUI.skin.button.alignment;
                GUI.skin.button.alignment = TextAnchor.MiddleLeft;
                GUI.backgroundColor       = itemBg;
                if (GUILayout.Button(td.ti.assetPath))
                {
                    Selection.activeObject = td.texture;
                }
                GUI.backgroundColor       = oldc;
                GUI.skin.button.alignment = align;
                GUILayout.EndHorizontal();
            }
        }
        //获取除cubemap以外的所有纹理
        //默认过滤安卓etc2 和ios pvrtc的贴图
        void GetTexList()
        {
            _config.Clear();
            _filterConfig.Clear();
            _filterTexs.Clear();
            TexData _td_temp = new TexData("ROOT", -1, 0);

            _config.Add(_td_temp);
            if (!string.IsNullOrEmpty(matDir))
            {
                string[] ids   = AssetDatabase.FindAssets("t:Material", new string[] { matDir });
                int      index = 0;
                foreach (var id in ids)
                {
                    string   matPath   = AssetDatabase.GUIDToAssetPath(id);
                    Material mat       = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
                    int      propCount = ShaderUtil.GetPropertyCount(mat.shader);
                    for (int i = 0; i < propCount; i++)
                    {
                        if (ShaderUtil.GetPropertyType(mat.shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                        {
                            string  propertyName = ShaderUtil.GetPropertyName(mat.shader, i);
                            Texture tex          = mat.GetTexture(propertyName);
                            if (tex == null)
                            {
                                continue;
                            }
                            string _tex = AssetDatabase.GetAssetPath(tex.GetInstanceID());
                            string ext  = System.IO.Path.GetExtension(_tex).ToLower();
                            if (ext.Equals(".cubemap"))
                            {
                                continue;
                            }

                            TexData td;
                            td         = new TexData("ROOT", 0, index++);
                            td.bModify = false;
                            td.texture = tex;
                            td.ti      = AssetImporter.GetAtPath(_tex) as TextureImporter;
                            td.android = td.ti.GetPlatformTextureSettings("Android");
                            td.ios     = td.ti.GetPlatformTextureSettings("iPhone");
                            td.mipmap  = td.ti.mipmapEnabled;
                            td.rw      = td.ti.isReadable;
                            td.color   = Color.red;
                            _filterConfig.Add(td);
                            _filterTexs.Add(_tex);
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(texDir))
            {
                string[] ids   = AssetDatabase.FindAssets("t:Texture", new string[] { texDir });
                int      index = 1;
                foreach (var id in ids)
                {
                    string texPath = AssetDatabase.GUIDToAssetPath(id);
                    if (_filterTexs.Contains(texPath))
                    {
                        continue;
                    }
                    string ext = System.IO.Path.GetExtension(texPath).ToLower();
                    if (ext.Equals(".cubemap") | ext.Equals(".rendertexture"))
                    {
                        continue;
                    }
                    TexData td;
                    td = new TexData("ROOT", 0, index++);

                    td.bModify = false;
                    td.texture = AssetDatabase.LoadAssetAtPath(texPath, typeof(Texture)) as Texture;
                    td.ti      = AssetImporter.GetAtPath(texPath) as TextureImporter;
                    td.android = td.ti.GetPlatformTextureSettings("Android");
                    td.ios     = td.ti.GetPlatformTextureSettings("iPhone");
                    bool bPass = false;

                    //如果mipmap开启 或者rw开启 一定要显示出来(默认规则)
                    bool bWastedMem = false;
                    if (td.ti.mipmapEnabled | td.ti.isReadable)
                    {
                        bWastedMem = true;
                    }

                    if ((td.android.format == TextureImporterFormat.ETC2_RGB4 | td.android.format == TextureImporterFormat.ETC2_RGBA8) &&
                        (td.ios.format == TextureImporterFormat.PVRTC_RGB4 | td.ios.format == TextureImporterFormat.PVRTC_RGBA4))
                    {
                        bPass = true;
                    }
                    if (bPass && bTexOkFilter && !bWastedMem)
                    {
                        index--;
                        continue;
                    }

                    //尺寸过滤
                    if (!FilterSize(td.texture) && !bWastedMem)
                    {
                        index--;
                        continue;
                    }

                    td.mipmap = td.ti.mipmapEnabled;
                    td.rw     = td.ti.isReadable;
                    td.color  = new Color(169 / 255f, 212 / 255f, 115 / 255f, 1f);
                    if (td.ti != null)
                    {
                        _config.Add(td);
                    }
                    else
                    {
                        Debug.LogError(texPath);
                    }
                }
            }
        }
        private void DoConvert()
        {
            int convertCount = 0;

            foreach (var item in _config)
            {
                if (item.bModify && item.texture != null)
                {
                    convertCount++;
                }
            }
            int ok = 0;

            for (int i = 0; i < _config.Count; i++)
            {
                TexData td = _config[i];
                if (td.bModify && td.texture != null)
                {
                    EditorUtility.DisplayProgressBar("纹理转换", td.ti.assetPath, ok++ / (float)convertCount);
                    td.bModify          = false;
                    td.color            = Color.gray;
                    td.ti.mipmapEnabled = td.mipmap;
                    td.ti.isReadable    = td.rw;
                    AndroidFormat androidFmt = (AndroidFormat)td.android.format;
                    IosFormat     iosFmt     = (IosFormat)td.ios.format;
                    //智能格式转换 - Normal不要alpha unity说没alpha 就不设置alpha
                    if (td.ti.textureType == TextureImporterType.NormalMap | !TextureHasAlpha(td.ti))
                    {
                        if (androidFmt == AndroidFormat.RGBA32)
                        {
                            androidFmt = AndroidFormat.RGB24;
                        }
                        else if (androidFmt == AndroidFormat.RGBA16)
                        {
                            androidFmt = AndroidFormat.RGB16;
                        }
                        else if (androidFmt == AndroidFormat.ETC2_RGBA8)
                        {
                            androidFmt = AndroidFormat.ETC2_RGB4;
                        }
                        if (iosFmt == IosFormat.RGBA32)
                        {
                            iosFmt = IosFormat.RGB24;
                        }
                        else if (iosFmt == IosFormat.RGBA16)
                        {
                            iosFmt = IosFormat.RGB16;
                        }
                        else if (iosFmt == IosFormat.PVRTC_RGBA4)
                        {
                            iosFmt = IosFormat.PVRTC_RGB4;
                        }
                        else if (iosFmt == IosFormat.ASTC_RGBA_4x4)
                        {
                            iosFmt = IosFormat.ASTC_RGB_4x4;
                        }
                        else if (iosFmt == IosFormat.ASTC_RGBA_6x6)
                        {
                            iosFmt = IosFormat.ASTC_RGB_6x6;
                        }
                    }
                    if (bModifyAndroid)
                    {
                        td.ti.SetPlatformTextureSettings("Android", td.android.maxTextureSize, (TextureImporterFormat)androidFmt, td.android.compressionQuality, false);
                    }
                    if (bModifyIOS)
                    {
                        td.ti.SetPlatformTextureSettings("iPhone", td.ios.maxTextureSize, (TextureImporterFormat)iosFmt, td.ios.compressionQuality, false);
                    }
                    AssetDatabase.ImportAsset(td.ti.assetPath);
                    EditorUtility.ClearProgressBar();
                }
            }
        }