Esempio n. 1
0
        /// <summary>
        /// 根据XMLtable表检查出需要下载的bundle
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public static List <string> GetBundleNeedDownLoadList(AssetBundleTable table, eAssetLanguageVarType lanType)
        {
            var list = new List <string>();

            if (table != null)
            {
                foreach (var x in table.BundleInfos)
                {
                    //检查Persist
                    var has = AssetBundlePathResolver.CheckBundleExistInPersisten(
                        x.GetBundleFileNameWithLangExtension(lanType));
                    //然后检查Stream
                    if (!has)
                    {
                        has = AssetBundlePathResolver.CheckBundleExistInStreaming(
                            x.GetBundleFileNameWithLangExtension(lanType));
                    }
                    if (!has)
                    {
                        list.Add(x.GetBundleFileNameWithLangExtension(lanType));
                    }
                }
            }

            return(list);
        }
Esempio n. 2
0
        public void Merge(AssetBundleTable patch)
        {
            var originLength = BundleInfos.Length;
            var count        = originLength + patch.BundleInfos.Length;

            Array.Resize(ref BundleInfos, count);
            Array.Copy(patch.BundleInfos, 0, BundleInfos,
                       originLength, patch.BundleInfos.Length);
        }
Esempio n. 3
0
        //解析配表
        private bool ParseBundleConfig(string cfgStr)
        {
            try
            {
                var table = cfgStr.FromXML <AssetBundleTable>();
                if (table != null)
                {
                    _table = table;
                    _abNameToData.Clear();
                    _resPathTofullAssetPathData.Clear();
                    _resNameToBundleName.Clear();

                    //将XML配置转换到系统内置信息
                    foreach (var x in table.BundleInfos)
                    {
                        var xbundleMD5Name = x.bundleNameMD5Struct.GetMD5Str(!x.isComplexName);
                        if (!_abNameToData.TryGetValue(xbundleMD5Name, out var abd))
                        {
                            abd = new AssetBundleData
                            {
                                bundleName      = xbundleMD5Name,
                                bundleFileName  = x.bundleFileName,
                                bundleHashName  = x.bundleNameMD5Struct,
                                dependency      = x.dependenceBundleName ?? new string[0],
                                assetsInfo      = new AssetBundleAssetData[x.assets.Length],
                                bundleLanguages = x.bundleLanguages
                            };


                            for (var i = 0; i < x.assets.Length; i++)
                            {
                                var ass = new AssetBundleAssetData
                                {
                                    resPath       = x.assets[i].resPath,
                                    assetFullName = x.assets[i].assetFullName
                                };
                                abd.assetsInfo[i] = ass;

                                _resPathTofullAssetPathData[ass.resPath] = ass.assetFullName;
                                _resNameToBundleName[ass.resPath]        = xbundleMD5Name;
                            }

                            _abNameToData[abd.bundleName] = abd;
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                CommonLog.Error(e);
                return(false);
            }
        }
Esempio n. 4
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生成完成"));
        }