在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Tencent/sluaunreal开源软件地址(OpenSource Url):https://github.com/Tencent/sluaunreal开源编程语言(OpenSource Language):C++ 83.9%开源软件介绍(OpenSource Introduction):What's slua-unreal?slua-unreal is unreal4 plugin, you can use lua language to develop game logic and hot fix your lua code via this plugin, slua-unreal give you 3 way to wrap your c++ interface for lua, including reflection(by blueprint), c++ template and static code generation by a tool, meanwhile you can communicate with blueprint, call lua from blueprint, vice versa. slua-unreal 是什么slua-unreal作为unreal引擎的插件,通过unreal自带蓝图接口的反射能力,结合libclang静态c++代码分析,自动化导出蓝图接口和静态c++接口,提供给lua语言,使得可以通过lua语言开发unreal游戏业务逻辑,方便游戏高效迭代开发,上线热更新,同时支持lua到c++双向,lua到蓝图双向调用,使用lua语言完美替代unreal的c++开发方式,修改业务逻辑不需要等待c++编译,大大提升开发速度。 目前该项目作为腾讯PUBG手游和潘多拉系统,该系统用于腾讯UE4游戏业务,帮助游戏业务构建周边系统、运营系统,上线质量稳定。 欢迎issue,pr,star,fork。 ShowcasesWhat's new?Release 1.3.3, fix a crash bug, more stable Release 1.3.2, fix building error on UE 4.24 Add a branch to support UE 4.25 or later Feature
slua-unreal 有什么功能
调试器支持Debugger Support我们开发了专门的vs code调试插件,支持真机调试,断点,查看变量值,代码智能提示等功能。调试器自动识别可以使用的UE UFunction蓝图函数和CppBinding导出的接口函数,不需要额外导出静态数据。 We developed a tool integrated with VsCode to support debug in device, breakpoint, watch variant and code intellisence. Debugger will auto generate intellisense data for UE UFunction and exported cpp function with CppBinding. 使用方法简单范例Usage at glance-- import blueprint class to use
local Button = import('Button');
local ButtonStyle = import('ButtonStyle');
local TextBlock = import('TextBlock');
local SluaTestCase=import('SluaTestCase');
-- call static function of uclass
SluaTestCase.StaticFunc()
-- create Button
local btn=Button();
local txt=TextBlock();
-- load panel of blueprint
local ui=slua.loadUI('/Game/Panel.Panel');
-- add to show
ui:AddToViewport(0);
-- find sub widget from the panel
local btn2=ui:FindWidget('Button1');
local index = 1
-- handle click event
btn2.OnClicked:Add(function()
index=index+1
print('say helloworld',index)
end);
-- handle text changed event
local edit=ui:FindWidget('TextBox_0');
local evt=edit.OnTextChanged:Add(function(txt) print('text changed',txt) end);
-- use FVector
local p = actor:K2_GetActorLocation()
local h = HitResult()
local v = FVector(math.sin(tt)*100,2,3)
local offset = FVector(0,math.cos(tt)*50,0)
-- support Operator
local ok,h=actor:K2_SetActorLocation(v+offset,true,h,true)
-- get referenced value
print("hit info",h) 在蓝图中调用luaBlueprint call lua
Output is: Slua: call from bp 1024 Hello World 3.1400001049042 UObject: 0x136486168 使用lua扩展ActorUsing lua extend Actor-- LuaActor.lua
local actor={}
-- override event from blueprint
function actor:BeginPlay()
self.bCanEverTick = true
print("actor:BeginPlay")
end
function actor:Tick(dt)
print("actor:Tick",self,dt)
-- call actor function
local pos = self:K2_GetActorLocation()
-- can pass self as Actor*
local dist = self:GetHorizontalDistanceTo(self)
print("actor pos",pos,dist)
end
return actor 性能slua-unreal提供3中技术绑定lua接口,包括: 1)蓝图反射方法 2)静态代码生成 3)CppBinding(模板展开) 其中方法2和3运行原理上没差别,只是方法2是基于libclang自动化生成代码,方法3是手写代码,所以下面的统计上仅针对1和3来对比,可以认为2和3的性能是等价的。 100万次函数调用时间统计(秒),测试用例可以参考附带的TestPerf.lua文件。 测试机器 MacOSX,Unreal 4.18 dev版(非release,release应该会稍微快一点),CPU i7 4GHz。 Performanceunit in second, 1,000,000 call to c++ interface from lua, compared reflection and cppbinding, (both reflection and cppbinding support by slua-unreal). Test machine, MacOSX, Unreal 4.18 develop building, CPU i7 4GHz, test case can find in TestPerf.lua
与slua unity版本相比,因为unreal的蓝图反射更高效,没有gc alloc开销,基于蓝图反射的方法的性能比slua unity的静态代码生成还要快1倍,而cppbinding则快一个数量级。 相关参考slua-unreal依赖dot-clang做c++静态代码生成的工具稍后开源,目前常用FVector等常用类的静态生成代码已经附带。 QQ技术支持群:15647305,需要提交具体问题issue后申请入群,谢绝hr和非技术人员进入。 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论