/// <summary>
        /// 4. 复制更新文件到补丁包目录
        /// </summary>
        private void CopyUpdateFiles()
        {
            string packageDirectory = GetPackageDirectory();

            Log($"开始复制更新文件到补丁包目录:{packageDirectory}");

            // 复制Readme文件
            {
                string sourcePath = $"{OutputDirectory}/{PatchDefine.ReadmeFileName}";
                string destPath   = $"{packageDirectory}/{PatchDefine.ReadmeFileName}";
                EditorTools.CopyFile(sourcePath, destPath, true);
                Log($"复制Readme文件到:{destPath}");
            }

            // 复制PatchManifest文件
            {
                string sourcePath = $"{OutputDirectory}/{PatchDefine.PatchManifestFileName}";
                string destPath   = $"{packageDirectory}/{PatchDefine.PatchManifestFileName}";
                EditorTools.CopyFile(sourcePath, destPath, true);
                Log($"复制PatchManifest文件到:{destPath}");
            }

            // 复制UnityManifest文件
            {
                string sourcePath = $"{OutputDirectory}/{PatchDefine.UnityManifestFileName}";
                string destPath   = $"{packageDirectory}/{PatchDefine.UnityManifestFileName}";
                EditorTools.CopyFile(sourcePath, destPath, true);
                Log($"复制UnityManifest文件到:{destPath}");
            }

            // 复制Manifest文件
            {
                string sourcePath = $"{OutputDirectory}/{PatchDefine.UnityManifestFileName}.manifest";
                string destPath   = $"{packageDirectory}/{PatchDefine.UnityManifestFileName}.manifest";
                EditorTools.CopyFile(sourcePath, destPath, true);
            }

            // 复制所有更新文件
            PatchManifest patchFile = LoadPatchManifestFile();

            foreach (var pair in patchFile.Elements)
            {
                if (pair.Value.Version == BuildVersion)
                {
                    string sourcePath = $"{OutputDirectory}/{pair.Key}";
                    string destPath   = $"{packageDirectory}/{pair.Key}";
                    EditorTools.CopyFile(sourcePath, destPath, true);
                    Log($"复制更新文件:{destPath}");
                }
            }
        }
示例#2
0
        /// <summary>
        /// 复制所有补丁包文件到流目录
        /// </summary>
        /// <param name="targetVersion">目标版本。如果版本为负值则拷贝所有版本</param>
        public static void CopyPackageToStreamingFolder(BuildTarget buildTarget, string outputRoot, int targetVersion = -1)
        {
            // 补丁清单路径
            string filePath = $"{outputRoot}/{buildTarget}/{PatchDefine.UnityManifestFileName}/{PatchDefine.PatchManifestFileName}";

            if (File.Exists(filePath) == false)
            {
                throw new System.Exception($"Not found {PatchDefine.PatchManifestFileName} file : {filePath}");
            }

            // 加载补丁清单
            string        jsonData = FileUtility.ReadFile(filePath);
            PatchManifest pm       = PatchManifest.Deserialize(jsonData);

            // 拷贝文件列表
            foreach (var element in pm.ElementList)
            {
                if (element.IsDLC())
                {
                    continue;
                }

                if (targetVersion >= 0 && element.Version > targetVersion)
                {
                    continue;
                }

                string sourcePath = $"{outputRoot}/{buildTarget}/{element.Version}/{element.Name}";
                string destPath   = $"{Application.dataPath}/StreamingAssets/{element.Name}";
                Debug.Log($"拷贝版本文件到流目录:{destPath}");
                EditorTools.CopyFile(sourcePath, destPath, true);
            }

            // 拷贝核心文件
            {
                string destFilePath = $"{Application.dataPath}/StreamingAssets/{PatchDefine.PatchManifestFileName}";
                EditorTools.CopyFile(filePath, destFilePath, true);
            }

            // 刷新目录
            AssetDatabase.Refresh();
        }