{"id":258,"date":"2015-01-24T11:46:54","date_gmt":"2015-01-24T03:46:54","guid":{"rendered":"http:\/\/qxu1606620110.my3w.com\/?p=258"},"modified":"2016-10-11T09:36:28","modified_gmt":"2016-10-11T01:36:28","slug":"unity3d%e4%b8%ad%e8%87%aa%e5%b8%a6%e4%ba%8b%e4%bb%b6%e5%87%bd%e6%95%b0%e7%9a%84%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=258","title":{"rendered":"Unity3D\u4e2d\u81ea\u5e26\u4e8b\u4ef6\u51fd\u6570\u7684\u8be6\u89e3"},"content":{"rendered":"<p style=\"text-align: center;\"><span style=\"color: #ff0000;\">\u8f6c\u81ea\uff1a<a href=\"http:\/\/www.jianshu.com\/p\/1d93ece664e2\" target=\"_blank\">http:\/\/www.jianshu.com\/p\/1d93ece664e2<\/a><\/span><\/p>\n<p>\u5728Unity3D\u811a\u672c\u4e2d\uff0c\u6709\u51e0\u4e2aUnity3D\u81ea\u5e26\u7684\u4e8b\u4ef6\u51fd\u6570\u6309\u7167\u9884\u5b9a\u7684\u987a\u5e8f\u6267\u884c\u4f5c\u4e3a\u811a\u672c\u6267\u884c\u3002\u5176\u6267\u884c\u987a\u5e8f\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u7f16\u8f91\u5668\uff08Editor\uff09<\/strong><\/p>\n<ul>\n<li><strong>Reset\uff1a<\/strong>Reset\u51fd\u6570\u88ab\u8c03\u7528\u6765\u521d\u59cb\u5316\u811a\u672c\u5c5e\u6027\u5f53\u811a\u672c\u7b2c\u4e00\u6b21\u88ab\u9644\u5230\u5bf9\u8c61\u4e0a\uff0c\u5e76\u4e14\u5728Reset\u547d\u4ee4\u88ab\u4f7f\u7528\u65f6\u4e5f\u4f1a\u8c03\u7528\u3002<br \/>\n\u7f16\u8005\u6ce8\uff1aReset\u662f\u5728\u7528\u6237\u70b9\u51fbInspector\u9762\u677f\u4e0aReset\u6309\u94ae\u6216\u8005\u9996\u6b21\u6dfb\u52a0\u8be5\u7ec4\u4ef6\u65f6\u88ab\u8c03\u7528\u3002Reset\u6700\u5e38\u7528\u4e8e\u5728\u89c1\u8bc6\u9762\u677f\u4e2d\u7ed9\u5b9a\u4e00\u4e2a\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u7b2c\u4e00\u6b21\u573a\u666f\u52a0\u8f7d\uff08First Scene Load\uff09<\/strong><br \/>\n\u8fd9\u4e9b\u51fd\u6570\u4f1a\u5728\u4e00\u4e2a\u573a\u666f\u5f00\u59cb\uff08\u573a\u666f\u4e2d\u6bcf\u4e2a\u7269\u4f53\u53ea\u8c03\u7528\u4e00\u6b21\uff09\u65f6\u88ab\u8c03\u7528\u3002<\/p>\n<ul>\n<li><strong>Awake\uff1a<\/strong>\u8fd9\u4e2a\u51fd\u6570\u603b\u662f\u5728\u4efb\u4f55Start()\u51fd\u6570\u4e4b\u524d\u4e00\u4e2a\u9884\u8bbe\u88ab\u5b9e\u4f8b\u5316\u4e4b\u540e\u88ab\u8c03\u7528\uff0c\u5982\u679c\u4e00\u4e2aGameObject\u662f\u975e\u6fc0\u6d3b\u7684\uff08inactive\uff09\uff0c\u5728\u542f\u52a8\u671f\u95f4Awake\u51fd\u6570\u662f\u4e0d\u4f1a\u88ab\u8c03\u7528\u7684\u76f4\u5230\u5b83\u662f\u6d3b\u52a8\u7684\uff08active\uff09\u3002<\/li>\n<li><strong>OnEnable\uff1a<\/strong>\u53ea\u6709\u5728\u5bf9\u8c61\u662f\u6fc0\u6d3b\uff08active\uff09\u72b6\u6001\u4e0b\u624d\u4f1a\u88ab\u8c03\u7528\uff0c\u8fd9\u4e2a\u51fd\u6570\u53ea\u6709\u5728object\u88ab\u542f\u7528\uff08enable\uff09\u540e\u624d\u4f1a\u8c03\u7528\u3002\u8fd9\u4f1a\u53d1\u751f\u5728\u4e00\u4e2aMonoBehaviour\u5b9e\u4f8b\u88ab\u521b\u5efa\uff0c\u4f8b\u5982\u5f53\u4e00\u4e2a\u5173\u5361\u88ab\u52a0\u8f7d\u6216\u8005\u4e00\u4e2a\u5e26\u6709\u811a\u672c\u7ec4\u4ef6\u7684GameObject\u88ab\u5b9e\u4f8b\u5316\u3002<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff1a\u5f53\u4e00\u4e2a\u573a\u666f\u88ab\u6dfb\u52a0\u5230\u573a\u666f\u4e2d\uff0c\u6240\u6709\u811a\u672c\u4e0a\u7684Awake()\u548cOnEable()\u51fd\u6570\u5c06\u4f1a\u88ab\u8c03\u7528\u5728Start()\u3001Update()\u7b49\u5b83\u4eec\u4e2d\u4efb\u4f55\u51fd\u6570\u88ab\u8c03\u7528\u4e4b\u524d\u3002\u81ea\u7136\u7684\uff0c\u5f53\u4e00\u4e2a\u7269\u4f53\u5728\u6e38\u620f\u8fc7\u7a0b\u4e2d\u88ab\u5b9e\u4f8b\u5316\u65f6\u8fd9\u4e0d\u80fd\u88ab\u5f3a\u5236\u6267\u884c\u3002<\/p>\n<p><strong>\u7b2c\u4e00\u5e27\u66f4\u65b0\u4e4b\u524d\uff08Before the first frame update\uff09<\/strong><\/p>\n<ul>\n<li><strong>Start:<\/strong>\u53ea\u8981\u811a\u672c\u5b9e\u4f8b\u88ab\u542f\u7528\u4e86Start()\u51fd\u6570\u5c06\u4f1a\u5728Update()\u51fd\u6570\u7b2c\u4e00\u5e27\u4e4b\u524d\u88ab\u8c03\u7528\u3002<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u90a3\u4e9b\u88ab\u6dfb\u52a0\u5230\u573a\u666f\u4e2d\u7684\u7269\u4f53\uff0c\u6240\u6709\u811a\u672c\u4e0a\u7684Start()\u51fd\u6570\u5c06\u4f1a\u5728\u5b83\u4eec\u4e2d\u4efb\u4f55\u7684Update()\u51fd\u6570\u4e4b\u524d\u88ab\u8c03\u7528\uff0c\u81ea\u7136\u7684\uff0c\u5f53\u4e00\u4e2a\u7269\u4f53\u5728\u6e38\u620f\u8fc7\u7a0b\u4e2d\u88ab\u5b9e\u4f8b\u5316\u65f6\u8fd9\u4e0d\u80fd\u88ab\u5f3a\u5236\u6267\u884c\u3002<\/p>\n<p><strong>\u5728\u5e27\u4e4b\u95f4\uff08In between frames\uff09<\/strong><\/p>\n<ul>\n<li><strong>OnApplicationPause\uff1a<\/strong>\u8fd9\u4e2a\u51fd\u6570\u5c06\u4f1a\u88ab\u8c03\u7528\u5728\u6682\u505c\u88ab\u68c0\u6d4b\u6709\u6548\u7684\u5728\u6b63\u5e38\u7684\u5e27\u66f4\u65b0\u4e4b\u95f4\u7684\u4e00\u5e27\u7684\u7ed3\u675f\u65f6\u3002\u5728OnApplicationPause\u88ab\u8c03\u7528\u540e\u5c06\u4f1a\u6709\u989d\u5916\u7684\u4e00\u5e27\u7528\u6765\u5141\u8bb8\u6e38\u620f\u663e\u793a\u663e\u793a\u56fe\u50cf\u8868\u793a\u5728\u6682\u505c\u72b6\u6001\u4e0b\u3002<\/li>\n<\/ul>\n<p><strong>\u66f4\u65b0\u987a\u5e8f\uff08Update Order\uff09<\/strong><\/p>\n<p>\u5f53\u4f60\u5728\u8ddf\u8e2a\u6e38\u620f\u903b\u8f91\u548c\u72b6\u6001\uff0c\u52a8\u753b\uff0c\u76f8\u673a\u4f4d\u7f6e\u7b49\u7684\u65f6\u5019\uff0c\u6709\u51e0\u4e2a\u4e0d\u540c\u7684\u4e8b\u4ef6\u51fd\u6570\u4f60\u53ef\u4ee5\u4f7f\u7528\u3002\u5e38\u89c1\u7684\u6a21\u5f0f\u662f\u5728Update()\u51fd\u6570\u4e2d\u6267\u884c\u5927\u591a\u6570\u4efb\u52a1\uff0c\u4f46\u662f\u4e5f\u6709\u5176\u5b83\u7684\u51fd\u6570\u4f60\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<ul>\n<li><strong>FixedUpdate\uff1a<\/strong>FixedUpdate\u51fd\u6570\u7ecf\u5e38\u4f1a\u6bd4Update\u51fd\u6570\u66f4\u9891\u7e41\u7684\u88ab\u8c03\u7528\u3002\u5b83\u4e00\u5e27\u4f1a\u88ab\u8c03\u7528\u591a\u6b21\uff0c\u5982\u679c\u5e27\u7387\u4f4e\u5b83\u53ef\u80fd\u4e0d\u4f1a\u5728\u5e27\u4e4b\u95f4\u88ab\u8c03\u7528\uff0c\u5c31\u7b97\u5e27\u7387\u662f\u9ad8\u7684\u3002\u6240\u6709\u7684\u56fe\u5f62\u8ba1\u7b97\u548c\u66f4\u65b0\u5728FixedUpdate\u4e4b\u540e\u4f1a\u7acb\u5373\u6267\u884c\u3002\u5f53\u5728FixedUpdate\u91cc\u6267\u884c\u79fb\u52a8\u8ba1\u7b97\uff0c\u4f60\u5e76\u4e0d\u9700\u8981Time.deltaTime\u4e58\u4ee5\u4f60\u7684\u503c\uff0c\u8fd9\u662f\u56e0\u4e3aFixedUpdate\u662f\u6309\u771f\u5b9e\u65f6\u95f4\uff0c\u72ec\u7acb\u4e8e\u5e27\u7387\u88ab\u8c03\u7528\u7684\u3002<\/li>\n<li><strong>Update\uff1a<\/strong>Update\u6bcf\u4e00\u5e27\u90fd\u4f1a\u88ab\u8c03\u7528\uff0c\u5bf9\u4e8e\u5e27\u66f4\u65b0\u5b83\u662f\u4e3b\u8981\u7684\u8d1f\u8377\u51fd\u6570\u3002<\/li>\n<li><strong>LateUpdate\uff1a<\/strong>LateUpdate\u4f1a\u5728Update\u7ed3\u675f\u4e4b\u540e\u6bcf\u4e00\u5e27\u88ab\u8c03\u7528\uff0c\u4efb\u4f55\u8ba1\u7b97\u5728Update\u91cc\u6267\u884c\u7ed3\u675f\u5f53LateUpdate\u5f00\u59cb\u65f6\u3002LateUpdate\u5e38\u7528\u4e3a\u7b2c\u4e09\u4eba\u79f0\u89c6\u89d2\u76f8\u673a\u8ddf\u968f\u3002<\/li>\n<\/ul>\n<p><strong>\u6e32\u67d3\uff08Rendering\uff09<\/strong><\/p>\n<ul>\n<li><strong>OnPreCull\uff1a<\/strong>\u5728\u76f8\u673a\u5254\u9664\u573a\u666f\u524d\u88ab\u8c03\u7528\u3002\u5254\u9664\u662f\u53d6\u51b3\u4e8e\u54ea\u4e9b\u7269\u4f53\u5bf9\u4e8e\u6444\u50cf\u673a\u662f\u53ef\u89c1\u7684\uff0cOnPreCull\u4ec5\u5728\u5254\u9664\u8d77\u4f5c\u7528\u4e4b\u524d\u88ab\u8c03\u7528\u3002<\/li>\n<li><strong>OnBecameVisible\/OnBecameInvisible\uff1a<\/strong>\u5f53\u4e00\u4e2a\u7269\u4f53\u5bf9\u4efb\u610f\u6444\u50cf\u673a\u53d8\u5f97\u53ef\u89c1\/\u4e0d\u53ef\u89c1\u65f6\u88ab\u8c03\u7528\u3002<\/li>\n<li><strong>OnPreRender\uff1a<\/strong>\u5728\u6444\u50cf\u673a\u5f00\u59cb\u6e32\u67d3\u573a\u666f\u4e4b\u524d\u8c03\u7528\u3002<\/li>\n<li><strong>OnRenderObject\uff1a<\/strong>\u5728\u6307\u5b9a\u573a\u666f\u6e32\u67d3\u5b8c\u6210\u4e4b\u540e\u8c03\u7528\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528GL\u7c7b\u6216\u8005Graphics.DrawMeshNow \u6765\u7ed8\u5236\u81ea\u5b9a\u4e49\u51e0\u4f55\u4f53\u5728\u8fd9\u91cc\u3002<\/li>\n<li><strong>OnPostRender\uff1a<\/strong>\u5728\u6444\u50cf\u673a\u5b8c\u6210\u573a\u666f\u6e32\u67d3\u4e4b\u540e\u8c03\u7528\u3002<\/li>\n<li><strong>OnRenderImage(Pro Only)\uff1a<\/strong>\u5728\u573a\u666f\u5f90\u7136\u5b8c\u6210\u4e4b\u540e\u5141\u8bb8\u5c4f\u5e55\u56fe\u50cf\u540e\u671f\u5904\u7406\u8c03\u7528\u3002<\/li>\n<li><strong>OnGUI\uff1a<\/strong>\u4e3a\u4e86\u54cd\u5e94GUI\u4e8b\u4ef6\uff0c\u6bcf\u5e27\u4f1a\u88ab\u8c03\u7528\u591a\u6b21\uff08\u4e00\u822c\u6700\u4f4e\u4e24\u6b21\uff09\u3002\u5e03\u5c40Layout\u548cRepaint\u4e8b\u4ef6\u4f1a\u9996\u5148\u5904\u7406\uff0c\u63a5\u4e0b\u6765\u5904\u7406\u7684\u662f\u662f\u901a\u8fc7<br \/>\nLayout\u548c\u952e\u76d8\/\u9f20\u6807\u4e8b\u4ef6\u5bf9\u5e94\u7684\u6bcf\u4e2a\u8f93\u5165\u4e8b\u4ef6\u3002<\/li>\n<li><strong>OnDrawGizmos\uff1a<\/strong>\u7528\u4e8e\u53ef\u89c6\u5316\u7684\u7ed8\u5236\u4e00\u4e9b\u5c0f\u73a9\u610f\u5728\u573a\u666f\u89c6\u56fe\u4e2d\u3002<\/li>\n<\/ul>\n<p><strong>\u534f\u540c\u7a0b\u5e8f\uff08Coroutines\uff09<\/strong><\/p>\n<p>\u6b63\u5e38\u7684\u534f\u540c\u7a0b\u5e8f\u66f4\u65b0\u662f\u5728Update\u51fd\u6570\u8fd4\u56de\u4e4b\u540e\u8fd0\u884c\u3002\u4e00\u4e2a\u534f\u540c\u7a0b\u5e8f\u662f\u53ef\u4ee5\u6682\u505c\u6267\u884c\uff08yield\uff09\u76f4\u5230\u7ed9\u51fa\u7684\u4f9d\u4ece\u6307\u4ee4\uff08YieldInstruction \uff09\u5b8c\u6210\uff0c\u5199\u6210\u7684\u4e0d\u540c\u8fd0\u7528\uff1a<\/p>\n<ul>\n<li><strong>yield\uff1a<\/strong>\u5728\u6240\u6709\u7684Update\u51fd\u6570\u90fd\u5df2\u7ecf\u88ab\u8c03\u7528\u7684\u4e0b\u4e00\u5e27\u8be5\u534f\u7a0b\u5c06\u6301\u7eed\u6267\u884c\u3002<\/li>\n<li><strong>yield WaitForSeconds\uff1a<\/strong>\u4e00\u6bb5\u6307\u5b9a\u7684\u65f6\u95f4\u5ef6\u8fdf\u4e4b\u540e\u7ee7\u7eed\u6267\u884c\uff0c\u5728\u6240\u6709\u7684Update\u51fd\u6570\u5b8c\u6210\u8c03\u7528\u7684\u90a3\u4e00\u5e27\u4e4b\u540e\u3002<\/li>\n<li><strong>yield WaitForFixedUpdate\uff1a<\/strong>\u6240\u6709\u811a\u672c\u4e0a\u7684FixedUpdate\u51fd\u6570\u5df2\u7ecf\u6267\u884c\u8c03\u7528\u4e4b\u540e\u6301\u7eed\u3002<\/li>\n<li><strong>yield WWW\uff1a<\/strong>\u5728WWW\u4e0b\u8f7d\u5b8c\u6210\u4e4b\u540e\u6301\u7eed\u3002<\/li>\n<li><strong>yield StartCoroutine\uff1a<\/strong>\u534f\u540c\u7a0b\u5e8f\u94fe\uff0c\u5c06\u4f1a\u7b49\u5230MuFunc\u51fd\u6570\u534f\u7a0b\u6267\u884c\u5b8c\u6210\u9996\u5148\u3002<\/li>\n<\/ul>\n<p><strong>\u9500\u6bc1\uff08When the Object is Destroyed\uff09<\/strong><\/p>\n<ul>\n<li><strong>OnDestory:<\/strong>\u8fd9\u4e2a\u51fd\u6570\u5728\u4f1a\u5728\u4e00\u4e2a\u5bf9\u8c61\u9500\u6bc1\u524d\u4e00\u5e27\u8c03\u7528\uff0c\u4f1a\u5728\u6240\u6709\u5e27\u66f4\u65b0\u4e00\u4e2a\u5bf9\u8c61\u5b58\u5728\u7684\u6700\u540e\u4e00\u5e27\u4e4b\u540e\u6267\u884c\uff0c\u5bf9\u8c61\u4e5f\u8bb8\u4f1a\u54cd\u5e94Object.Destroy \u6216\u4e00\u4e2a\u573a\u666f\u5173\u95ed\u65f6\u88ab\u9500\u6bc1\u3002<\/li>\n<\/ul>\n<p><strong>\u9000\u51fa\u6e38\u620f\uff08When Quitting\uff09<\/strong><br \/>\n\u8fd9\u4e9b\u51fd\u6570\u4f1a\u5728\u4f60\u573a\u666f\u4e2d\u6240\u6709\u7684\u6fc0\u6d3b\u7684\u7269\u4f53\u4e0a\u8c03\u7528\uff1a<\/p>\n<ul>\n<li><strong>OnApplicationQuit\uff1a<\/strong>\u8fd9\u4e2a\u51fd\u6570\u5728\u5e94\u7528\u9000\u51fa\u4e4b\u524d\u7684\u6240\u6709\u6e38\u620f\u7269\u4f53\u4e0a\u8c03\u7528\uff0c\u5728\u7f16\u8f91\u5668\uff08Editor\uff09\u6a21\u5f0f\u4e2d\u4f1a\u5728\u7528\u6237\u505c\u6b62PlayMode\u65f6\u8c03\u7528\uff0c\u5728\u7f51\u9875\u64ad\u653e\u5668\uff08web player\uff09\u4e2d\u4f1a\u5728\u7f51\u9875\u89c6\u56fe\u5173\u95ed\u65f6\u8c03\u7528\u3002<\/li>\n<li><strong>OnDisable\uff1a<\/strong>\u5f53\u884c\u4e3a\u53d8\u4e3a\u975e\u542f\u7528\uff08disable\uff09\u6216\u975e\u6fc0\u6d3b\uff08inactive\uff09\u65f6\u8c03\u7528\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea\uff1ahttp:\/\/www.jianshu.com\/p\/1d93ece664e2 &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=258\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[61,60],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/258"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=258"}],"version-history":[{"count":4,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":775,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions\/775"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}