{"id":669,"date":"2025-09-18T16:42:11","date_gmt":"2025-09-18T08:42:11","guid":{"rendered":"https:\/\/reverieland.cn\/?p=669"},"modified":"2025-09-18T17:25:21","modified_gmt":"2025-09-18T09:25:21","slug":"%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/reverieland.cn\/index.php\/669\/","title":{"rendered":"SAT\u9ad8\u6027\u80fd\u78b0\u649e-\u8bc4\u4f30\u7bc7"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1.\u548cUnity\u81ea\u5e26\u7684Mesh Collider\u7684\u533a\u522b<\/h2>\n\n\n\n<p>\u867d\u7136\u5bf9\u4e8e\u5e38\u89c4\u6e38\u620f\u5f00\u53d1\u9700\u6c42\uff0cUnity\u81ea\u5e26\u7684<code>Mesh Collider<\/code>\u786e\u5b9e\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\uff0c\u4f46SAT\u9879\u76ee\u7684\u5b9e\u73b0\u5c55\u73b0\u4e86\u5b8c\u5168\u4e0d\u540c\u5c42\u9762\u4e0a\u7684\u6280\u672f\u8ffd\u6c42\u548c\u4f18\u52bf\u3002\u6211\u4eec\u6765\u4ece\u51e0\u4e2a\u65b9\u9762\u8fdb\u884c\u8be6\u7ec6\u8bc4\u4f30\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6280\u672f\u6808(Performance Philosophy)<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Unity <code>Mesh Collider<\/code><\/strong>: \u5b83\u7684\u540e\u7aef\u662fNVIDIA\u7684PhysX\u7269\u7406\u5f15\u64ce\uff0c\u8fd9\u662f\u4e00\u4e2a\u7528C++\u7f16\u5199\u7684\u3001\u7ecf\u8fc7\u957f\u671f\u4f18\u5316\u548c\u9a8c\u8bc1\u7684\u6210\u719f\u7269\u7406\u5e93\u3002\u5b83\u6027\u80fd\u975e\u5e38\u9ad8\uff0c\u529f\u80fd\u7a33\u5b9a\u3002\u4f46\u662f\uff0cUnity\u5f15\u64ce\uff08C#\uff09\u4e0ePhysX\uff08C++\uff09\u4e4b\u95f4\u7684\u4ea4\u4e92\u5b58\u5728\u4e00\u5b9a\u7684\u201c\u80f6\u6c34\u4ee3\u7801\u201d\u5f00\u9500\uff08interop overhead\uff09\u3002<\/li>\n\n\n\n<li><strong>SAT\u9879\u76ee<\/strong>: \u8fd9\u4e2a\u4f5c\u4e1a\u7684\u6838\u5fc3\u662f<strong>\u5b8c\u5168\u57fa\u4e8eC#\u7684\u3001\u9762\u5411Unity DOTS\uff08Data-Oriented Technology Stack\uff09\u6280\u672f\u6808\u7684\u5b9e\u73b0<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li><strong>Burst Compiler<\/strong>: Burst\u53ef\u4ee5\u5c06\u7279\u5b9a\u7684C#\u4ee3\u7801\uff08unmanaged, HPC#\uff09\u7f16\u8bd1\u6210\u9ad8\u5ea6\u4f18\u5316\u7684\u672c\u5730\u673a\u5668\u7801\uff0c\u5176\u6027\u80fd\u53ef\u4ee5\u4e0eC++\u5ab2\u7f8e\u751a\u81f3\u8d85\u8d8a\uff0c\u540c\u65f6\u907f\u514d\u4e86C#\u4e0eC++\u4e4b\u95f4\u7684\u8c03\u7528\u5f00\u9500\u3002<\/li>\n\n\n\n<li><strong>\u96f6GC (Zero GC)<\/strong>: \u901a\u8fc7\u7cbe\u7ec6\u7684\u5185\u5b58\u7ba1\u7406\uff08<code>stackalloc<\/code>, <code>UnsafeUtility<\/code>\uff09\uff0c\u8be5\u5b9e\u73b0\u907f\u514d\u4e86\u6258\u7ba1\u5806\u5185\u5b58\u5206\u914d\uff0c\u4ece\u800c\u6d88\u9664\u4e86\u5783\u573e\u56de\u6536\uff08GC\uff09\u53ef\u80fd\u5e26\u6765\u7684\u6027\u80fd\u6296\u52a8\u548c\u5361\u987f\u3002\u8fd9\u5bf9\u4e8e\u9700\u8981\u7a33\u5b9a\u9ad8\u5e27\u7387\u7684\u6e38\u620f\uff08\u5982\u683c\u6597\u3001\u97f3\u4e50\u3001\u7535\u7ade\u7c7b\u6e38\u620f\uff09\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u5bfc\u5411\u8bbe\u8ba1<\/strong>: \u8fd9\u79cd\u5b9e\u73b0\u65b9\u5f0f\u975e\u5e38\u5951\u5408Unity\u7684DOTS\u67b6\u6784\uff0c\u53ef\u4ee5\u4e0eC# Job System\u548cECS\uff08Entity Component System\uff09\u65e0\u7f1d\u96c6\u6210\uff0c\u5b9e\u73b0\u5927\u89c4\u6a21\u5e76\u884c\u8ba1\u7b97\uff0c\u8fd9\u662f\u4f20\u7edf<code>GameObject<\/code>\u548c<code>MonoBehaviour<\/code>\u67b6\u6784\u96be\u4ee5\u4f01\u53ca\u7684\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u5c0f\u7ed3<\/strong>\uff1a\u8fd9\u5728\u7279\u5b9a\u573a\u666f\u4e0b\uff08\u4f8b\u5982\uff0c\u9700\u8981\u5728\u4e00\u4e2a\u573a\u666f\u4e2d\u5904\u7406\u6210\u5343\u4e0a\u4e07\u4e2a\u52a8\u6001\u51f8\u4f53\u78b0\u649e\uff09<strong>\u6709\u53ef\u80fd\u8d85\u8d8a<\/strong> <code>Mesh Collider<\/code>\u7684\u8868\u73b0\uff0c\u56e0\u4e3a\u5b83\u6d88\u9664\u4e86\u8de8\u8bed\u8a00\u8c03\u7528\u7684\u5f00\u9500\uff0c\u5e76\u5b8c\u5168\u878d\u5165\u4e86Unity\u6700\u65b0\u7684\u9ad8\u6027\u80fd\u6280\u672f\u6808\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u7b97\u6cd5\u5b9e\u73b0\u4e0e\u63a7\u5236\u529b (Algorithm &amp; Control)<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Unity <code>Mesh Collider<\/code><\/strong>: \u5b83\u662f\u4e00\u4e2a\u201c\u9ed1\u76d2\u201d\u3002\u5f00\u53d1\u8005\u77e5\u9053\u5b83\u53ef\u4ee5\u5de5\u4f5c\uff0c\u4f46\u65e0\u6cd5\u5e72\u9884\u5176\u5185\u90e8\u7684\u7b97\u6cd5\u7ec6\u8282\u3002\u4f8b\u5982\uff0c\u5f53<code>Mesh Collider<\/code>\u8bbe\u7f6e\u4e3a\"Convex\"\u65f6\uff0c\u5176\u5185\u90e8\u53ef\u80fd\u4f7f\u7528GJK\u7b97\u6cd5\u6216SAT\u7b97\u6cd5\u7684\u53d8\u79cd\uff0c\u4f46\u5177\u4f53\u5b9e\u73b0\u662f\u56fa\u5316\u7684\u3002\u5bf9\u4e8e\u975e\u51f8<code>Mesh Collider<\/code>\uff0c\u5176\u529f\u80fd\u9650\u5236\u5f88\u591a\uff08\u4e0d\u80fd\u4e0e\u5176\u4ed6\u975e\u51f8\u7f51\u683c\u78b0\u649e\uff09\u3002<\/li>\n\n\n\n<li><strong>SAT\u9879\u76ee<\/strong>: \u8fd9\u4e2a\u4f5c\u4e1a\u662f\u5bf9\u6838\u5fc3\u78b0\u649e\u7b97\u6cd5\uff083D SAT\uff09\u7684<strong>\u7cbe\u786e\u590d\u73b0\u548c\u6df1\u5ea6\u4f18\u5316<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u7cbe\u786e\u63a7\u5236<\/strong>: \u5f00\u53d1\u8005\u5b8c\u5168\u7406\u89e3\u5e76\u80fd\u63a7\u5236\u78b0\u649e\u68c0\u6d4b\u7684\u6bcf\u4e00\u4e2a\u73af\u8282\uff0c\u4ece\u5206\u79bb\u8f74\u7684\u7b5b\u9009\uff08\u901a\u8fc7Minkowski\u5dee\u4f18\u5316\uff09\u5230\u63a5\u89e6\u70b9\u7684\u751f\u6210\uff08Sutherland-Hodgman\u88c1\u526a\uff09\u3002\u8fd9\u610f\u5473\u7740\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u8fdb\u884c\u6df1\u5ea6\u5b9a\u5236\u548c\u8c03\u8bd5\u3002<\/li>\n\n\n\n<li><strong>\u7b97\u6cd5\u7406\u89e3<\/strong>: \u771f\u6b63\u7406\u89e3\u4e863D\u78b0\u649e\u68c0\u6d4b\u7684\u5e95\u5c42\u6570\u5b66\u539f\u7406\u3002\u8fd9\u79cd\u80fd\u529b\u5728\u89e3\u51b3\u590d\u6742\u548c\u975e\u6807\u51c6\u7684\u7269\u7406\u95ee\u9898\u65f6\u662f\u65e0\u4ef7\u7684\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u5c0f\u7ed3<\/strong>\uff1aSAT\u9879\u76ee\u7684\u4ef7\u503c\u5728\u4e8e\u5176<strong>\u767d\u76d2\u7279\u6027\u548c\u5b8c\u5168\u7684\u63a7\u5236\u529b<\/strong>\u3002\u5f53\u4f60\u9700\u8981\u5b9e\u73b0\u4e00\u4e9bUnity\u539f\u751f\u7269\u7406\u4e0d\u652f\u6301\u7684\u7279\u6b8a\u6548\u679c\uff0c\u6216\u8005\u5f53\u5185\u7f6e\u7269\u7406\u5f15\u64ce\u7684\u884c\u4e3a\u4e0d\u7b26\u5408\u9884\u671f\u9700\u8981\u6df1\u5ea6\u8c03\u8bd5\u65f6\uff0c\u8fd9\u79cd\u81ea\u7814\u80fd\u529b\u5c31\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u201c\u5b9e\u7528\u6027\u201d\u7684\u5b9a\u4e49<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5bf9\u4e8e\u666e\u901a\u9879\u76ee<\/strong>: \u5982\u679c\u4f60\u7684\u6e38\u620f\u53ea\u9700\u8981\u5e38\u89c4\u7684\u7269\u7406\u4ea4\u4e92\uff08\u4f8b\u5982\uff0c\u89d2\u8272\u63a7\u5236\u5668\u3001\u7b80\u5355\u7684\u521a\u4f53\u78b0\u649e\uff09\uff0c\u90a3\u4e48\u4f7f\u7528\u5185\u7f6e\u7684<code>Mesh Collider<\/code>\u65e0\u7591\u662f\u6700\u9ad8\u6548\u3001\u6700\u5b9e\u7528\u7684\u9009\u62e9\u3002\u4ece\u8fd9\u4e2a\u89d2\u5ea6\u770b\uff0c\u539f\u8bf4\u6cd5\u6709\u4e00\u5b9a\u9053\u7406\u3002<\/li>\n\n\n\n<li><strong>\u5bf9\u4e8e\u8ffd\u6c42\u6781\u81f4\u6027\u80fd\u548c\u5b9a\u5236\u5316\u7684\u9879\u76ee<\/strong>: \u5982\u679c\u4f60\u6b63\u5728\u5f00\u53d1\u4e00\u4e2a\u9700\u8981\u6d77\u91cf\u7269\u7406\u5bf9\u8c61\u4ea4\u4e92\u7684\u6a21\u62df\u7a0b\u5e8f\u3001\u4e00\u4e2a\u5bf9\u5e27\u7387\u7a33\u5b9a\u6027\u8981\u6c42\u6781\u9ad8\u7684\u786c\u6838\u6e38\u620f\uff0c\u6216\u8005\u4e00\u4e2a\u9700\u8981\u7279\u6b8a\u7269\u7406\u89c4\u5219\u7684\u6e38\u620f\uff0c\u90a3\u4e48\u4e00\u4e2a\u57fa\u4e8eBurst\u548c\u96f6GC\u7684\u81ea\u5b9a\u4e49\u7269\u7406\u7cfb\u7edf\u5c31<strong>\u975e\u5e38\u5b9e\u7528<\/strong>\u3002\u5b83\u4e3a\u6027\u80fd\u548c\u529f\u80fd\u7684\u53ef\u6269\u5c55\u6027\u63d0\u4f9b\u4e86\u575a\u5b9e\u7684\u57fa\u7840\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2.SAT\u9ad8\u6027\u80fd\u78b0\u649e\u548cMesh Collider\u90fd\u6d89\u53ca\u5230C#\u548cC++\u7684\u8f6c\u6362\uff0c\u533a\u522b\u3001\u4f18\u52bf\u5728\u54ea<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u8f6c\u6362\u7684\u65f6\u673a\u4e0e\u65b9\u5f0f (When &amp; How)<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Unity <code>Mesh Collider<\/code> (\u4f20\u7edf\u65b9\u5f0f - \u8fd0\u884c\u65f6\u6865\u63a5)<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u65f6\u673a<\/strong>: <strong>\u8fd0\u884c\u65f6 (Runtime)<\/strong>\u3002\u6bcf\u6b21\u4f60\u7684C#\u811a\u672c\u8c03\u7528\u4e00\u4e2a\u7269\u7406API\uff08\u5982 <code>Rigidbody.AddForce<\/code>\uff09\u6216\u8005\u5f15\u64ce\u56de\u8c03\u4f60\u7684C#\u65b9\u6cd5\uff08\u5982 <code>OnCollisionEnter<\/code>\uff09\u65f6\uff0c\u8f6c\u6362\u90fd\u4f1a\u5b9e\u65f6\u53d1\u751f\u3002<\/li>\n\n\n\n<li><strong>\u65b9\u5f0f<\/strong>: \u901a\u8fc7\u4e00\u4e2a\u88ab\u79f0\u4e3a <strong>\u201cP\/Invoke\u201d (Platform Invoke) \u6216\u5185\u90e8\u8c03\u7528 (Internal Call)<\/strong> \u7684\u201c\u6865\u6881\u201d\u3002\n<ul class=\"wp-block-list\">\n<li><strong>C# \u2192 C++<\/strong>: \u4f60\u7684C#\u4ee3\u7801\u8c03\u7528\u88ab\u7f16\u8bd1\u6210\u4e2d\u95f4\u8bed\u8a00\uff08IL\uff09\u3002\u5728\u8fd0\u884c\u65f6\uff0c\u5f53\u9700\u8981\u8c03\u7528\u7269\u7406\u5f15\u64ce\u529f\u80fd\u65f6\uff0c\u6267\u884c\u6d41\u4f1a\u6682\u505c\uff0c\u6253\u5305\uff08\u7f16\u7ec4\uff09\u597d\u6570\u636e\uff0c\u7136\u540e\u901a\u8fc7\u8fd9\u4e2a\u201c\u6865\u6881\u201d\u8df3\u8f6c\u5230\u9884\u5148\u7f16\u8bd1\u597d\u7684C++ PhysX\u5e93\u51fd\u6570\u4e2d\u53bb\u6267\u884c\u3002\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u518d\u5e26\u7740\u8fd4\u56de\u503c\u8df3\u56de\u6765\u3002<\/li>\n\n\n\n<li><strong>C++ \u2192 C#<\/strong>: \u7269\u7406\u5f15\u64ce\u5728\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u7b97\u5b8c\u540e\uff0c\u9700\u8981\u901a\u77e5\u4e3b\u7ebf\u7a0b\u7684C#\u811a\u672c\u3002\u5b83\u4f1a\u901a\u8fc7\u8fd9\u4e2a\u201c\u6865\u6881\u201d\u53cd\u5411\u8c03\u7528\u4f60\u7684C#\u51fd\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u672c\u8d28<\/strong>: \u8fd9\u662f\u4e00\u79cd<strong>\u52a8\u6001\u7684\u3001\u8fd0\u884c\u65f6\u7684\u4e92\u64cd\u4f5c\uff08Interop\uff09<\/strong>\u3002\u4e24\u4e2a\u72ec\u7acb\u7684\u7a0b\u5e8f\u4e16\u754c\uff08C#\u6258\u7ba1\u73af\u5883 \u548c C++\u539f\u751f\u73af\u5883\uff09\u5728\u8fdb\u884c\u5b9e\u65f6\u5bf9\u8bdd\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>SAT\u9879\u76ee (Burst\u65b9\u5f0f - \u7f16\u8bd1\u65f6\u4e00\u4f53\u5316)<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u65f6\u673a<\/strong>: <strong>\u7f16\u8bd1\u65f6 (Compile-Time)<\/strong>\u3002\u5728\u4f60\u70b9\u51fbUnity\u7684\u201cPlay\u201d\u6309\u94ae\u4e4b\u524d\uff0c\u6216\u8005\u5728\u9879\u76ee\u6784\u5efa\u65f6\u3002<\/li>\n\n\n\n<li><strong>\u65b9\u5f0f<\/strong>: \u901a\u8fc7 <strong>Burst\u7f16\u8bd1\u5668<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li>Burst\u662f\u4e00\u4e2a\u7279\u6b8a\u7684<strong>AOT (Ahead-of-Time) \u7f16\u8bd1\u5668<\/strong>\u3002\u5b83\u4f1a\u83b7\u53d6\u4f60\u6807\u8bb0\u4e3a <code>[BurstCompile]<\/code> \u7684C#\u4ee3\u7801\u5b50\u96c6\uff08\u5fc5\u987b\u662f\u6240\u8c13\u7684HPC#\uff0c\u9ad8\u6027\u80fdC#\u5b50\u96c6\uff09\uff0c\u7136\u540e<strong>\u76f4\u63a5\u5c06\u5176\u7ffb\u8bd1\u6210\u9488\u5bf9\u76ee\u6807\u5e73\u53f0\uff08\u5982x86\u3001ARM\uff09\u9ad8\u5ea6\u4f18\u5316\u7684\u672c\u5730\u673a\u5668\u7801\uff08Machine Code\uff09<\/strong>\uff0c\u5c31\u50cf\u7528C++\u7f16\u8bd1\u5668\u7f16\u8bd1C++\u4ee3\u7801\u4e00\u6837\u3002<\/li>\n\n\n\n<li>\u8fd9\u4e2a\u8fc7\u7a0b<strong>\u7ed5\u8fc7\u4e86\u6807\u51c6\u7684C# IL\u548cJIT\/IL2CPP\u7f16\u8bd1\u6d41\u7a0b<\/strong>\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u672c\u8d28<\/strong>: \u8fd9\u4e0d\u662f\u4e24\u4e2a\u4e16\u754c\u7684\u201c\u5bf9\u8bdd\u201d\uff0c\u800c\u662f\u5c06\u4f60\u7684C#\u903b\u8f91**\u201c\u53d8\u8eab\u201d<strong>\u6210\u4e0ePhysX\u540c\u6837\u5730\u4f4d\u7684\u539f\u751f\u4ee3\u7801\u3002\u5b83\u4e0d\u518d\u662f\u201cC#\u811a\u672c\u201d\uff0c\u800c\u662f\u4e00\u4e2a<\/strong>\u9ad8\u6027\u80fd\u7684\u539f\u751f\u4ee3\u7801\u5e93**\uff0c\u53ea\u662f\u5b83\u7684\u6e90\u7801\u6070\u597d\u662f\u7528C#\u5199\u7684\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u6570\u636e\u5904\u7406\u4e0e\u5185\u5b58 (Data &amp; Memory)<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Unity <code>Mesh Collider<\/code> (\u6570\u636e\u9700\u8981\u8de8\u754c\u201c\u7f16\u7ec4\u201d)<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u5185\u5b58\u6a21\u578b<\/strong>: \u6570\u636e\u5b58\u5728\u4e8e\u4e24\u4e2a\u4e16\u754c\u3002C#\u5bf9\u8c61\uff08\u5982 <code>Vector3<\/code> \u7ed3\u6784\u4f53\uff0c\u6216\u8005 <code>Collision<\/code> \u7c7b\uff09\u5b58\u5728\u4e8e<strong>\u6258\u7ba1\u5806 (Managed Heap)<\/strong> \u4e0a\uff0c\u800cPhysX\u7684\u5185\u90e8\u6570\u636e\uff08\u5982 <code>PxVec3<\/code>\uff09\u5b58\u5728\u4e8e<strong>\u539f\u751f\u5806 (Native Heap)<\/strong> \u4e0a\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u4f20\u9012<\/strong>: \u5f53\u8c03\u7528\u53d1\u751f\u65f6\uff0c\u6570\u636e\u9700\u8981\u88ab**\u201c\u7f16\u7ec4\u201d (Marshalling)**\u3002\u8fd9\u610f\u5473\u7740\u8fd0\u884c\u65f6\u7cfb\u7edf\u9700\u8981\u8bfb\u53d6C#\u5185\u5b58\u4e2d\u7684\u6570\u636e\uff0c\u6309\u7167C++\u80fd\u7406\u89e3\u7684\u683c\u5f0f\u5728\u539f\u751f\u5185\u5b58\u4e2d\u521b\u5efa\u4e00\u4e2a\u526f\u672c\uff0c\u7136\u540e\u624d\u80fd\u4f20\u9012\u8fc7\u53bb\u3002\u8fd9\u4e2a\u590d\u5236\u8fc7\u7a0b\uff0c\u5373\u4f7f\u5bf9\u4e8e\u7b80\u5355\u7684\u503c\u7c7b\u578b\uff0c\u4e5f\u5b58\u5728\u5f00\u9500\u3002<\/li>\n\n\n\n<li><strong>\u9650\u5236<\/strong>: \u4f60\u4e0d\u80fd\u76f4\u63a5\u5c06C#\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u76f4\u63a5\u4e22\u7ed9C++\u4f7f\u7528\uff08\u6709\u5b89\u5168\u98ce\u9669\u548cGC\u95ee\u9898\uff09\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u4f60\u7684\u8bfe\u7a0b\u4f5c\u4e1a (\u6570\u636e\u5171\u4eab\u539f\u751f\u5185\u5b58)<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>\u5185\u5b58\u6a21\u578b<\/strong>: \u4f60\u901a\u8fc7\u4f7f\u7528 <code>unmanaged<\/code> \u7c7b\u578b\u3001<code>stackalloc<\/code>\u3001\u6307\u9488 (<code>UnsafeUtility<\/code>) \u548c <code>NativeBuffer&lt;T><\/code>\uff0c<strong>\u4ece\u4e00\u5f00\u59cb\u5c31\u53ea\u5728\u539f\u751f\u5185\u5b58\u4e2d\u64cd\u4f5c\u6570\u636e<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u4f20\u9012<\/strong>: <strong>\u6ca1\u6709\u201c\u4f20\u9012\u201d\uff0c\u53ea\u6709\u201c\u8bbf\u95ee\u201d<\/strong>\u3002\u56e0\u4e3aBurst\u7f16\u8bd1\u540e\u7684\u539f\u751f\u4ee3\u7801\u548c\u4f60\u7684\u6570\u636e\u90fd\u4f4d\u4e8e\u540c\u4e00\u7247\u539f\u751f\u5185\u5b58\u533a\u57df\uff0c\u6240\u4ee5\u4e0d\u5b58\u5728\u8de8\u754c\u590d\u5236\u3002\u5f53\u4f60\u7684Burst Job\u9700\u8981\u4e00\u4e2a\u5411\u91cf\u65f6\uff0c\u5b83\u76f4\u63a5\u901a\u8fc7\u6307\u9488\u6216\u5f15\u7528\u8bbf\u95ee\u539f\u751f\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5373\u53ef\uff0c\u8fd9\u4e0eC++\u4ee3\u7801\u8bbf\u95ee\u81ea\u8eab\u6570\u636e\u7684\u6548\u7387\u662f\u5b8c\u5168\u4e00\u6837\u7684\u3002<\/li>\n\n\n\n<li><strong>\u4f18\u52bf<\/strong>: \u5b9e\u73b0\u4e86\u771f\u6b63\u7684<strong>\u96f6\u62f7\u8d1d (Zero-Copy)<\/strong> \u548c\u96f6\u7f16\u7ec4\u5f00\u9500\uff0c\u6570\u636e\u5e03\u5c40\u4e5f\u66f4\u7d27\u51d1\uff0c\u6709\u5229\u4e8eCPU\u7f13\u5b58\u547d\u4e2d\u7387\uff08Data Locality\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u7b80\u5355\u6765\u8bf4\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Mesh Collider<\/code>\u7684\u65b9\u5f0f\uff0c\u5c31\u50cf\u4e00\u4e2a**\u4e2d\u6587\u6bcd\u8bed\u8005\uff08C#\uff09<strong>\u5728\u901a\u8fc7\u4e00\u4e2a<\/strong>\u540c\u58f0\u4f20\u8bd1\uff08\u8fd0\u884c\u65f6\u6865\u6881\uff09<strong>\u4e0e\u4e00\u4e2a<\/strong>\u82f1\u6587\u6bcd\u8bed\u8005\uff08C++ PhysX\uff09**\u5bf9\u8bdd\u3002\u5373\u4f7f\u7ffb\u8bd1\u518d\u5feb\uff0c\u4e5f\u5b58\u5728\u5ef6\u8fdf\u548c\u8f6c\u6362\u6210\u672c\u3002<\/li>\n\n\n\n<li>\u4f60\u7684\u8bfe\u7a0b\u4f5c\u4e1a\u7684\u65b9\u5f0f\uff0c\u5219\u662f\u8fd9\u4e2a**\u4e2d\u6587\u6bcd\u8bed\u8005\uff08\u4f60\u7684C#\u4ee3\u7801\uff09**\u901a\u8fc7\u5b66\u4e60\u548c\u8bad\u7ec3\uff08<strong>Burst\u7f16\u8bd1\u5668<\/strong>\uff09\uff0c<strong>\u81ea\u5df1\u5b66\u4f1a\u4e86\u8bf4\u6d41\u5229\u7684\u82f1\u8bed\uff08\u539f\u751f\u673a\u5668\u7801\uff09<\/strong>\uff0c\u53ef\u4ee5\u76f4\u63a5\u548c\u82f1\u6587\u6bcd\u8bed\u8005\u65e0\u969c\u788d\u3001\u9ad8\u6548\u7387\u5730\u4ea4\u6d41\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3.Unity\u7684Mesh Collider\uff0c\u662f\u5426\u662f\u96f6GC\u7684\uff1f<\/h2>\n\n\n\n<p><strong>\u4e0d\u5b8c\u5168\u662f\uff0c\u8fd9\u53d6\u51b3\u4e8e\u7a0b\u5e8f\u5458\u5982\u4f55\u4e0e\u5b83\u4ea4\u4e92\u3002<\/strong>\u5c06\u8fd9\u4e2a\u95ee\u9898\u62c6\u89e3\u4e3a\u4e24\u4e2a\u90e8\u5206\u6765\u770b\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u6838\u5fc3\u7269\u7406\u8ba1\u7b97<\/strong>\uff1a<code>Mesh Collider<\/code>\u80cc\u540e\u7684PhysX\u5f15\u64ce\u662fC++\u539f\u751f\u4ee3\u7801\u3002\u5b83\u5728\u81ea\u5df1\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\u8fdb\u884c\u6240\u6709\u7684\u78b0\u649e\u68c0\u6d4b\u3001\u6c42\u89e3\u548c\u6a21\u62df\u8fd0\u7b97\u3002<strong>\u8fd9\u4e2a\u6838\u5fc3\u8ba1\u7b97\u8fc7\u7a0b\u672c\u8eab\uff0c\u5bf9\u4e8eC#\u7684\u6258\u7ba1\u5806\uff08Managed Heap\uff09\u6765\u8bf4\uff0c\u662f\u96f6GC\u7684\u3002<\/strong> \u5b83\u4e0d\u4f1a\u5728C#\u8fd9\u8fb9\u4ea7\u751f\u4efb\u4f55\u9700\u8981\u5783\u573e\u56de\u6536\u5668\uff08Garbage Collector\uff09\u5904\u7406\u7684\u5185\u5b58\u5783\u573e\u3002<\/li>\n\n\n\n<li><strong>C# API\u4ea4\u4e92\u5c42<\/strong>\uff1a\u95ee\u9898\u51fa\u5728\u6211\u4eec\u7684C#\u811a\u672c\u9700\u8981\u4ece\u7269\u7406\u5f15\u64ce\u83b7\u53d6\u4fe1\u606f\u7684\u65f6\u5019\u3002\u5f53\u78b0\u649e\u53d1\u751f\u65f6\uff0c\u5f15\u64ce\u9700\u8981\u5c06\u7ed3\u679c\u901a\u77e5\u7ed9C#\u5c42\uff0c\u8fd9\u4e2a\u8fc7\u7a0b<strong>\u6709\u53ef\u80fd\u4ea7\u751fGC Alloc<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u5178\u578b\u7684\u9ad8GC\u573a\u666f<\/strong>\uff1a\u5728<code>OnCollisionEnter(Collision collision)<\/code>\u56de\u8c03\u4e2d\uff0c\u5982\u679c\u4f60\u8bbf\u95ee<code>collision.contacts<\/code>\u8fd9\u4e2a\u5c5e\u6027\uff0cUnity\u4e3a\u4e86\u65b9\u4fbf\u4f7f\u7528\uff0c\u4f1a<strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 <code>ContactPoint<\/code> \u6570\u7ec4<\/strong>\u3002\u6bcf\u6b21\u8bbf\u95ee\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\uff0c\u8fd9\u4f1a\u4ea7\u751f\u5927\u91cf\u7684GC\u3002\u540c\u7406\uff0c\u4f7f\u7528 <code>Physics.RaycastAll<\/code> \u7b49\u8fd4\u56de\u6570\u7ec4\u7684API\uff0c\u540c\u6837\u4f1a\u56e0\u521b\u5efa\u65b0\u6570\u7ec4\u800c\u4ea7\u751fGC\u3002<\/li>\n\n\n\n<li><strong>\u5982\u4f55\u505a\u5230\u4f4eGC\u6216\u96f6GC<\/strong>\uff1a\u73b0\u4ee3Unity\u7248\u672c\u5df2\u7ecf\u610f\u8bc6\u5230\u4e86\u8fd9\u4e2a\u95ee\u9898\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e0d\u4ea7\u751fGC\u7684\u66ff\u4ee3\u65b9\u6848\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 <code>collision.GetContacts(List&lt;ContactPoint> contacts)<\/code> \u6216 <code>collision.GetContacts(NativeArray&lt;ContactPoint> contacts)<\/code> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u63a5\u89e6\u70b9\u4fe1\u606f\u586b\u5145\u5230\u4f60\u9884\u5148\u5206\u914d\u597d\u7684\u5217\u8868\u6216<code>NativeArray<\/code>\u4e2d\uff0c\u4ece\u800c\u907f\u514d\u4e86\u91cd\u590d\u521b\u5efa\u6570\u7ec4\u5e26\u6765\u7684GC\u5f00\u9500\u3002\u5bf9\u4e8e\u7269\u7406\u67e5\u8be2\uff0c\u4e5f\u6709\u4e00\u7cfb\u5217 <code>Physics.RaycastNonAlloc<\/code> \u8fd9\u6837\u7684\u201cNonAlloc\u201d\u7248\u672cAPI\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>\u7ed3\u8bba<\/strong>\uff1a<code>Mesh Collider<\/code>\u7684\u5e95\u5c42\u662f\u96f6GC\u7684\uff0c\u4f46\u5f00\u53d1\u8005\u5728C#\u5c42\u5bf9\u7269\u7406\u4fe1\u606f\u7684<strong>\u8bbf\u95ee\u65b9\u5f0f<\/strong>\u51b3\u5b9a\u4e86\u6700\u7ec8\u662f\u5426\u4f1a\u4ea7\u751fGC\u3002\u9700\u8981\u6709\u610f\u8bc6\u5730\u4f7f\u7528\u6700\u65b0\u7684\u975e\u5206\u914dAPI\uff0c\u624d\u80fd\u5728\u5b9e\u8df5\u4e2d\u8d8b\u8fd1\u4e8e\u96f6GC\u3002\u800c\u8bfe\u7a0b\u4f5c\u4e1a\u90a3\u79cd\u4ece\u5e95\u5c42\u5c31\u5b8c\u5168\u63a7\u5236\u5185\u5b58\u7684\u5b9e\u73b0\uff0c\u5219\u4ece\u67b6\u6784\u4e0a\u4fdd\u8bc1\u4e86\u96f6GC\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4.Unity\u81ea\u5e26\u7684Mesh Collider\u662f\u4e0d\u5b58\u5728\u8de8\u8bed\u8a00\u8c03\u7528\u5f00\u9500\u7684\u5417\uff1f<\/h2>\n\n\n\n<p><strong>\u56de\u7b54\uff1a\u8fd9\u4e2a\u8bf4\u6cd5\u662f\u9519\u8bef\u7684\u3002<code>Mesh Collider<\/code>\u6070\u6070\u662f\u8de8\u8bed\u8a00\u8c03\u7528\u7684\u5178\u578b\u4ee3\u8868\uff0c\u5b83\u5fc5\u7136\u5b58\u5728\u5f00\u9500\u3002<\/strong><\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u4ec0\u4e48\u662f\u8de8\u8bed\u8a00\u8c03\u7528\u5f00\u9500\uff08Interop Overhead\uff09<\/strong>\uff1a Unity\u7684\u811a\u672c\u903b\u8f91\uff08\u6e38\u620f\u73a9\u6cd5\uff09\u8fd0\u884c\u5728C#\u6258\u7ba1\u73af\u5883\u4e2d\uff08Mono\u6216IL2CPP\uff09\uff0c\u800c\u7269\u7406\u5f15\u64ce\uff08PhysX\uff09\u662fC++\u539f\u751f\u4ee3\u7801\u3002\u5f53C#\u4ee3\u7801\u9700\u8981\u8c03\u7528\u7269\u7406\u529f\u80fd\uff08\u4f8b\u5982\uff0c\u7ed9\u521a\u4f53\u65bd\u52a0\u529b <code>rigidbody.AddForce()<\/code>\uff09\uff0c\u6216\u8005\u5f53\u7269\u7406\u5f15\u64ce\u9700\u8981\u901a\u77e5C#\u4ee3\u7801\u53d1\u751f\u4e86\u67d0\u4ef6\u4e8b\uff08\u4f8b\u5982\uff0c\u8c03\u7528<code>OnCollisionEnter<\/code>\uff09\uff0c\u6570\u636e\u548c\u6267\u884c\u63a7\u5236\u6743\u5c31\u9700\u8981\u7a7f\u8fc7\u4e00\u5ea7\u201c\u6865\u6881\u201d\uff0c\u5728C#\u548cC++\u4e24\u4e2a\u4e16\u754c\u4e4b\u95f4\u6765\u56de\u4f20\u9012\u3002\u8fd9\u4e2a\u7a7f\u8d8a\u201c\u6865\u6881\u201d\u7684\u8fc7\u7a0b\u4e0d\u662f\u6ca1\u6709\u4ee3\u4ef7\u7684\uff0c\u5176\u5f00\u9500\u4e3b\u8981\u5305\u62ec\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u7f16\u7ec4\uff08Marshalling\uff09<\/strong>\uff1a\u9700\u8981\u5c06\u6570\u636e\u4eceC#\u7684\u5185\u5b58\u5e03\u5c40\u8f6c\u6362\u6210C++\u8ba4\u8bc6\u7684\u5185\u5b58\u5e03\u5c40\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u4f8b\u5982\uff0c\u5c06\u4e00\u4e2aC#\u7684<code>Vector3<\/code>\u7ed3\u6784\u4f53\u4f20\u9012\u7ed9C++\u51fd\u6570\u3002\u5bf9\u4e8e\u7b80\u5355\u7684\u6570\u636e\u7c7b\u578b\uff08blittable types\uff09\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5f88\u5feb\uff0c\u4f46\u5bf9\u4e8e\u590d\u6742\u7c7b\u578b\uff08\u5982\u5b57\u7b26\u4e32\u3001\u6258\u7ba1\u6570\u7ec4\uff09\uff0c\u5f00\u9500\u4f1a\u663e\u8457\u589e\u52a0\u3002<\/li>\n\n\n\n<li><strong>\u4e0a\u4e0b\u6587\u5207\u6362<\/strong>\uff1a\u6267\u884c\u6d41\u7a0b\u4ece\u4e00\u4e2a\u8fd0\u884c\u65f6\u73af\u5883\u5207\u6362\u5230\u53e6\u4e00\u4e2a\uff0c\u8fd9\u672c\u8eab\u5c31\u6709\u5fae\u5c0f\u7684\u6027\u80fd\u6210\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5f00\u9500\u6709\u591a\u5927\uff1f<\/strong> \u5bf9\u4e8e\u5355\u6b21\u8c03\u7528\uff0c\u8fd9\u4e2a\u5f00\u9500\u975e\u5e38\u975e\u5e38\u5c0f\uff0c\u901a\u5e38\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\u3002\u4f46\u5982\u679c\u4f60\u7684\u6e38\u620f\u6bcf\u4e00\u5e27\u90fd\u9700\u8981\u8fdb\u884c\u6210\u5343\u4e0a\u4e07\u6b21\u8fd9\u6837\u7684\u8c03\u7528\uff08\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u5faa\u73af\u91cc\u9891\u7e41\u67e5\u8be2\u7269\u7406\u6216\u4fee\u6539\u5927\u91cf\u521a\u4f53\u72b6\u6001\uff09\uff0c\u8fd9\u4e9b\u5fae\u5c0f\u7684\u5f00\u9500\u7d2f\u79ef\u8d77\u6765\u5c31\u53ef\u80fd\u6210\u4e3a\u6027\u80fd\u74f6\u9888\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u7ed3\u8bba<\/strong>\uff1a<code>Mesh Collider<\/code>\u548c\u5176\u80cc\u540e\u7684PhysX\u5f15\u64ce\u4e0eC#\u811a\u672c\u4e4b\u95f4\u7684<strong>\u6bcf\u4e00\u6b21\u4ea4\u4e92\u90fd\u5b58\u5728\u8de8\u8bed\u8a00\u8c03\u7528\u5f00\u9500<\/strong>\u3002\u56e0\u6b64\uff0cSAT\u78b0\u649e\u68c0\u6d4b\u9879\u76ee\uff0c\u5b83\u4f7f\u7528<strong>Burst\u7f16\u8bd1\u5668<\/strong>\u5c06C#\u4ee3\u7801\u76f4\u63a5\u7f16\u8bd1\u6210\u4e0eC++\u6027\u80fd\u76f8\u5f53\u7684\u672c\u5730\u673a\u5668\u7801\uff0c\u5e76\u4f7f\u7528<code>NativeContainer<\/code>\u7b49\u6570\u636e\u7ed3\u6784\uff0c<strong>\u5b8c\u5168\u6d88\u9664\u4e86\u8fd9\u79cd\u8de8\u8bed\u8a00\u8c03\u7528\u7684\u201c\u6865\u6881\u201d<\/strong>\u3002\u6574\u4e2a\u8ba1\u7b97\u8fc7\u7a0b\u90fd\u4fdd\u6301\u5728\u540c\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u539f\u751f\u4ee3\u7801\u73af\u5883\u4e2d\uff0c\u5b9e\u73b0\u4e86\u6570\u636e\u7684\u65e0\u7f1d\u6d41\u8f6c\uff0c\u4ece\u800c\u5728\u9700\u8981\u5927\u89c4\u6a21\u8ba1\u7b97\u7684\u573a\u666f\u4e0b\u83b7\u5f97\u4e86\u5de8\u5927\u7684\u6027\u80fd\u4f18\u52bf\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u548cUnity\u81ea\u5e26\u7684Mesh Collider\u7684\u533a\u522b \u867d\u7136\u5bf9\u4e8e\u5e38\u89c4\u6e38\u620f\u5f00\u53d1\u9700\u6c42\uff0cUnity\u81ea\u5e26\u7684Mesh Collider\u786e\u5b9e\u529f &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[34],"tags":[36,39,41],"class_list":["post-669","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-unity","tag-41"],"_links":{"self":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts\/669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/comments?post=669"}],"version-history":[{"count":2,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts\/669\/revisions"}],"predecessor-version":[{"id":672,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts\/669\/revisions\/672"}],"wp:attachment":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/media?parent=669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/categories?post=669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/tags?post=669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}