int i = LuaManager.Instance.Global.Get<int>("TestNumber"); Debug.Log("TestNumber:" + i);
bool b = LuaManager.Instance.Global.Get<bool>("TestBool"); Debug.Log("TestBool:" + b);
float f = LuaManager.Instance.Global.Get<float>("TestFloat"); Debug.Log("TestFloat:" + f);
double d = LuaManager.Instance.Global.Get<double>("TestFloat"); Debug.Log("TestFloat_double:" + d);
string s = LuaManager.Instance.Global.Get<string>("TestString"); Debug.Log("TestString:" + s);
要注意,这种方式获取的变量都是值拷贝,也就是修改接收到的变量不会影响原来的全局变量
1 2 3 4 5
int i = LuaManager.Instance.Global.Get<int>("TestNumber"); Debug.Log("TestNumber:" + i); i = 10; int i2 = LuaManager.Instance.Global.Get<int>("TestNumber"); Debug.Log("TestNumber:" + i2);
修改全局变量
我们可以通过Set<>()传入变量名和要修改的值获取全局变量(泛型参数可忽略)
1 2 3 4 5
int i = LuaManager.Instance.Global.Get<int>("TestNumber"); Debug.Log("TestNumber:" + i); LuaManager.Instance.Global.Set<string, int>("TestNumber", 55); int i2 = LuaManager.Instance.Global.Get<int>("TestNumber"); Debug.Log("TestNumber_i2:" + i2);