在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):topameng/tolua开源软件地址(OpenSource Url):https://github.com/topameng/tolua开源编程语言(OpenSource Language):C# 60.9%开源软件介绍(OpenSource Introduction):tolua#tolua# is a Unity lua static binder solution. the first solution that analyzes code by reflection and generates wrapper classes. 欢迎大家点星支持,谢谢^_^ Librarytolua_runtime FrameWork and DemoLuaFrameWork DebuggerEmmyLua Packages Basics Math Data Structures 特性
快速入门在CustomSetting.cs中添加需要导出的类或者委托,类加入到customTypeList列表,委托加入到customDelegateList列表 //例子1
LuaState lua = new LuaState();
lua.Start();
lua.DoString("print('hello world')");
lua.Dispose();
//例子2
LuaState luaState = null;
void Awake()
{
luaState = LuaClient.GetMainState();
try
{
luaState.Call("UIShop.Awake", false);
}
catch (Exception e)
{
//Awake中必须这样特殊处理异常
luaState.ThrowLuaException(e);
}
}
void Start()
{
luaState.Call("UIShop.Start", false);
} local go = GameObject('go')
go:AddComponent(typeof(UnityEngine.ParticleSystem))
go.transform.position = Vector3.zero
go.transform:Rotate(Vector3(0,90,0), UnityEngine.Space.World)
go.transform:Rotate(Vector3(0, 1, 0), 0)
--DoTween 需要在CustomSetting导出前定义USING_DOTWEENING宏,或者取消相关注释
go.transform:DORotate(Vector3(0,0,360), 2, DG.Tweening.RotateMode.FastBeyond360)
Shop = {}
function Shop:Awake()
self.OnUpdate = UpdateBeat:CreateListener(Shop.Update, self)
UpdateBeat:AddListener(self.OnUpdate)
end
function Shop:OnDestroy()
UpdateBeat:RemoveListener(self.OnUpdate)
end
function Shop:OnClick()
print("OnClick")
end
function Shop:OnToggle()
print("OnToggle")
end
function Shop:Update()
end
--委托
local listener = UIEventListener.Get(go)
listener.onClick = function() print("OnClick") end
listener.onClick = nil
listener.onClick = UIEventListener.VoidDelegate(Shop.OnClick, Shop)
listener.onClick = listener.onClick + UIEventListener.VoidDelegate(Shop.OnClick, Shop)
listener.onClick = listener.onClick - UIEventListener.VoidDelegate(Shop.OnClick, Shop)
local toggle = go:GetComponent(typeof(UIToggle))
EventDelegate.Add(toggle.onChange, EventDelegate.Callback(Shop.OnToggle, Shop))
EventDelegate.Remove(toggle.onChange, EventDelegate.Callback(Shop.OnToggle, Shop))
--事件
local Client = {}
function Client:Log(str)
end
Application.logMessageReceived = Application.logMessageReceived + Application.LogCallback(Clent.Log, Client)
Application.logMessageReceived = Application.logMessageReceived - Application.LogCallback(Clent.Log, Client)
--out参数
local _layer = 2 ^ LayerMask.NameToLayer('Default')
local flag, hit = UnityEngine.Physics.Raycast(ray, nil, 5000, _layer)
if flag then
print('pick from lua, point: '..tostring(hit.point))
end 这里是更多的示例。 关于反射tolua# 不支持动态反射。动态反射对于重载函数有参数匹配问题,函数排序问题,ref,out 参数问题等等。
Performance
测试结果为C#:Lua. 环境不同会略有差异。可用数字倍率做参考 Examples参考包内1-24例子 About Luawin, android ios using luajit2.1-beta3. macos using luac5.1.5(for u5.x). 注意iOS未编译模拟器库,请用真机测试 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论