上次已经搭建好了框架,这里开始使用框架,本文会比较长~~因为我搞了一天,也遇到了好多坑
今天主要记录一下 c# 与 lua 的交互~~ 然后配以demo
C# 调用 lua 这个很简单,之前也有说过,这里不废话,直接贴
LuaScriptMgr mgr = new LuaScriptMgr ();
mgr.Start ();
mgr.DoFile ("LoginUI.lua");
难点其实是Lua调用c#,以及效率问题
>> 最古老的是使用反射调用,不过由于反射的性能问题,目前基本上不怎么用了
>>wrap调用提升了反射在效率上的不足,但是必须自己去wrap,所以大版本更新是可以用到的,小版本更新目前还是得用到反射
ok~~ 肯定一头雾水,什么是wrap,怎么生成wrap,wrap工作原理是怎样的?(在今天之前我也是如此多的疑惑)
什么是wrap: wrap是对c#类的成员函数,成员变量,通过映射的方式。这里对比一下两个文件
这个是c#文件
using UnityEngine;
using System.Collections;
public class LoginData {
public string username;
public string password;
public int id;
public LoginData(){
}
public LoginData(string username, string password, int id){
this.username = username;
this.password = password;
this.id = id;
}
public void Equip(string username, string password, int id){
Debug.Log ("logindata equip log");
if (this.username.Equals (username) && password.Equals (password) && this.id == id) {
Debug.Log ("C# >>> LoginData = {username = " + this.username + ", password =" + this.password + ", id = " + this.id + " check ok!!!");
} else {
Debug.Log ("C# >>> LoginData = {username = " + this.username + ", password =" + this.password + ", id = " + this.id + " check error!!!");