当前位置:   article > 正文

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

c# action lua 引用

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

test.lua

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

}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

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();
    }



}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/253741
推荐阅读
相关标签
  

闽ICP备14008679号