Esempio n. 1
0
        //=======================
        // 工具函数
        //=======================

        //获取Build信息
        static BuildInfo FetchBuildInfo(string resDir, string searchPattern, BuildType buildType)
        {
            BuildInfo buildInfo = new BuildInfo();

            buildInfo.assetPaths = new List <string>();
            FileInfo[] resFiles = BMEditUtility.GetAllFiles(resDir, searchPattern);
            for (int i = 0; i < resFiles.Length; i++)
            {
                FileInfo fileInfo  = resFiles[i];
                string   lowerName = fileInfo.Name.ToLower();
                string   dirPath   = BMEditUtility.Absolute2Relativity(fileInfo.DirectoryName) + "/";

                //过滤一些文件
                if ((fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                if ((fileInfo.Directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                if (IgnoreFile(lowerName, dirPath))
                {
                    continue;
                }

                string path = dirPath + fileInfo.Name; //相对路径
                if (buildType == BuildType.Lua)
                {
                    string temp = path + "." + BMUtility.EncryptWithMD5(path) + ".bytes";
                    if (File.Exists(temp))
                    {
                        File.Delete(temp);
                    }
                    if (isLuaEncoded)
                    {
                        if (!EncodeLuaFile(path, temp))
                        {
                            Debug.Log("Encode lua file fail!");
                            break;
                        }
                    }
                    else
                    {
                        File.Copy(path, temp);
                    }
                    buildInfo.assetPaths.Add(temp);
                    tempLuaPaths.Add(temp);
                }
                else
                {
                    buildInfo.assetPaths.Add(path);
                }
                //Logger.Log("path:{0}", path);
                EditorUtility.DisplayCancelableProgressBar("Fetch Build Info...", path, (float)(i + 1.0f) / (float)resFiles.Length);
            }
            //EditorUtility.ClearProgressBar();
            if (buildType == BuildType.Lua)
            {
                AssetDatabase.Refresh();
            }
            return(buildInfo);
        }
Esempio n. 2
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.");
        }