SetAssetBundleNameAndVariant() private méthode

private SetAssetBundleNameAndVariant ( string assetBundleName, string assetBundleVariant ) : void
assetBundleName string
assetBundleVariant string
Résultat void
Exemple #1
0
    static void MenuRemoveAB()
    {
        AssetDatabase.RemoveUnusedAssetBundleNames();
        List <string> fileList   = new List <string>();
        List <string> fileRemove = new List <string>();

        /// 遍历 目录 操作
        if (null != Selection.objects)
        {
            for (int index = 0; index < Selection.objects.Length; index++)
            {
                if (null != Selection.objects[index])
                {
                    string path = string.Format("{0}/../{1}", Application.dataPath, AssetDatabase.GetAssetPath(Selection.objects[index]));
                    if (System.IO.Directory.Exists(path))
                    {
                        EditorSearchFile.SearchPath(path, fileList, "");
                    }
                    else
                    {
                        fileList.Add(path);
                    }
                }
            }
        }
        /// 资源剔除处理
        RemoveSameAndUnExportAssets(fileList, fileRemove);
        /// 打印 LOG
        for (int index = 0; index < fileList.Count; index++)
        {
            UnityEditor.AssetImporter importer = UnityEditor.AssetImporter.GetAtPath("Assets" + fileList[index].Substring(fileList[index].IndexOf("/Resources-/")));
            if (null == importer)
            {
                continue;
            }

            /// 为空返回
            if (string.IsNullOrEmpty(importer.assetBundleName) && string.IsNullOrEmpty(importer.assetBundleVariant))
            {
                continue;
            }
            /// 设置
            Debug.Log(string.Format("Remove AssetBundle : {0}.{1}", importer.assetBundleName, importer.assetBundleVariant));
            importer.SetAssetBundleNameAndVariant("", "");
            importer.SaveAndReimport();
        }

        for (int index = 0; index < fileRemove.Count; index++)
        {
            UnityEditor.AssetImporter importer = UnityEditor.AssetImporter.GetAtPath("Assets" + fileRemove[index].Substring(fileRemove[index].IndexOf("/Resources-/")));
            if (null == importer)
            {
                continue;
            }
            /// 没设置 返回
            if (string.IsNullOrEmpty(importer.assetBundleName) && string.IsNullOrEmpty(importer.assetBundleVariant))
            {
                continue;
            }
            /// 的是依赖 返回
            if (importer.assetBundleName.StartsWith("d/"))
            {
                continue;
            }
            /// 设置

            Debug.LogError(string.Format("Remove AssetBundle : {0}.{1}", importer.assetBundleName, importer.assetBundleVariant));
            importer.SetAssetBundleNameAndVariant("", "");
            importer.SaveAndReimport();
        }
    }