Exemplo n.º 1
0
        private void PrepareDownloads(FileMapSystem.FileMapSystem newMap, string versionStr)
        {
            if (_downloader != null)
            {
                _downloader.Release();
                _downloader = null;
            }

            _downloader = new HttpFileDownloader(new Uri(GetDownloadBaseURL(versionStr)),
                                                 AssetBundlePathResolver.BundleSaveDirName);
            var currentMap = AssetBundleManager.Instance.GetFileMapSystem();
            var misses     = currentMap.GetMissFileMaps(newMap);

            _currentDownloadingGroupDesc = misses;
            CommonLog.Log(MAuthor.WY, $"{misses.Count} files miss in current file map");

            foreach (var fileMapGroupDescIter in misses)
            {
                var fileName     = fileMapGroupDescIter.Key;
                var desc         = fileMapGroupDescIter.Value;
                var fileSavePath = _savePath + fileName;

                if (File.Exists(fileSavePath))
                {
                    var bytes = FileUtils.ReadAllBytes(fileSavePath);
                    if (bytes != null && bytes.Length > 0)
                    {
                        var md5 = MD5Creater.Md5Struct(bytes);
                        if (md5.MD51 == desc.Md51 && md5.MD52 == desc.Md52)
                        {
                            CommonLog.Log(MAuthor.WY, $"file {fileSavePath} already exist, skip");
                            continue;
                        }
                    }
                }

                _downloader.AddDownLoad(new WWWFileDownloader.DownloadFileInfo
                {
                    FileName           = fileName,
                    FileSize           = desc.Len,
                    MapedFileName_MD51 = desc.Md51,
                    MapedFileName_MD52 = desc.Md52,
                });
            }
        }
Exemplo n.º 2
0
        public virtual void End(AssetBundleManifest manifest, bool addPacker = false)
        {
            //生成TableBundle信息
            XMLTable = new AssetBundleTable();

            XMLTable.GenBundleInfoFromRaw(AssetBundleRawInfoList);

            //刷新XML数据
            RefreshXMLTableByManifest(manifest);

            var abMainifestName = System.IO.Path.GetFileName(BundleSavePath.Substring(0, BundleSavePath.Length - 1));

            //删了主AB包
            FileUtils.DeleteFile(BundleSavePath + abMainifestName);
            //删了无用的manifest
            //FileUtils.DeleteFiles(BundleSavePath(), SearchOption.TopDirectoryOnly, ".manifest");

            //重命名所有Bundle
            //foreach (var info in XMLTable.BundleInfos)

            for (int index = 0; index < XMLTable.BundleInfos.Length; index++)
            {
                var bunldeInfo = XMLTable.BundleInfos[index];
                for (int i = 0; i < bunldeInfo.bundleLanguages.Length; i++)
                {
                    if (bunldeInfo.bundleLanguages[i])
                    {
                        if (!FileUtils.IsFileExist(BundleSavePath + bunldeInfo.GetBundleNameWithLangExtension((eAssetLanguageVarType)i)))
                        {
                            CommonLog.Error("找不到打包后的资源:" + bunldeInfo.assets[0].assetFullName);
                            continue;
                        }

                        //是否增量打Bundle
                        if (addPacker)
                        {
                            string sourceFilePath = BundleSavePath + bunldeInfo.GetBundleNameWithLangExtension((eAssetLanguageVarType)i);
                            string targetFilePath = BundleSavePath + bunldeInfo.GetBundleFileNameWithLangExtension((eAssetLanguageVarType)i);
                            if (!sourceFilePath.Equals(targetFilePath))
                            {
                                if (File.Exists(targetFilePath))
                                {
                                    File.Delete(targetFilePath);
                                }

                                File.Copy(BundleSavePath + bunldeInfo.GetBundleNameWithLangExtension((eAssetLanguageVarType)i),
                                          BundleSavePath + bunldeInfo.GetBundleFileNameWithLangExtension((eAssetLanguageVarType)i), true);
                            }
                        }
                        else
                        {
                            FileUtils.RenameFile(BundleSavePath, bunldeInfo.GetBundleNameWithLangExtension((eAssetLanguageVarType)i),
                                                 bunldeInfo.GetBundleFileNameWithLangExtension((eAssetLanguageVarType)i));
                        }
                    }
                }

                //计算Bundle的MD5
                var assetBundleBytes = FileUtils.ReadAllBytes($"{BundleSavePath}/{bunldeInfo.bundleFileName}");
                if (assetBundleBytes != null && assetBundleBytes.Length > 0)
                {
                    var md5Str = MD5Creater.Md5Struct(assetBundleBytes).GetMD5Str(false);
                    bunldeInfo.bundleMD5 = md5Str;
                }
            }

            //TODO 写上版本号

            string xml = XMLTable.ToXML();

            File.WriteAllText(BundleSavePath + AssetBundlePathResolver.DependFileName, xml);

            EditorUtility.ClearProgressBar();

            CommonLog.Warning(string.Format("热更新XML生成完成"));
        }
Exemplo n.º 3
0
    private static List <AssetBundleXMLRawData> RefreshNewNameAndGetAssetBundleList()
    {
        List <AssetBundleXMLRawData> list = new List <AssetBundleXMLRawData>();
        //非Default的资源
        List <AssetBundleXMLRawData> foreignlist = new List <AssetBundleXMLRawData>();

        bool checkConfig = AssetBundleBuilderExtSetting.Instance.InitProjectSettingFromFile();

        if (!checkConfig)
        {
            return(null);
        }

        var paths = AssetDatabase.GetAllAssetPaths();

        bool isBreak = false;

        for (int i = 0; i < paths.Length; i++)
        {
            var path = paths[i];

            if (!path.Contains("."))
            {
                continue;
            }

            //不需要打包的文件类型
            if (!CheckNeedPackFile(path))
            {
                continue;
            }

            if (!path.Contains("/AssetBundles/") &&
                !AssetBundleBuilderExtSetting.Instance.CheckIsInExtFolderAsset(path) &&
                !AssetBundleBuilderExtSetting.Instance.CheckIsSpriteInTagAsset(path))
            {
                continue;
            }

            //if (!path.Contains("/AssetBundles/")) continue;

            //不导文件夹
            if (AssetDatabase.IsValidFolder(path))
            {
                continue;
            }

            //是否取消打包
            isBreak = EditorUtility.DisplayCancelableProgressBar("Loading", path, (float)i / paths.Length);
            if (isBreak)
            {
                CommonLog.Log("终止打包");
                return(null);
            }

            AssetBundleXMLRawData xmlRawData = new AssetBundleXMLRawData();

            var extensionName =
                Path.GetExtension(path); //path.Remove(0,path.LastIndexOf(".", StringComparison.Ordinal));
            var withoutExtensionPath =
                path.Replace(extensionName,
                             string.Empty); //path.Substring(0, path.LastIndexOf(".", StringComparison.Ordinal));


            int abResourceStartIndex = withoutExtensionPath.LastIndexOf("AssetBundles", StringComparison.Ordinal);
            var resPath = AssetI8NHelper.GetDefaultPathLanguage(abResourceStartIndex >= 0
                ? withoutExtensionPath.Substring(abResourceStartIndex)
                : withoutExtensionPath);

            //剔除 Assets/
            if (resPath.StartsWith("Assets/"))
            {
                int startIndex = resPath.IndexOf("/", StringComparison.Ordinal) + 1;
                resPath = resPath.Substring(startIndex);
            }

            var langType = AssetI8NHelper.GetPathLanguage(path);

            xmlRawData.resPath = resPath;

            xmlRawData.resPathMD5Struct = MD5Creater.Md5Struct(xmlRawData.resPath);

            xmlRawData.Language = langType;

            string fileName   = Path.GetFileNameWithoutExtension(resPath);
            string bundleName =
                Path.GetDirectoryName(resPath.Substring(0, resPath.LastIndexOf("/", StringComparison.Ordinal)));

            //设置bundleName,使用时,使用下面的MD5
            xmlRawData.bundleName =
                AssetBundleBuilderExtSetting.Instance.GetGroupMappedBundlePath(xmlRawData.resPath, extensionName);

            xmlRawData.bundleMD5Struct =
                MD5Creater.Md5Struct(
                    AssetBundleBuilderExtSetting.Instance.GetGroupMappedBundlePath(xmlRawData.resPath, extensionName));

            //fullName带后缀名
            //int assetStartIndex = path.IndexOf("Assets", StringComparison.Ordinal);
            xmlRawData.assetFullName = path; //path.Substring(assetStartIndex);

            //int resStartIndex = resPath.LastIndexOf("/", StringComparison.Ordinal) + 1;
            xmlRawData.resShortName = Path.GetFileName(resPath); //resPath.Substring(resStartIndex);

            xmlRawData.OtherLanguages[(int)langType] = true;
            list.Add(xmlRawData);

            foreignlist.Add(xmlRawData);
        }

        //第二遍开始计算asset的多语言信息
        foreach (var xmlRaw in list)
        {
            if (xmlRaw.Language == eAssetLanguageVarType.Default)
            {
                foreach (var xmlForeign in foreignlist)
                {
                    if (xmlForeign.bundleName == xmlRaw.bundleName)
                    {
                        xmlRaw.OtherLanguages[(int)xmlForeign.Language] = true;
                    }
                }
            }
        }


        return(list);
    }