{"id":433,"date":"2022-05-13T12:21:23","date_gmt":"2022-05-13T04:21:23","guid":{"rendered":"http:\/\/www.mapleriver.cn\/?p=433"},"modified":"2022-05-13T17:14:25","modified_gmt":"2022-05-13T09:14:25","slug":"unity-build-patch","status":"publish","type":"post","link":"https:\/\/www.mapleriver.cn\/?p=433","title":{"rendered":"Unity Build &#038; Patch"},"content":{"rendered":"<h4>1.Build<\/h4>\n<ul>\n<li>\u914d\u7f6e\u5fc5\u8981\u53c2\u6570<\/li>\n<li>\u521b\u5efaAB<\/li>\n<li>\u521b\u5efaABList<\/li>\n<li>\u538b\u7f29AB<\/li>\n<li>\u6587\u4ef6\u8fc1\u79fb<\/li>\n<li>\u6253\u5305<\/li>\n<li>\u5305\u4f53\u52a0\u56fa<\/li>\n<\/ul>\n<h6>1.\u914d\u7f6e\u9879<\/h6>\n<p>&emsp;\u00a0&emsp;\u4e00\u4e9b\u914d\u7f6e\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5305\u62ec\uff1a\u6253\u5305\u76ee\u6807\u5e73\u53f0\u3001\u662f\u5426\u9700\u8981\u6253AB\u3001\u662f\u5426\u9700\u8981\u6253ABList\u3001AB\u662f\u5426\u9700\u8981\u538b\u7f29\u7b49\uff0c\u5177\u4f53\u6839\u636e\u9879\u76ee\u9700\u8981\u8fdb\u884c\u6dfb\u52a0\u5373\u53ef\u3002<br \/>\n&emsp;\u00a0&emsp;\u6b64\u5916\u8fd8\u6709\u4e00\u4e9b\u6253\u5305\u9700\u8981\u7684\u56fa\u5b9a\u8def\u5f84\uff0c\u5982\u5305\u4f53\u5b58\u653e\u8def\u5f84\uff0cAB\u8def\u5f84\u7b49\u7b49\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u5e38\u91cf\u6216\u662fAsset\u8fdb\u884c\u914d\u7f6e<\/p>\n<h6>2.\u521b\u5efaAB<\/h6>\n<p>&emsp;\u00a0&emsp;<a href=\"https:\/\/www.mapleriver.cn\/?p=436\">\u521b\u5efaAB<\/a><\/p>\n<h6>3.\u521b\u5efaABList<\/h6>\n<p>&emsp;\u00a0&emsp;\u751f\u6210ABList\u662f\u4e3a\u4e86\u540e\u9762\u6211\u4eec\u505aPatch\u505a\u51c6\u5907\uff0c\u5f53\u8d44\u6e90\u53d1\u751f\u66f4\u6539\u65f6\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u54ea\u4e9b\u8d44\u6e90\u66f4\u6539\u4e86\uff0c\u6211\u4eec\u9700\u8981Patch\u54ea\u4e9b\u8d44\u6e90\u3002\u4fee\u6539\u7684\u8d44\u6e90\u53d8\u5316\u6709\u591a\u5927\uff0c\u63d0\u4f9b\u7ed9\u73a9\u5bb6\u9700\u8981\u66f4\u65b0\u7684\u8d44\u6e90\u5927\u5c0f\u4fe1\u606f\u7b49\u3002<\/p>\n<pre><code class=\"language-C#\">\npublic static void GenerateAssetBundleList()\n{\n    AssetBundleManifest manifest = LoadAssetBundleManifest();\n    if (manifest == null)\n    {\n        Debug.LogError(&quot;LoadAssetBundleManifest Failed&quot;);\n        return;\n    }\n    var allAssetBundles = manifest.GetAllAssetBundles().ToList();\n    allAssetBundles.Add(BuildSetting.Instance.AssetBundleFolder);\n    var abList = new AssetBundleList();\n    foreach (var abName in allAssetBundles)\n    {\n        var abPath = GetAssetBundleBuildPath(abName);\n        FileInfo fileInfo = new FileInfo(abPath);\n        var md5 = StringUtils.GetFileHash(abPath);\n        \/\/\u5199\u5165\u8d44\u6e90\u540d\uff0c\u8d44\u6e90\u5927\u5c0f\uff0cmd5\u7b49\u4fe1\u606f\n        abList.AddABInfo(abName, fileInfo.Length, md5);\n        Debug.Log(&quot;Generate AssetBundle MD5: &quot; + abName);\n    }\n    \/\/serialize AssetBundleList\n    var path = GetABListBuildPath();\n    abList.Save(path);\n    Debug.Log(&quot;Generate AssetBundleList Success: &quot; + path);\n}<\/code><\/pre>\n<h6>4.AB\u538b\u7f29<\/h6>\n<p>&emsp;\u00a0&emsp;\u4e3a\u4e86\u8ba9\u6211\u4eec\u7684\u5305\u4f53\u66f4\u5c0f\uff0c\u9996\u5305\u5916\u653e\u7684\u65f6\u5019\u8d44\u6e90\u4f1a\u4f7f\u7528\u538b\u7f29\u5305\uff0c\u7b2c\u4e00\u6b21\u8fdb\u6e38\u620f\u7684\u65f6\u5019\u8fdb\u884c\u89e3\u538b\u7f29\u3002\u540e\u9762\u5728\u66f4\u65b0patch\u7684\u65f6\u5019\u4e00\u822c\u5c31\u4e0d\u4f1a\u518d\u4f7f\u7528\u538b\u7f29AB\u4e86\u3002(\u6211\u53ea\u60f3Patch\u5176\u4e2d\u7684\u4e00\u4e2a\u6587\u4ef6\uff0c\u5982\u679c\u6253\u538b\u7f29AB\u8fd8\u8981\u5168\u4e0b\u8f7d\u4e0b\u6765)<\/p>\n<pre><code class=\"language-C#\">\/\/\u81ea\u5b9a\u4e49cmd\u6307\u4ee4\u6267\u884c7z\u538b\u7f29\uff08\u8981\u6ce8\u610f\u5148\u5b89\u88c57z\u538b\u7f29\u73af\u5883\u54e6https:\/\/www.7-zip.org\/\uff09\nvar args = &quot;a \\&quot;&quot; + path + &quot;.7z\\&quot; \\&quot;&quot; + path + &quot;\/*\\&quot; &quot;;\nvar cmd = &quot;C:\/Program Files\/7-Zip\/7z.exe&quot;;\n\nSystem.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(cmd, args);\ninfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;\ninfo.UseShellExecute = false;\ninfo.RedirectStandardOutput = true;\nSystem.Diagnostics.Process process = System.Diagnostics.Process.Start(info);\nstring content = process.StandardOutput.ReadToEnd();\nprocess.WaitForExit();<\/code><\/pre>\n<h6>5.\u6587\u4ef6\u8fc1\u79fb<\/h6>\n<p>&emsp;\u00a0&emsp;\u628a\u538b\u7f29\u540e\u7684\u538b\u7f29\u5305\u8fc1\u79fb\u5230StreamingAssets\uff0c\u4fdd\u8bc1\u8d44\u6e90\u6253\u8fdb\u5305\u5185\u3002<br \/>\n&emsp;\u00a0&emsp;\u8fd9\u6ca1\u5565\u53ef\u8bf4\u7684\uff0c\u5c31\u662f\u8bb0\u5f97io\u524d\u5148\u521b\u5efa\u5bf9\u5e94\u7684\u6587\u4ef6\u5939\u8def\u5f84\u5c31\u53ef\u4ee5\u4e86\uff0c\u76f4\u63a5\u4f7f\u7528File.Copy\u90fd\u4e0d\u7528\u81ea\u5df1\u5f00\u6d41\u5199\u5165\u4fdd\u5b58\u3002<\/p>\n<pre><code class=\"language-C#\">\/\/\u641e\u4e00\u4e2a\u9012\u5f52\u521b\u5efa\u6587\u4ef6\u5939\u7684\u51fd\u6570\npublic static void RecursivelyCreateDirectory(string fullDirectoryPath)\n{\n    if (Directory.Exists(fullDirectoryPath))\n        return;\n    string text = string.Empty;\n    string text2 = fullDirectoryPath;\n    List&lt;string&gt; list = new List&lt;string&gt;();\n    while (!Directory.Exists(text2))\n    {\n        if (text2.LastIndexOf(Path.DirectorySeparatorChar) == text2.Length - 1)\n        {\n            text2 = text2.Substring(0, text2.Length - 1);\n        }\n        int num = text2.LastIndexOf(Path.DirectorySeparatorChar);\n        text = text2.Substring(num + 1, text2.Length - (num + 1));\n        list.Add(text);\n        text2 = text2.Substring(0, num);\n    }\n    while (list.Count &gt; 0)\n    {\n        int num = list.Count - 1;\n        text = list[num];\n        list.RemoveAt(num);\n        text2 = text2 + Path.DirectorySeparatorChar + text;\n        Directory.CreateDirectory(text2);\n    }\n}<\/code><\/pre>\n<h6>6.\u6253\u5305<\/h6>\n<p>&emsp;\u00a0&emsp;AB\u90fd\u5904\u7406\u5b8c\u4e86\uff0c\u63a5\u4e0b\u6765\u5c31\u662f\u6253apk\u4e86\u3002\u6ca1\u5565\u597d\u8bf4\u7684\uff0c\u8c03\u4e00\u4e0bAPI\u5c31\u884c\u4e86\u3002<\/p>\n<pre><code class=\"language-C#\">BuildPipeline.BuildPlayer(EditorBuildSettings.scenes, outputPackage, platform, option);<\/code><\/pre>\n<h6>7.\u52a0\u56fa\u5305\u4f53<\/h6>\n<p>&emsp;\u00a0&emsp;\u8fd9\u5c31\u770b\u63a5\u5165\u7684\u52a0\u56faSDK\u4e86\uff0cSDK\u4e00\u822c\u90fd\u6709\u56fa\u5b9a\u7684\u52a0\u56fa\u6d41\u7a0b\uff0c\u53ea\u8981\u4f7f\u7528\u5bf9\u5e94\u5e73\u53f0\u7684\u6307\u4ee4\u5c31\u53ef\u4ee5\u5b8c\u6210\u52a0\u56fa\u4e86\u3002<\/p>\n<h4>2.Patch<\/h4>\n<p>&emsp;\u00a0&emsp;Patch\u7684\u7f16\u8f91\u5668\u6d41\u7a0b\u5176\u5b9e\u548cBuild\u7c7b\u4f3c<\/p>\n<ul>\n<li>\u521b\u5efaAB<\/li>\n<li>\u6784\u5efaABList<\/li>\n<li>\u5dee\u5f02\u5904\u7406<\/li>\n<li>\u5dee\u5f02AB\u4e0a\u4f20\u5230\u670d\u52a1\u5668<\/li>\n<\/ul>\n<p>&emsp;\u00a0&emsp;\u5176\u4e2d\u521b\u5efaAB\u548c\u6784\u5efaABList\u5176\u5b9e\u548cBuild\u7684\u6d41\u7a0b\u662f\u5b8c\u5168\u4e00\u6837\u7684\u3002<br \/>\n&emsp;\u00a0&emsp;\u5dee\u5f02\u5904\u7406\u5c31\u662f\u901a\u8fc7\u5bf9\u6bd4\u672c\u5730ABList\u548c\u670d\u52a1\u5668\u4e0a\u7684ABList\u628a\u4e0d\u540c\u7684AB\u627e\u51fa\u6765\u3002<br \/>\n&emsp;\u00a0&emsp;\u7136\u540e\u628a\u8fd9\u4e9b\u5dee\u5f02AB\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u5c31\u53ef\u4ee5\u62c9\uff0c\u8bb0\u5f97\u4e5f\u8981\u628aABList\u4e0a\u4f20\u54e6~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.Build \u914d\u7f6e\u5fc5\u8981\u53c2\u6570 \u521b\u5efaAB \u521b\u5efaABList \u538b\u7f29AB \u6587\u4ef6\u8fc1\u79fb \u6253\u5305 \u5305\u4f53\u52a0\u56fa 1.\u914d\u7f6e\u9879 &#038;e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-unity"],"_links":{"self":[{"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=433"}],"version-history":[{"count":6,"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mapleriver.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}