{"id":3508,"date":"2021-01-23T20:27:34","date_gmt":"2021-01-23T12:27:34","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=3508"},"modified":"2021-01-23T20:44:45","modified_gmt":"2021-01-23T12:44:45","slug":"%e5%9c%a8unity2019-3%e4%b8%ad%e6%9b%b4%e5%bf%ab%e5%9c%b0%e8%bf%9b%e5%85%a5%e8%bf%90%e8%a1%8c%e6%a8%a1%e5%bc%8fplaymode","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=3508","title":{"rendered":"\u5728Unity2019.3\u4e2d\u66f4\u5feb\u5730\u8fdb\u5165\u8fd0\u884c\u6a21\u5f0f(PlayMode)"},"content":{"rendered":"\n<p><a href=\"https:\/\/docs.unity3d.com\/2019.3\/Documentation\/Manual\/ConfigurableEnterPlayMode.html\">https:\/\/docs.unity3d.com\/2019.3\/Documentation\/Manual\/ConfigurableEnterPlayMode.html<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/blogs.unity3d.com\/2019\/11\/05\/enter-play-mode-faster-in-unity-2019-3\/\">https:\/\/blogs.unity3d.com\/2019\/11\/05\/enter-play-mode-faster-in-unity-2019-3\/<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/docs.unity3d.com\/2019.3\/Documentation\/Manual\/ConfigurableEnterPlayModeDetails.html\">https:\/\/docs.unity3d.com\/2019.3\/Documentation\/Manual\/ConfigurableEnterPlayModeDetails.html<\/a><\/p>\n\n\n\n<p>\u8fd0\u884c\u6a21\u5f0f(PlayMode)\u662fUnity\u5de5\u4f5c\u7684\u6838\u5fc3\uff0c\u968f\u7740\u9879\u76ee\u53d8\u5f97\u8d8a\u6765\u8d8a\u590d\u6742\uff0c\u8fdb\u5165\u548c\u9000\u51fa\u8fd0\u884c\u6a21\u5f0f\u53d8\u6210\u8d8a\u6765\u8d8a\u6162\uff0c\u5de5\u4f5c\u6548\u7387\u5c31\u8d8a\u6765\u8d8a\u4f4e\uff1b\u5728Unity2019.3\u4e2d\u5f15\u5165\u4e86\u4e00\u4e2a\u53ef\u5feb\u901f\u8fdb\u5165\u8fd0\u884c\u6a21\u5f0f\u7684\u5b9e\u9a8c\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u6839\u636e\u6d4b\u8bd5\u7ed3\u679c\uff0c\u6839\u636e\u4e0d\u540c\u7684\u9879\u76ee\uff0c\u542f\u52a8\u5feb\u901f\u8fd0\u884c\u6a21\u5f0f\u540e\uff0c\u53ef\u8282\u770150%~90%\u7684\u7b49\u5f85\u65f6\u95f4\uff1b<\/p>\n\n\n\n<p>\u5f53\u524d\u5728Unity\u4e2d\u8fdb\u5165\u8fd0\u884c\u6a21\u5f0f\uff0cUnity\u4f1a\u505a2\u4ef6\u4e8b\u60c5\uff1a\u91cd\u7f6e\u811a\u672c\u72b6\u6001 [\u57df\u91cd\u8f7d(Domain Reload)]\uff0c\u4ee5\u53ca\u91cd\u65b0\u52a0\u8f7d\u573a\u666f\uff1b<\/p>\n\n\n\n<p>\u5f00\u542f\u65b9\u6cd5\u4e3a\uff1a File \/ Project Settings \/ Editor \/ Enter Play Mode Settings \u4e2d\uff0c\u52fe\u4e0a Enter Play Mode Options ( Experimental )\uff1b<\/p>\n\n\n\n<p>\u800c\u4e14\u540e\u9762\u8fd8\u67092\u4e2a\u9009\u9879\uff1a\u91cd\u65b0\u57df \u548c \u91cd\u8f7d\u573a\u666f\uff1b<br>\u8fd9\u4e9b\u9009\u9879\u53ef\u4ee5\u5728\u6ca1\u6709\u4ee3\u7801\u66f4\u6539\u7684\u60c5\u51b5\u4e0b\uff0c\u7981\u7528 \u57df\u548c\u91cd\u65b0\u573a\u666f\uff1b<\/p>\n\n\n\n<p>\u4e0b\u56fe\u5c55\u793a\u4e86\u7981\u7528\u57df\u91cd\u8f7d\u548c\u573a\u666f\u91cd\u8f7d\uff0c\u8fdb\u5165\u8fd0\u884c\u6a21\u5f0f\u7684\u8fc7\u7a0b<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1103\" height=\"377\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2021\/01\/image-12.png\" alt=\"\" class=\"wp-image-3516\"\/><\/figure>\n\n\n\n<p>\u6ce8\u610f\uff1a\u6b64\u529f\u80fd\u5904\u4e8e\u5b9e\u9a8c\u9636\u6bb5\uff0c\u6709\u4e9b\u8f6f\u4ef6\u5305\u53ef\u80fd\u4f1a\u6709\u95ee\u9898\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7981\u7528\u4e86\u57df\u91cd\u8f7d\u540e\u5982\u4f55\u6b63\u786e\u4fee\u6539\u811a\u672c\uff1f<\/h2>\n\n\n\n<p>\u6211\u4eec\u9700\u8981\u4fee\u6539\u811a\u672c\u4e2d\u9759\u6001\u5bf9\u8c61\u548c\u4e8b\u4ef6\uff0c\u4ee5\u786e\u4fdd\u8fdb\u5165\u8fd0\u884c\u6a21\u5f0f\u65f6\u6b63\u786e\u91cd\u7f6e\u811a\u672c\u73af\u5883\uff1b<\/p>\n\n\n\n<p>\u4f7f\u7528[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]\u5c5e\u6027\uff0c\u5e76\u663e\u5f0f\u91cd\u7f6e\u8be5\u503c\uff0c\u4ee5\u786e\u4fdd\u5728\u7981\u7528\u57df\u91cd\u8f7d\u65f6\uff0c\u76f8\u5173\u5185\u5bb9\u88ab\u91cd\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using UnityEngine;\n \npublic class StaticCounterExampleFixed : MonoBehaviour\n{\n  static int counter = 0; \n \n [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]\n  static void Init()\n  {\n    counter = 0;   \n  }\n \n  void Update()\n  {\n    if (Input.GetButtonDown(\"Jump\"))\n    {\n      counter++;\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u4e0b\u4ee3\u7801\u5728\u7981\u7528\u57df\u91cd\u8f7d\u540e\u4f1a\u51fa\u95ee\u9898\uff0c\u56e0\u4e3a\u6bcf\u6b21\u542f\u52a8Start\u65f6\u90fd\u4f1a\u6dfb\u52a0Quit\u65b9\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using UnityEngine;\npublic class StaticEventExample : MonoBehaviour\n{\n    void Start()\n    {\n        Debug.Log(\"Registering quit function\");\n        Application.quitting += Quit;\n    }\n    \n    static void Quit()\n    {\n        Debug.Log(\"Quitting!\");\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528 [RuntimeInitializeOnLoadMethod] \u5c5e\u6027\u89e3\u51b3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using UnityEngine;\npublic class StaticEventExampleFixed : MonoBehaviour\n{\n    [RuntimeInitializeOnLoadMethod]\n    static void RunOnStart()\n    {\n        Debug.Log(\"Unregistering quit function\");\n        Application.quitting -= Quit;\n    }\n \n    void Start()\n    {\n        Debug.Log(\"Registering quit function\");\n        Application.quitting += Quit;\n    }\n \n    static void Quit()\n    {\n        Debug.Log(\"Quitting the Player\");\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/docs.unity3d.com\/2019.3\/Documentation\/Manual\/Co [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3508"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3508"}],"version-history":[{"count":9,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3508\/revisions"}],"predecessor-version":[{"id":3520,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3508\/revisions\/3520"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}