我也是新手,对于Lua发表一下自己的看法。在我学习Lua的过程中,Unity调用的Lua可以通过委托、结构体、类、接口去调取Lua相对应的属性,方法,以及模块(也就相当于C#里面的类)里面的方法(如果有其他更好用的方法,求大佬讲解)。
//结构体
public struct Son
{
public int Id;
public string s;
}
//类
public class Son1
{
public int Id;
public string s;
}
//接口
public interface Son2
{
public int Id { get; set; }
public string s { get; set; }
public void Func();
}
//委托
public delegate int id;
public delegate int Obj(object a, object b);
在我看来在这四种方式里面接口的用法应该是最好用的,我的推荐也是使用接口去调取。我用别的方式去获取模块里面的方法时,都会出现一些小BUG,所以如果大家想去获取类里面的方法,我在这里推荐各位使用接口。其他的小型数据可以使用结构体的方式去获取是最方便的。
接口的使用:获取类里面的方法
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XLua;
/*
*创建者:
*创建时间:
*描述:
*版本:
*/
[CSharpCallLua]//一定要添加特性,里面的属性名称和方法名称也必须和L