{"id":377,"date":"2015-06-24T10:37:39","date_gmt":"2015-06-24T02:37:39","guid":{"rendered":"http:\/\/39.100.100.179\/?p=377"},"modified":"2016-10-11T09:32:11","modified_gmt":"2016-10-11T01:32:11","slug":"unity3d%e4%b8%adjs%e4%b8%8ec%e4%b9%8b%e9%97%b4%e7%9b%b8%e4%ba%92%e8%b0%83%e7%94%a8%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=377","title":{"rendered":"js\u4e0eC#\u4e4b\u95f4\u76f8\u4e92\u8c03\u7528\u7684\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<p style=\"text-align: center;\"><span style=\"color: #ff0000;\">\u8f6c\u81ea\uff1a<\/span><a href=\"http:\/\/www.unitymanual.com\/3102.html\" target=\"_blank\">http:\/\/www.unitymanual.com\/3102.html<\/a><\/p>\n<p><a href=\"http:\/\/www.unitymanual.com\/\" target=\"_blank\"><strong>Unity3D<\/strong><\/a>\u4e2d\u4e00\u4e9b\u811a\u672c\u7684\u65b9\u6cd5\u53ea\u80fd\u7528\u5728JS\u4e2d\uff0c\u5728C#\u4e2d\u662f\u65e0\u6548\u7684\uff0c\u800cC#\u53ef\u4ee5\u4e0e\u670d\u52a1\u5668\u7aef\u901a\u8baf\uff0cJS\u672c\u8eab\u5374\u4e0d\u884c\u3002\u800c\u4e14\uff0c\u5982\u679c\u9700\u8981\u7528\u5230js\u8c03\u7528c#\u7684\u95ee\u9898\uff0cjs\u4f1a\u6bd4c#\u5148\u7f16\u8bd1\uff0c\u6240\u4ee5\u5728mac\u91cc\u7f16\u8bd1ios\u7684\u65f6\u5019\u4f1a\u51fa\u9519\uff0c\u63d0\u793a\u4e3a\u65e0\u6cd5\u627e\u5230\u90a3\u4e2aC#\u7c7b\u3002\u6240\u4ee5\u52bf\u5fc5\u4f1a\u9047\u5230\u8fd9\u4e24\u79cd\u8bed\u8a00\u811a\u672c\u4e2d\u65b9\u6cd5\u7684\u4e92\u76f8\u8c03\u7528\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>1.\u9996\u5148\u5728\u4f60\u7684Unity3D\u7a0b\u5e8f\u91cc\u5efa\u4e00\u4e2aPlugins\u7684\u6587\u4ef6\u5939\uff0c\u6ce8\u610f\u5fc5\u987b\u662f\u8fd9\u4e2a\u540d\u5b57\uff01<\/p>\n<p>2.\u5c06\u8981\u8c03\u7528\u7684C#\u7c7b\u91cc\u7684\u7cfb\u7edf\u547d\u540d\u7a7a\u95f4\u53bb\u6389\uff0c\u53ea\u4fdd\u7559\u5fc5\u987b\u8981\u7528\u7684\u547d\u540d\u7a7a\u95f4\uff0c\u7c7b\u540d\u540e\u9762\u7684\u7236\u7c7b\u4e5f\u53bb\u6389\uff0c\u5c06\u91cc\u9762\u7684\u65b9\u6cd5\u8bbe\u4e3a\u9759\u6001\u7684\u65b9\u6cd5\u3002<\/p>\n<p>3.\u5c06\u8fd9\u4e2aC#\u7c7b\u65b9\u6cd5Plugins\u6587\u4ef6\u5939\u4e0b\u3002<\/p>\n<p>4.\u5728js\u91cc\u5c31\u53ef\u4ee5\u76f4\u63a5\u5f15\u7528\u4e86\uff0c\u5982\uff1atest.test();<\/p>\n<p>\u5b9e\u4f8b\uff1a\u4e24\u4e2a\u6587\u4ef6 test1.js \u548c test2.cs\u3002<\/p>\n<p>test1.js<\/p>\n<pre class=\"lang:js decode:true \">function OnGUI()\r\n\r\n{\r\n\r\nif(GUI.Button(Rect(25,25,100,30),\"JS Call CS\" ))\r\n\r\n{\r\n\r\nvar c = gameObject.GetComponent(\"test2\");\r\n\r\nc.PrintTest();\r\n\r\n}\r\n\r\n}\r\n\r\nfunction testPrint()\r\n\r\n{\r\n\r\nprint(\"CS Call JS\");\r\n\r\n}<\/pre>\n<p>test2.cs<\/p>\n<pre class=\"lang:c# decode:true \">using UnityEngine;\r\n\r\nusing System.Collections;\r\n\r\npublic class test2: MonoBehaviour {\r\n\r\nvoid OnGUI()\r\n\r\n{\r\n\r\nif(GUI.Button(new Rect(25,70,100,30), \"CS Call JS\"))\r\n\r\n{\r\n\r\ntest1 c = (test1)gameObject.GetComponent(\"test1\");\r\n\r\nc.testPrint();\r\n\r\n}\r\n\r\n}\r\n\r\nvoid PrintTest()\r\n\r\n{\r\n\r\nprint(\"JS Call CS\");\r\n\r\n}\r\n\r\n}<\/pre>\n<p>\u8fd9\u91cc\u5fc5\u987b\u8981\u6ce8\u610f\u7684\u662fJS\u6587\u4ef6\u5fc5\u987b\u662f\u5728 \"Standard Assets\"\u3001 \"Pro Standard Assets\" \u548c \"Plugins\" \u8fd9\u4e09\u4e2a\u76ee\u5f55\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u91cc\uff0c\u800cCS\u6587\u4ef6\u4e0d\u80fd\u4e0eJS\u6587\u4ef6\u5728\u4e00\u4e2a\u76ee\u5f55\u4e2d\u3002\u539f\u56e0\u662f\uff0c\u8fd9\u4e09\u4e2a\u76ee\u5f55\u91cc\u7684\u811a\u672c\u88ab\u6700\u5148\u7f16\u8bd1\uff0c\"Editor\"\u76ee\u5f55\u91cc\u7684\u7a0d\u540e\u7f16\u8bd1\uff0c\u5176\u4ed6\u7684\u811a\u672c\u6700\u540e\u7f16\u8bd1\u3002\u76ee\u524dUnity3D\u76842.5\u7684\u7248\u672c\u4f3c\u4e4e\u4e0d\u652f\u6301C# 3.0\uff0c\u6240\u4ee5\u65e0\u6cd5\u7528var\u7684\u5173\u952e\u5b57\uff0c\u8fd9\u6837\u5c31\u53ea\u652f\u6301\u5f3a\u7c7b\u578b\uff0c\u6240\u4ee5\u5982\u679c\u5728\u4e00\u4e2a\u76ee\u5f55\u4e0b\u5219CS\u6587\u4ef6\u65e0\u6cd5\u8bfb\u53d6JS\u91cc\u7684\u65b9\u6cd5\uff0c\u4e5f\u5c31\u65e0\u6cd5\u7f16\u8bd1\u901a\u8fc7\u4e86\u3002\u800cJS\u8c03\u7528CS\u65b9\u6cd5\u5219\u65e0\u6b64\u9650\u5236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea\uff1ahttp:\/\/www.unitymanual.com\/3102.html  &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=377\">\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":[23],"tags":[97,96],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/377"}],"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=377"}],"version-history":[{"count":3,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions"}],"predecessor-version":[{"id":734,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions\/734"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}