{"id":35764,"date":"2025-05-06T17:15:59","date_gmt":"2025-05-06T09:15:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/35764.html"},"modified":"2025-05-06T17:15:59","modified_gmt":"2025-05-06T09:15:59","slug":"%e3%80%90unity%e3%80%91%e4%bd%bf%e7%94%a8xlua%e5%ae%9e%e7%8e%b0c%e8%ae%bf%e9%97%aelua%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/35764.html","title":{"rendered":"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6"},"content":{"rendered":"<p> <span style=\"background-color:#ff9c99\"><span style=\"color:#333333\">\u5148\u5f15\u5165XLua\u6587\u4ef6\u4e2d\u7684Plugins\u548cXLua\u6587\u4ef6\u5939\u4e8eUnity\u9879\u76ee\u7684Asset\u6587\u4ef6\u4e2d<\/span><\/span> <\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\">XLua_github\u94fe\u63a5<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"735\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250506091558-6819d34e29b93.png\" width=\"1882\" \/><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\">\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#92d050\"><span style=\"color:#333333\">\u5efa\u7acbLua\u865a\u62df\u673a<\/span><\/span><span style=\"color:#333333\">&#xff1a;LuaEnv luaEnv &#061; new LuaEnv();<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#92d050\"><span style=\"color:#333333\">\u5173\u95ed\u865a\u62df\u673a<\/span><\/span><span style=\"color:#333333\">&#xff0c;\u53ca\u65f6\u91ca\u653e\u8d44\u6e90&#xff1a;luaEnv.Dispose();<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#92d050\"><span style=\"color:#333333\">Resources\u6587\u4ef6\u5939\u4e0b\u52a0\u8f7dlua\u6587\u4ef6<\/span><\/span><span style=\"color:#333333\">&#xff08;\u5047\u8bbe\u6587\u4ef6\u8def\u5f84\u4e3aResources\/Lua\/test.lua.text&#xff09;:<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">luaEnv.DoString(&#034;require &#039;lua\/test&#039;&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#92d050\"><span style=\"color:#333333\">\u52a0\u8f7d\u81ea\u5b9a\u4e49\u6587\u4ef6\u5939\u4e0b\u7684lua\u6587\u4ef6&#xff08;\u5047\u8bbe\u6587\u4ef6\u8def\u5f84\u4e3aAsset\/Lua\/test.lua&#xff09;<\/span><\/span><span style=\"color:#333333\">&#xff1a;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(a)\u7f16\u5199\u52a0\u8f7dLua\u6587\u4ef6\u7684\u52a0\u8f7d\u5668&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">private byte[] LoadLua(ref string file)<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">{<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">string luaStr &#061; File.ReadAllText(Application.dataPath &#043; &#034;\/Lua\/&#034; &#043; file &#043; &#034;.lua&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">byte[] luaByte &#061; new UTF8Encoding().GetBytes(luaStr);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">return luaByte;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">}<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(b)\u4e3a\u865a\u62df\u673a\u6dfb\u52a0Lua\u52a0\u8f7d\u5668&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">luaEnv.AddLoader(LoadLua);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(c)\u8fd0\u884clua\u6587\u4ef6&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">luaEnv.DoString(&#034;require &#039;test&#039;&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\">\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">\u5047\u8bbe\u6709test.lua:<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">a &#061; 1<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">b &#061; true<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">c &#061; &#034;\u4f60\u597d\u561b&#034;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">table1 &#061; {&#034;aa&#034;, &#034;bb&#034;, &#034;cc&#034;, &#034;12&#034;, &#034;23&#039;, true, false}<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">person &#061; <\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">{<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">name &#061; &#034;zhaoxi&#034;,<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">age &#061; 18<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">}<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">function Add(a, b)<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">return a &#043; b<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">end<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">function Get(a, b)<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">return a,b<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#f2f2f2\"><span style=\"color:#333333\">end<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\">\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#92d050\"><span style=\"color:#333333\">\u83b7\u53d6lua\u6587\u4ef6\u7684\u5168\u5c40\u53d8\u91cf&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">int&#xff1a;int a &#061; luaEnv.Global.Get&lt;int&gt;(&#034;a&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">bool&#xff1a;bool b &#061; luaEnv.Global.Get&lt;bool&gt;(&#034;b&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">string&#xff1a;string c &#061; luaEnv.Global.Get&lt;string&gt;(&#034;c&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\">\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#92d050\"><span style=\"color:#333333\">\u8bbf\u95eetable\u7684\u56db\u79cd\u65b9\u5f0f:<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffdcc4\"><span style=\"color:#333333\">&#xff08;1&#xff09;\u503c\u7c7b\u578b\u65b9\u5f0f&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#00b0f0\"><span style=\"color:#333333\">&#xff08;1-1&#xff09;\u7c7b\u7684\u5f62\u5f0f\u8bbf\u95ee&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(a)\u5b9a\u4e49\u4e00\u4e2a\u7c7bPerson&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">public class Person<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">{<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">public string name;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">public int age;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">}<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(b)\u83b7\u53d6lua\u6570\u636e&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Person person &#061; luaEnv.Global.Get&lt;Person&gt;(&#034;person&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(person.name &#043; person.age);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#00b0f0\"><span style=\"color:#333333\">&#xff08;1-2&#xff09;Dictionary List\u7684\u65b9\u5f0f\u8bbf\u95ee&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Dictionary&lt;string, object&gt; tableDic &#061; luaEnv.Global.Get&lt;Dictionary&lt;string, object&gt;&gt;(&#034;person&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(tableDic[&#034;name&#034;] &#043; &#034; &#034; &#043; tableDic[&#034;age&#034;]);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">List&lt;Object&gt; tableList &#061; lua.Global.Get&lt;List&lt;object&gt;&gt;(&#034;table1&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(tableList[0].ToString());<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffdcc4\"><span style=\"color:#333333\">&#xff08;2&#xff09;\u5f15\u7528\u7c7b\u578b\u8bbf\u95ee&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#00b0f0\"><span style=\"color:#333333\">&#xff08;2-1&#xff09;\u63a5\u53e3\u8bbf\u95ee&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(a)\u5b9a\u4e49\u63a5\u53e3IPerson(\u9700\u6302\u8f7d[CSharpCallLua])&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">[CSharpCallLua]<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">public interface IPerson<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">{<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">public string name{get; set;}<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">public int age{get; set;}<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">}<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(b)\u63a5\u6536\u6765\u81eaLua\u7684\u6570\u636e&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">IPerson iperson &#061; luaEnv.Global.Get&lt;IPerson&gt;(&#034;person&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(iperson.name);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">iperson.name &#061; &#039;&#039;yeye&#039;&#039;;\/\/\u4fee\u6539lua\u6570\u636e&#xff0c;\u4f46\u4e0d\u4f1a\u5bf9\u539flua\u6587\u4ef6\u9020\u6210\u5f71\u54cd<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">luaEnv.DoString(&#034;print(person.name)&#034;);\/\/\u6253\u5370\u4e3ayeye<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#00b0f0\"><span style=\"color:#333333\">&#xff08;2-2&#xff09;LuaTable\u7684\u65b9\u5f0f\u8bbf\u95ee(\u80fd\u591f\u5b9e\u73b0\u52a8\u6001\u884c\u4e3a&#xff0c;\u51cf\u5c11\u7f16\u8bd1\u65f6\u95f4&#xff0c;\u4f46\u662f\u6027\u80fd\u5f00\u9500\u8f83\u5927&#xff0c;\u4e14\u96be\u4ee5\u8ffd\u8e2a\u95ee\u9898\u8fd8\u4f1a\u62a5\u7c7b\u578b\u5b89\u5168\u7684\u9519\u8bef\u7b49\u7b49&#xff09;&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">LuaTable luaTable &#061; luaEnv.Global.Get&lt;LuaTable&gt;(&#034;person&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(luaTable.Get&lt;string&gt;(&#034;name&#034;));\/\/\u6253\u5370&#034;zhaoxi&#034;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\">\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#92d050\"><span style=\"color:#333333\">\u8bbf\u95ee\u5168\u5c40\u51fd\u6570&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffdcc4\"><span style=\"color:#333333\">&#xff08;1&#xff09;\u4f7f\u7528\u59d4\u6258\u8bbf\u95ee&#xff08;\u9700\u5728\u59d4\u6258\u524d\u6302\u8f7d[CSharpCallLua]&#xff09;\u4f18\u70b9&#xff1a;\u8c03\u7528\u76f4\u63a5\u3001\u6027\u80fd\u5feb\u4f46\u662f\u7075\u6d3b\u6027\u5dee<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(a)\u5b9a\u4e49\u59d4\u6258<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">[CSharpCallLua] public delegate int Add(int a, int b);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">[CSharpCallLua] public delegate int Get(int a, int b, out int c);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffc000\"><span style=\"color:#333333\">(b)\u83b7\u53d6\u51fd\u6570<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Add addFunc &#061; luaEnv.Global.Get&lt;Add&gt;(&#034;add&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">addFunc(1, 2);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\">\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Get get &#061; luaEnv.Global.Get&lt;Get&gt;(&#034;get&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">int num1, num2;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">num1 &#061; get(1, 2, out num2);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(num1 &#043; &#034; &#034; &#043; num2);\/\/num1 &#061; 1, num2 &#061; 2<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"background-color:#ffdcc4\"><span style=\"color:#333333\">&#xff08;2&#xff09;\u4f7f\u7528LuaFunction\u4f18\u70b9&#xff1a;\u7075\u6d3b\u6027\u9ad8&#xff0c;\u51cf\u5c11C#\u4e0eLua\u7684\u6865\u63a5\u4ee3\u7801<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">LuaFunction luaFunction &#061; luaEnv.Global.Get&lt;LuaFunction&gt;(&#034;add&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">LuaFunction luaFunction1 &#061; luaEnv.Global.Get&lt;LuaFunction&gt;(&#034;get&#034;);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">object[] obs &#061; luaFuction.Call(1, 2);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">object[] obs1 &#061; luaFunction.Call(1, 2);<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(obs[0]);\/\/3<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:left\"><span style=\"color:#333333\">Debug.Log(obs[0] &#043; &#034; &#034; &#043; obs[1]);\/\/1, 2<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb738\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\/\u4fee\u6539lua\u6570\u636e\uff0c\u4f46\u4e0d\u4f1a\u5bf9\u539flua\u6587\u4ef6\u9020\u6210\u5f71\u54cd\u3002\u52a0\u8f7d\u81ea\u5b9a\u4e49\u6587\u4ef6\u5939\u4e0b\u7684lua\u6587\u4ef6\uff08\u5047\u8bbe\u6587\u4ef6\u8def\u5f84\u4e3aAsset\/Lua\/test.lua\uff09\uff082\uff09\u4f7f\u7528LuaFunction\u4f18\u70b9\uff1a\u7075\u6d3b\u6027\u9ad8\uff0c\u51cf\u5c11C#\u4e0eLua\u7684\u6865\u63a5\u4ee3\u7801\u3002\u5148\u5f15\u5165XLua\u6587\u4ef6\u4e2d\u7684Plugins\u548cXLua\u6587\u4ef6\u5939\u4e8eAsset\u6587\u4ef6\u4e2d\u3002\uff0c\u53ca\u65f6\u91ca\u653e\u8d44\u6e90\uff1aluaEnv.Dispose();<\/p>\n","protected":false},"author":2,"featured_media":35763,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3056,55,1463,183],"topic":[],"class_list":["post-35764","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-clua","tag-c","tag-lua","tag-unity"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/35764.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb738\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\/\u4fee\u6539lua\u6570\u636e\uff0c\u4f46\u4e0d\u4f1a\u5bf9\u539flua\u6587\u4ef6\u9020\u6210\u5f71\u54cd\u3002\u52a0\u8f7d\u81ea\u5b9a\u4e49\u6587\u4ef6\u5939\u4e0b\u7684lua\u6587\u4ef6\uff08\u5047\u8bbe\u6587\u4ef6\u8def\u5f84\u4e3aAsset\/Lua\/test.lua\uff09\uff082\uff09\u4f7f\u7528LuaFunction\u4f18\u70b9\uff1a\u7075\u6d3b\u6027\u9ad8\uff0c\u51cf\u5c11C#\u4e0eLua\u7684\u6865\u63a5\u4ee3\u7801\u3002\u5148\u5f15\u5165XLua\u6587\u4ef6\u4e2d\u7684Plugins\u548cXLua\u6587\u4ef6\u5939\u4e8eAsset\u6587\u4ef6\u4e2d\u3002\uff0c\u53ca\u65f6\u91ca\u653e\u8d44\u6e90\uff1aluaEnv.Dispose();\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/35764.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-06T09:15:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250506091558-6819d34e29b93.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35764.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/35764.html\",\"name\":\"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-06T09:15:59+00:00\",\"dateModified\":\"2025-05-06T09:15:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/35764.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/35764.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35764.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/35764.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb738\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf10\u6b21\u3002\/\u4fee\u6539lua\u6570\u636e\uff0c\u4f46\u4e0d\u4f1a\u5bf9\u539flua\u6587\u4ef6\u9020\u6210\u5f71\u54cd\u3002\u52a0\u8f7d\u81ea\u5b9a\u4e49\u6587\u4ef6\u5939\u4e0b\u7684lua\u6587\u4ef6\uff08\u5047\u8bbe\u6587\u4ef6\u8def\u5f84\u4e3aAsset\/Lua\/test.lua\uff09\uff082\uff09\u4f7f\u7528LuaFunction\u4f18\u70b9\uff1a\u7075\u6d3b\u6027\u9ad8\uff0c\u51cf\u5c11C#\u4e0eLua\u7684\u6865\u63a5\u4ee3\u7801\u3002\u5148\u5f15\u5165XLua\u6587\u4ef6\u4e2d\u7684Plugins\u548cXLua\u6587\u4ef6\u5939\u4e8eAsset\u6587\u4ef6\u4e2d\u3002\uff0c\u53ca\u65f6\u91ca\u653e\u8d44\u6e90\uff1aluaEnv.Dispose();","og_url":"https:\/\/www.wsisp.com\/helps\/35764.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-06T09:15:59+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250506091558-6819d34e29b93.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/35764.html","url":"https:\/\/www.wsisp.com\/helps\/35764.html","name":"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-06T09:15:59+00:00","dateModified":"2025-05-06T09:15:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/35764.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/35764.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/35764.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Unity\u3011\u4f7f\u7528XLua\u5b9e\u73b0C#\u8bbf\u95eeLua\u6587\u4ef6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=35764"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35764\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/35763"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=35764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=35764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=35764"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=35764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}