c#调用lua之接口映射table(引用拷贝)

注意:接口没有成员变量,只有属性,包括对应的函数都不能用委托,如果无参,无返回值可以用unityaction,而且接口去接要打上csharpcalllua标记,而且接口是引用拷贝!!!改了值会反应在lua定义的表中

test.lua

--class
--这样定义的表相当于是个自定义的类,有成员变量和成员函数
testClass={
	testInt=1,
	testBool=true,
	testFloat=1.3,
	testString="13",
	testFun=function ()
		-- body
		print("nihaoyahahahahha")
	end,
	

}


c#代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using XLua;

//接口只能用属性去接lua表里的成员,名字也要与lua中定义的一致,
//当接口中增加或者减少属性时,一定要清空生成的代码,然后再重新生成一遍,这个接口才能用,多的或者少的属性依旧会被忽略
//用接口接,是引用拷贝!!!!!,改了值,lua中的东西也会改变
[CSharpCallLua]
public interface ICallLuaClass
{
    
    int testInt
    {
        get;
        set;
    }

    bool testBool
    {
        get;
        set;
    }

    float testFloat
    {
        get;
        set;
    }

    string testString
    {
        get;
        set;
    }

    UnityAction testFun
    {
        get;
        set;
    }


}
public class CallInterface : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        LuaMgr.GetInstance().Init();
        LuaMgr.GetInstance().DoLuaFile("Main");

        ICallLuaClass icc = LuaMgr.GetInstance().Global.Get<ICallLuaClass>("testClass");
        Debug.Log(icc.testInt);
        Debug.Log(icc.testBool);
        Debug.Log(icc.testFloat);
        Debug.Log(icc.testString);
        icc.testFun();
    }



}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值