Lua调用C#(非反射)

来源:互联网 发布:exo中国四子的关系知乎 编辑:程序博客网 时间:2024/06/05 03:30

1.将自定义脚本加入WrapFile中,如下图自定义Test脚本


2.在Unity面板(已经导入ulua_v1.25插件)中点击Lua->Gen Lua Wrap Files即可在ulua->source->luaWrap中生成TestWrap脚本


3.Test脚本如下

using System.Collections.Generic;
using UnityEngine;
public class Test
{
    void Start()
    {
    }
    public void Show()
    {
        Debug.Log("show");
    }
    public static void ShowMess()
    {
        Debug.Log("StaticShow");

    }
    void Update()
    {
    }
}

4.挂载脚本

using System;
using System.Collections.Generic;
using UnityEngine;
using LuaInterface;

class LuaCShapeTest : MonoBehaviour
{
    string script = @"
test = Test();
test:Show();
Test.ShowMess();
";
    void Start()
    {
        LuaScriptMgr mgr = new LuaScriptMgr();
        mgr.Start();
        mgr.DoString(script);
    }
    // Update is called once per frame
    void Update()
    {
    }
}



原创粉丝点击