Beispiel #1
0
        static void CalcAssetBundleInfos()
        {
            for (int i = 0; i < buildInfoList.Count; i++)
            {
                BuildInfo buildInfo = buildInfoList[i];
                buildInfo.subBuildInfoMap = new Dictionary <string, SubBuildInfo>();
                for (int j = 0; j < buildInfo.assetPaths.Count; j++)
                {
                    string path    = buildInfo.assetPaths[j];
                    string dirName = Path.GetDirectoryName(path);
                    string name;
                    int    version = 0;
                    switch (buildInfo.buildType)
                    {
                    case BuildType.Pack:
                        name = BMUtility.Path2Name(dirName);
                        break;

                    case BuildType.Scene:
                        name = BMUtility.Path2Name(dirName + "/" + Path.GetFileNameWithoutExtension(path));
                        if (scenesVersionDict.TryGetValue(path, out string verStr))
                        {
                            version = int.Parse(verStr);
                        }
                        else
                        {    //新场景
                            version = 1;
                            scenesVersionDict.Add(path, version.ToString());
                            BMEditUtility.SaveDictionary(settings.scenesVersionFile, scenesVersionDict);
                        }
                        break;

                    case BuildType.Shader:
                        name = BMUtility.Path2Name(buildInfo.buildName);
                        break;

                    case BuildType.Lua:
                        name = BMUtility.Path2Name(buildInfo.buildName);
                        break;

                    default:    // BuildType.Single:
                        name = BMUtility.Path2Name(dirName + "/" + Path.GetFileName(path));
                        break;
                    }
                    string       md5     = BMUtility.EncryptWithMD5(name + "." + settings.Suffix_Bundle);
                    SubBuildInfo subInfo = null;
                    if (!buildInfo.subBuildInfoMap.TryGetValue(md5, out subInfo))
                    {
                        string abName = name;
                        if (settings.useHashName)
                        {
                            abName = md5;
                        }
                        subInfo = new SubBuildInfo()
                        {
                            bundleName       = name,
                            buildMd5         = md5,
                            buildType        = buildInfo.buildType,
                            version          = version,
                            assetBundleBuild = new AssetBundleBuild()
                            {
                                assetBundleName    = abName,
                                assetBundleVariant = settings.Suffix_Bundle,
                            },
                            assetPaths        = new List <string>(),
                            assetHashs        = new List <string>(),
                            dependenceMap     = new Dictionary <string, string[]>(),
                            dependenceHashMap = new Dictionary <string, string[]>(),
                        };
                        buildInfo.subBuildInfoMap.Add(md5, subInfo);
                    }
                    //添加依赖关系
                    AddDependence(path, subInfo.dependenceMap);
                    string hash = HashHelper.ComputeMD5(path);
                    subInfo.assetPaths.Add(path.ToLower());
                    subInfo.assetHashs.Add(hash);
                    AssetBundleBuild abb = subInfo.assetBundleBuild;
                    abb.assetNames = subInfo.assetPaths.ToArray();

                    //abb.addressableNames = subInfo.assetPaths.ToArray();
                    subInfo.assetBundleBuild = abb;
                    EditorUtility.DisplayProgressBar("Calc Asset Bundle Build Infos...", path, (float)(j + 1.0f) / (float)buildInfo.assetPaths.Count);
                }
            }
            EditorUtility.ClearProgressBar();


            Logger.Log("Calc Asset Bundle Infos Over.");
        }