Ejemplo n.º 1
0
        static void FormatPathRecursively(string path, List <string> ignoreList, FormatPathPair fpp, TFormatterPlatform platform, bool origin = false)
        {
            string        platformName = TextureFormat.GetPlatformName(platform);
            TextureFormat tf           = fpp.GetFormatByPlatform((int)platform);

            path = path.Replace('\\', '/');
            for (int k = 0; k < ignoreList.Count; k++)
            {
                if (ignoreList[k] == path && !origin)
                {
                    return;
                }
            }
            TextureImporterFormat tif = tf.format;
            bool      advanced        = tif > 0;
            ApplyData ad = new ApplyData(path, ignoreList, fpp);

            ad.tf           = tf;
            ad.advanced     = advanced;
            ad.platformName = platformName;
            ApplyImporter importerHandler = null;

            switch (fpp.iType)
            {
            case ImporterType.Texture:
                importerHandler = ApplyTextureImporter;
                break;

            case ImporterType.Model:
                importerHandler = ApplyModelImporter;
                break;

            case ImporterType.Audio:
                importerHandler = ApplyAudioImporter;
                break;
            }
            if (Directory.Exists(path))
            {
                ad.needToCheck = true;
                DirectoryInfo   di    = new DirectoryInfo(path);
                FileInfo[]      files = di.GetFiles();
                DirectoryInfo[] dis   = di.GetDirectories();
                foreach (FileInfo fi in files)
                {
                    int    index     = fi.FullName.IndexOf("Assets");
                    string assetPath = fi.FullName.Substring(index);
                    assetPath    = assetPath.Replace('\\', '/');
                    ad.assetPath = assetPath;
                    importerHandler(ad);
                }
                foreach (DirectoryInfo idi in dis)
                {
                    FormatPathRecursively(idi.FullName.Substring(idi.FullName.IndexOf("Assets")), ignoreList, fpp, platform);
                }
            }
            else if (File.Exists(path))
            {
                importerHandler(ad);
            }
        }
Ejemplo n.º 2
0
        static void ApplyTextureImporter(ApplyData ad)
        {
            string          assetPath    = ad.assetPath;
            List <string>   ignoreList   = ad.ignoreList;
            TextureFormat   tf           = ad.tf;
            FormatPathPair  fpp          = ad.fpp;
            bool            advanced     = ad.advanced;
            string          platformName = ad.platformName;
            bool            needToCheck  = ad.needToCheck;
            TextureImporter ti           = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if (ti != null)
            {
                if (needToCheck)
                {
                    for (int k = 0; k < ignoreList.Count; k++)
                    {
                        if (ignoreList[k] == assetPath)
                        {
                            return;
                        }
                    }
                }

                if (string.IsNullOrEmpty(platformName))
                {
                    for (int j = 0; j < 3; j++)
                    {
                        tf           = fpp.GetFormatByPlatform(j);
                        platformName = platforms[j];
                        if (!fpp.Compare(ti, tf, platformName))
                        {
                            fpp.Apply(ti, tf, platformName);
                            if (!reimportList.Contains(assetPath))
                            {
                                reimportList.Add(assetPath);
                            }
                        }
                    }
                }
                else
                {
                    if (!fpp.Compare(ti, tf, platformName))
                    {
                        fpp.Apply(ti, tf, platformName);
                        if (!reimportList.Contains(assetPath))
                        {
                            reimportList.Add(assetPath);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static void ApplyAudioImporter(ApplyData ad)
        {
            string         assetPath    = ad.assetPath;
            List <string>  ignoreList   = ad.ignoreList;
            TextureFormat  tf           = ad.tf;
            FormatPathPair fpp          = ad.fpp;
            bool           advanced     = ad.advanced;
            string         platformName = ad.platformName;
            bool           needToCheck  = ad.needToCheck;
            AudioImporter  ai           = AssetImporter.GetAtPath(assetPath) as AudioImporter;

            if (ai != null)
            {
                if (needToCheck)
                {
                    for (int k = 0; k < ignoreList.Count; k++)
                    {
                        if (ignoreList[k] == assetPath)
                        {
                            return;
                        }
                    }
                }

                AudioImporterSampleSettings aiss;
                if (string.IsNullOrEmpty(platformName))
                {
                    for (int j = 0; j < 3; j++)
                    {
                        tf           = fpp.GetFormatByPlatform(j);
                        platformName = audioPlatforms[j];
                        if (ai.ContainsSampleSettingsOverride(platformName))
                        {
                            aiss = ai.GetOverrideSampleSettings(platformName);
                            if (aiss.loadType != tf.loadType || !ai.forceToMono)
                            {
                                aiss.loadType  = tf.loadType;
                                ai.forceToMono = true;
                                if (!reimportList.Contains(assetPath))
                                {
                                    reimportList.Add(assetPath);
                                }
                            }
                        }
                        else if (ai.defaultSampleSettings.loadType != tf.loadType || !ai.forceToMono)
                        {
                            ai.forceToMono = true;
                            aiss           = ai.defaultSampleSettings;
                            aiss.loadType  = tf.loadType;
                            ai.SetOverrideSampleSettings(platformName, aiss);
                            if (!reimportList.Contains(assetPath))
                            {
                                reimportList.Add(assetPath);
                            }
                        }
                    }
                }
                else
                {
                    if (platformName == platforms[2])
                    {
                        platformName = "iOS";
                    }
                    if (ai.ContainsSampleSettingsOverride(platformName))
                    {
                        aiss = ai.GetOverrideSampleSettings(platformName);
                        if (aiss.loadType != tf.loadType || !ai.forceToMono)
                        {
                            ai.forceToMono = true;
                            aiss.loadType  = tf.loadType;
                            ai.SetOverrideSampleSettings(platformName, aiss);
                            if (!reimportList.Contains(assetPath))
                            {
                                reimportList.Add(assetPath);
                            }
                        }
                    }
                    else if (ai.defaultSampleSettings.loadType != tf.loadType || !ai.forceToMono)
                    {
                        ai.forceToMono = true;
                        aiss           = ai.defaultSampleSettings;
                        aiss.loadType  = tf.loadType;
                        ai.SetOverrideSampleSettings(platformName, aiss);
                        if (!reimportList.Contains(assetPath))
                        {
                            reimportList.Add(assetPath);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        void OnGUI()
        {
            try
            {
                scrollPos = GUILayout.BeginScrollView(scrollPos);
                GUILayout.Label("默认格式:");
                setting.standaloneDefault = (TextureImporterFormat)EditorGUILayout.EnumPopup("StandAlone", (StandAloneCompress)setting.standaloneDefault);
                setting.androidDefault    = (TextureImporterFormat)EditorGUILayout.EnumPopup("Android", (AndroidCompress)setting.androidDefault);
                setting.iosDefault        = (TextureImporterFormat)EditorGUILayout.EnumPopup("IOS", (IosCompress)setting.iosDefault);
                GUILayout.BeginHorizontal();
                GUILayout.Label("平台设置选择:");
                toolBar = GUILayout.Toolbar(toolBar, platforms);
                GUILayout.EndHorizontal();
                if (toolBar != editPlatform)
                {
                    editPlatform = toolBar;
                    OnPlatformChange();
                }
                for (int i = 0; i < curtf.Count; i++)
                {
                    FormatPathPair fpp = curtf[i];
                    ItemState      its = stateList[i];
                    TextureFormat  tf  = fpp.GetFormatByPlatform(editPlatform);
                    GUILayout.BeginVertical("box");
                    GUILayout.BeginHorizontal();
                    GUI.backgroundColor = Color.red;
                    if (GUILayout.Button("X", GUILayout.MaxWidth(20)))
                    {
                        curtf.RemoveAt(i);
                        stateList.RemoveAt(i);
                        return;
                    }
                    GUI.backgroundColor = Color.white;
                    if (its.rename)
                    {
                        fpp.name            = GUILayout.TextField(fpp.name, GUILayout.MaxWidth(100));
                        GUI.backgroundColor = Color.yellow;
                        if (GUILayout.Button("R", GUILayout.MaxWidth(20)))
                        {
                            its.rename = false;
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    else
                    {
                        Rect rect = EditorGUILayout.BeginHorizontal("Button", GUILayout.MaxWidth(120));
                        if (GUI.Button(rect, GUIContent.none))
                        {
                            its.expand = !its.expand;
                        }
                        GUILayout.Label(its.expand ? "-" : "+");
                        GUILayout.Label(fpp.name);
                        GUILayout.Label("");
                        EditorGUILayout.EndHorizontal();
                        GUI.backgroundColor = Color.yellow;
                        if (GUILayout.Button("R", GUILayout.MaxWidth(20)))
                        {
                            its.rename = true;
                        }
                        GUI.backgroundColor = Color.white;
                    }

                    fpp.iType = (ImporterType)EditorGUILayout.EnumPopup(fpp.iType);
                    if (fpp.iType == ImporterType.Texture)
                    {
                        tf.format = (TextureImporterFormat)EditorGUILayout.EnumPopup(TextureFormat.GetPlatformEnum(editPlatform, (int)tf.format));
                    }
                    GUI.backgroundColor = Color.blue;
                    if (GUILayout.Button("Apply", GUILayout.MaxWidth(43)))
                    {
                        List <FormatPathPair> applyList = new List <FormatPathPair>();
                        applyList.Add(fpp);
                        Format(applyList, (TFormatterPlatform)editPlatform);
                        return;
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();
                    if (its.expand)
                    {
                        switch (fpp.iType)
                        {
                        case ImporterType.Texture:
                            DrawTextureSettingItem(tf, fpp);
                            break;

                        case ImporterType.Model:
                            DrawModelSettingItem(tf, fpp);
                            break;

                        case ImporterType.Audio:
                            DrawAudioSettingItem(tf, fpp);
                            break;
                        }
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.Label("", GUILayout.Height(20));
                GUILayout.BeginArea(new Rect(0, position.height - 20 + scrollPos.y, position.width, 20));
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("添加自定义配置"))
                {
                    GUILayout.EndHorizontal();
                    if (scrollPos.y == 0)
                    {
                        GUILayout.EndArea();
                    }
                    GUILayout.EndScrollView();
                    for (int i = 0; i < stateList.Count; i++)
                    {
                        stateList[i].expand = false;
                    }
                    int newIndex = 1;
                    while (!CheckIndexAvailable(newIndex, curtf))
                    {
                        newIndex++;
                    }
                    FormatPathPair fpp = new FormatPathPair(newIndex);
                    curtf.Add(fpp);
                    ItemState its = new ItemState();
                    its.expand = true;
                    stateList.Add(its);
                    return;
                }
                if (GUILayout.Button("保存配置到磁盘"))
                {
                    GUILayout.EndHorizontal();
                    if (scrollPos.y == 0)
                    {
                        GUILayout.EndArea();
                    }
                    GUILayout.EndScrollView();
                    EditorUtility.SetDirty(setting);
                    AssetDatabase.SaveAssets();
                    tmp_setting = (TFormatterSetting)setting.Clone();
                    EditorUtility.DisplayDialog("TextureFormatter", "配置保存成功!", "确定");
                    return;
                }
                if (GUILayout.Button("回滚至磁盘版本"))
                {
                    GUILayout.EndHorizontal();
                    if (scrollPos.y == 0)
                    {
                        GUILayout.EndArea();
                    }
                    GUILayout.EndScrollView();
                    setting.Copy(tmp_setting);
                    return;
                }
                if (GUILayout.Button("应用当前平台配置"))
                {
                    GUILayout.EndHorizontal();
                    if (scrollPos.y == 0)
                    {
                        GUILayout.EndArea();
                    }
                    GUILayout.EndScrollView();
                    Format(setting.formatList, (TFormatterPlatform)editPlatform);
                    return;
                }
                if (GUILayout.Button("应用全平台配置"))
                {
                    GUILayout.EndHorizontal();
                    if (scrollPos.y == 0)
                    {
                        GUILayout.EndArea();
                    }
                    GUILayout.EndScrollView();
                    FormatAll();
                    return;
                }
                GUILayout.EndHorizontal();
                GUILayout.EndArea();
                GUILayout.EndScrollView();
            }
            catch (Exception e)
            {
                Debug.Log(e);
                Close();
            }
        }