{"id":211,"date":"2017-02-21T20:05:07","date_gmt":"2017-02-21T12:05:07","guid":{"rendered":"http:\/\/www.yarpee.com\/?p=211"},"modified":"2017-02-21T20:44:11","modified_gmt":"2017-02-21T12:44:11","slug":"unity-script-bindings-to-a-c-class","status":"publish","type":"post","link":"http:\/\/www.yarpee.cn\/?p=211","title":{"rendered":"Unity script bindings to a C++ class"},"content":{"rendered":"<p>Unity\u6e90\u7801\u4e2dC#\u5230C++\u7684\u7ed1\u5b9a\u662f\u901a\u8fc7\u4e00\u4e2a\u63cf\u8ff0C#\u548cC++\u4ee3\u7801\u7684txt\u6587\u4ef6\uff08\u5982UnityEngineGameObject.txt\uff09\u6765\u751f\u6210\u7684\u3002<\/p>\n<p>\u8fd9\u7c7b\u6587\u4ef6\u653e\u5728Runtime\\Export\u548cEditor\\Mono\u76ee\u5f55\u4e0b\uff0cUnity\u6e90\u7801\u4f1a\u6839\u636e\u5b83\u4eec\u751f\u6210\u4e00\u4e2a.cs\u548c\u4e00\u4e2a.cpp\u6587\u4ef6\u3002.cs\u6587\u4ef6\u63d0\u4f9b\u4e86C#\u5c42\u7684\u63a5\u53e3\uff0c.cpp\u6587\u4ef6\u901a\u8fc7mono_add_internal_call\u5b9e\u73b0\u4e86C#\u5230C++\u7684\u7ed1\u5b9a\u3002<\/p>\n<p>Unity\u91c7\u7528Embedding Mono\u7684\u65b9\u5f0f\u5b9e\u73b0C#\u5230C++\u7684\u8c03\u7528\uff0cEmbedding Mono\u53c2\u8003<a href=\"http:\/\/www.mono-project.com\/docs\/advanced\/embedding\/\" target=\"_blank\">http:\/\/www.mono-project.com\/docs\/advanced\/embedding\/<\/a>\u3002<\/p>\n<p>\u5176C#\u5c42\u7684\u5bf9\u8c61\u90fd\u7ee7\u627f\u4e8eUnityEngine.Object\uff0cObject\u4e2d\u6709\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u6210\u5458\u53d8\u91cfm_UnityRuntimeReferenceData\uff1a<br \/>\n<a href=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/1.png\" rel=\"attachment wp-att-214\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-214\" src=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/1.png\" alt=\"m_UnityRuntimeReferenceData\" width=\"427\" height=\"366\" srcset=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/1.png 427w, http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/1-300x257.png 300w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/a><\/p>\n<div>ReferenceData\u7ed3\u6784\uff1a<\/div>\n<p><a href=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/2.png\" rel=\"attachment wp-att-215\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-215\" src=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/2.png\" alt=\"ReferenceData\" width=\"253\" height=\"167\" \/><\/a><\/p>\n<p>Unity\u901a\u8fc7\u8fd9\u91cc\u7684cachedPtr\u5b58\u50a8C++\u5c42\u4e0e\u4e4b\u5173\u8054\u7684\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002<\/p>\n<p>\u5f53C#\u5c42\u901a\u8fc7Mono\u8c03\u7528C++\u65b9\u6cd5\u65f6\u4f20\u5165\u5bf9\u8c61\u7684this\u5f15\u7528\uff0cC++\u65b9\u6cd5\u5c06\u83b7\u5f97\u4e00\u4e2aMonoObject\u7684\u5bf9\u8c61\u6307\u9488\uff08MonoObject*\uff0cUnity typedef MonoObject\u4e3aScriptingObject\uff09\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u6307\u9488\u6307\u5411\u7684\u5185\u5b58\u5176\u5b9e\u5c31\u662fC#\u5bf9\u8c61\u7684\u5185\u5b58\uff0c\u5176\u5185\u5b58\u5e03\u5c40\u5982\u56fe\uff1a<br \/>\n<a href=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/3.png\" rel=\"attachment wp-att-216\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-216\" src=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/3.png\" alt=\"3\" width=\"197\" height=\"98\" \/><\/a><br \/>\n<a href=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/4.png\" rel=\"attachment wp-att-217\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-217\" src=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/4.png\" alt=\"4\" width=\"142\" height=\"159\" \/><\/a><\/p>\n<p>\u5982\u4e0a\u56fe\uff0cMono\u4e2d\u6bcf\u4e2aC#\u5bf9\u8c61\u7684\u5185\u5b58\u5e03\u5c40\u90fd\u4ee5MonoObject\u5f00\u59cb\uff0c\u800cUnity\u4e2d\u6bcf\u4e2aC#\u5bf9\u8c61\u7684\u5185\u5b58\u5e03\u5c40\u662f\u7d27\u63a5\u5728MonoObject\u540e\u4f1a\u6709\u4e00\u4e2aReferenceData\u3002\u56e0\u6b64Unity C++\u5c42\u5b9a\u4e49\u4e86\u4e00\u4e2aUnityEngineObjectMemoryLayout\u4e0eC#\u5c42ReferenceData\u76f8\u5bf9\u5e94\uff1a<br \/>\n<a href=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/5.png\" rel=\"attachment wp-att-218\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-218\" src=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/5.png\" alt=\"5\" width=\"356\" height=\"202\" srcset=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/5.png 356w, http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/5-300x170.png 300w\" sizes=\"(max-width: 356px) 100vw, 356px\" \/><\/a><\/p>\n<div style=\"text-align: center;\">Runtime\\Scripting\\Scripting.h<\/div>\n<\/p>\n<p>MonoObject\u7684\u5b9a\u4e49\uff1a<br \/>\n<a href=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/6.png\" rel=\"attachment wp-att-219\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-219\" src=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/6.png\" alt=\"6\" width=\"313\" height=\"78\" srcset=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/6.png 313w, http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/6-300x75.png 300w\" sizes=\"(max-width: 313px) 100vw, 313px\" \/><\/a><br \/>\n<a href=\"https:\/\/github.com\/mono\/mono\/blob\/master\/mono\/metadata\/object.h\" target=\"_blank\">https:\/\/github.com\/mono\/mono\/blob\/master\/mono\/metadata\/object.h<\/a><br \/>\n<a href=\"http:\/\/docs.go-mono.com\/index.aspx?link=xhtml%3Adeploy%2Fmono-api-object.html\" target=\"_blank\">http:\/\/docs.go-mono.com\/index.aspx?link=xhtml%3Adeploy%2Fmono-api-object.html<\/a><\/p>\n<p>Unity C++\u5c42\u901a\u8fc7\u5c06C#\u5c42\u7684\u5bf9\u8c61\u5185\u5b58\u5730\u5740+8bytes\u6765\u53d6\u5f97ReferenceData\u7ed3\u6784\u5e76\u89e3\u6790\u4e3aUnityEngineObjectMemoryLayout\uff0c\u540c\u65f6\u5c06C++\u5c42\u4e0eC#\u7ed1\u5b9a\u7684\u5bf9\u8c61\u4f7f\u7528cachedPtr\u8fdb\u884c\u5b58\u53d6\u3002<br \/>\n<a href=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/7.png\" rel=\"attachment wp-att-220\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-220\" src=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/7.png\" alt=\"7\" width=\"1105\" height=\"574\" srcset=\"http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/7.png 1105w, http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/7-300x156.png 300w, http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/7-768x399.png 768w, http:\/\/www.yarpee.cn\/wp-content\/uploads\/2017\/02\/7-1024x532.png 1024w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unity\u6e90\u7801\u4e2dC#\u5230C++\u7684\u7ed1\u5b9a\u662f\u901a\u8fc7\u4e00\u4e2a\u63cf\u8ff0C#\u548cC++\u4ee3\u7801\u7684txt\u6587\u4ef6\uff08\u5982UnityEngineGame &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.yarpee.cn\/?p=211\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cUnity script bindings to a C++ class\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-211","post","type-post","status-publish","format-standard","hentry","category-unity"],"_links":{"self":[{"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=\/wp\/v2\/posts\/211"}],"collection":[{"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211"}],"version-history":[{"count":10,"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":228,"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions\/228"}],"wp:attachment":[{"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yarpee.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}