コード例 #1
0
        /// <summary>
        /// 2. 创建补丁清单文件到输出目录
        /// </summary>
        private void CreatePatchManifestFile(AssetBundleManifest unityManifest, List <AssetInfo> buildMap, List <string> encryptList)
        {
            string[] allAssetBundles = unityManifest.GetAllAssetBundles();

            // 创建DLC管理器
            DLCManager dlcManager = new DLCManager();

            dlcManager.LoadAllDLC();

            // 加载旧补丁清单
            PatchManifest oldPatchManifest = LoadPatchManifestFile();

            // 创建新补丁清单
            PatchManifest newPatchManifest = new PatchManifest();

            // 写入版本信息
            newPatchManifest.ResourceVersion = BuildVersion;

            // 写入所有AssetBundle文件的信息
            for (int i = 0; i < allAssetBundles.Length; i++)
            {
                string   bundleName = allAssetBundles[i];
                string   path       = $"{OutputDirectory}/{bundleName}";
                string   md5        = HashUtility.FileMD5(path);
                uint     crc32      = HashUtility.FileCRC32(path);
                long     sizeBytes  = EditorTools.GetFileSize(path);
                int      version    = BuildVersion;
                string[] assetPaths = GetBundleAssetPaths(buildMap, bundleName);
                string[] depends    = unityManifest.GetDirectDependencies(bundleName);
                string[] dlcLabels  = dlcManager.GetAssetBundleDLCLabels(bundleName);

                // 创建标记位
                bool isEncrypted = encryptList.Contains(bundleName);
                bool isCollected = IsCollectBundle(buildMap, bundleName);
                int  flags       = PatchElement.CreateFlags(isEncrypted, isCollected);

                // 注意:如果文件没有变化使用旧版本号
                if (oldPatchManifest.Elements.TryGetValue(bundleName, out PatchElement oldElement))
                {
                    if (oldElement.MD5 == md5)
                    {
                        version = oldElement.Version;
                    }
                }

                PatchElement newElement = new PatchElement(bundleName, md5, crc32, sizeBytes, version, flags, assetPaths, depends, dlcLabels);
                newPatchManifest.ElementList.Add(newElement);
            }

            // 写入所有变体信息
            {
                Dictionary <string, List <string> > variantInfos = GetVariantInfos(allAssetBundles);
                foreach (var pair in variantInfos)
                {
                    if (pair.Value.Count > 0)
                    {
                        string        bundleName = $"{pair.Key}.{ PatchDefine.AssetBundleDefaultVariant}";
                        List <string> variants   = pair.Value;
                        newPatchManifest.VariantList.Add(new PatchVariant(bundleName, variants));
                    }
                }
            }

            // 创建新文件
            string filePath = OutputDirectory + $"/{PatchDefine.PatchManifestFileName}";

            Log($"创建补丁清单文件:{filePath}");
            PatchManifest.Serialize(filePath, newPatchManifest);
        }
コード例 #2
0
        /// <summary>
        /// 1. 创建补丁清单文件到输出目录
        /// </summary>
        private void CreatePatchManifestFile(string[] allAssetBundles)
        {
            // 加载旧文件
            PatchManifest patchManifest = LoadPatchManifestFile();

            // 删除旧文件
            string filePath = OutputPath + $"/{PatchDefine.PatchManifestFileName}";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            // 创建新文件
            Log($"创建补丁清单文件:{filePath}");
            using (FileStream fs = File.Create(filePath))
            {
                StreamWriter sw = new StreamWriter(fs);

                // 写入版本信息
                sw.Write(BuildVersion);
                sw.Write("\n");
                sw.Flush();

                // 写入UnityManifest文件的信息
                {
                    string assetName = PatchDefine.UnityManifestFileName;
                    string path      = $"{OutputPath}/{assetName}";
                    string md5       = HashUtility.FileMD5(path);
                    long   sizeBytes = EditorTools.GetFileSize(path);
                    int    version   = BuildVersion;

                    sw.Write($"{assetName}={md5}={sizeBytes}={version}");
                    sw.Write("\n");
                    sw.Flush();
                }

                // 写入所有AssetBundle文件的信息
                foreach (string assetName in allAssetBundles)
                {
                    string path      = $"{OutputPath}/{assetName}";
                    string md5       = HashUtility.FileMD5(path);
                    long   sizeBytes = EditorTools.GetFileSize(path);
                    int    version   = BuildVersion;

                    // 注意:如果文件没有变化使用旧版本号
                    PatchElement element;
                    if (patchManifest.Elements.TryGetValue(assetName, out element))
                    {
                        if (element.MD5 == md5)
                        {
                            version = element.Version;
                        }
                    }

                    sw.Write($"{assetName}={md5}={sizeBytes}={version}");
                    sw.Write("\n");
                    sw.Flush();
                }

                // 关闭文件流
                sw.Close();
                fs.Close();
            }
        }
コード例 #3
0
        private void CreatePatchManifestBytesFile(string[] allAssetBundles, Dictionary <string, List <string> > variantInfos)
        {
            ByteBuffer fileBuffer  = new ByteBuffer(PatchManifest.FileStreamMaxLen);
            ByteBuffer tableBuffer = new ByteBuffer(PatchManifest.TableStreamMaxLen);

            // 加载补丁清单
            PatchManifest oldPatchManifest = LoadPatchManifestFile();

            // 删除旧文件
            string filePath = OutputPath + $"/{PatchDefine.PatchManifestBytesFileName}";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            // 创建新文件
            Log($"创建补丁清单文件:{filePath}");

            // 写入版本信息
            fileBuffer.WriteInt(BuildVersion);

            // 写入元素总数
            fileBuffer.WriteInt(allAssetBundles.Length + 1);

            // 写入UnityManifest文件的信息
            {
                string        assetName   = PatchDefine.UnityManifestFileName;
                string        path        = $"{OutputPath}/{assetName}";
                string        md5         = HashUtility.FileMD5(path);
                long          sizeBytes   = EditorTools.GetFileSize(path);
                int           version     = BuildVersion;
                List <string> variantList = null;

                tableBuffer.Clear();
                tableBuffer.WriteUTF(assetName);
                tableBuffer.WriteUTF(md5);
                tableBuffer.WriteLong(sizeBytes);
                tableBuffer.WriteInt(version);
                tableBuffer.WriteListUTF(variantList);

                // 写入到总缓存
                int tabSize = tableBuffer.ReadableBytes();
                fileBuffer.WriteShort(PatchManifest.TableStreamHead);
                fileBuffer.WriteInt(tabSize);
                fileBuffer.WriteBytes(tableBuffer.ReadBytes(tabSize));
            }

            // 写入所有AssetBundle文件的信息
            foreach (string assetName in allAssetBundles)
            {
                string path      = $"{OutputPath}/{assetName}";
                string md5       = HashUtility.FileMD5(path);
                long   sizeBytes = EditorTools.GetFileSize(path);
                int    version   = BuildVersion;

                string        variants    = GetVariants(variantInfos, assetName);
                List <string> variantList = null;
                if (string.IsNullOrEmpty(variants) == false)
                {
                    variantList = variants.Split('|').ToList();
                }

                // 注意:如果文件没有变化使用旧版本号
                if (oldPatchManifest.Elements.TryGetValue(assetName, out PatchElement element))
                {
                    if (element.MD5 == md5)
                    {
                        version = element.Version;
                    }
                }

                tableBuffer.Clear();
                tableBuffer.WriteUTF(assetName);
                tableBuffer.WriteUTF(md5);
                tableBuffer.WriteLong(sizeBytes);
                tableBuffer.WriteInt(version);
                tableBuffer.WriteListUTF(variantList);

                // 写入到总缓存
                int tabSize = tableBuffer.ReadableBytes();
                fileBuffer.WriteShort(PatchManifest.TableStreamHead);
                fileBuffer.WriteInt(tabSize);
                fileBuffer.WriteBytes(tableBuffer.ReadBytes(tabSize));
            }

            // 创建文件
            using (FileStream fs = new FileStream(filePath, FileMode.Create))
            {
                byte[] data   = fileBuffer.Buf;
                int    length = fileBuffer.ReadableBytes();
                fs.Write(data, 0, length);
            }
        }