在xlua中使用DoTween动画插件
在使用xlua编程热更新项目时,如果需要使用DoTween动画插件该如何去设置呢?今天就遇到了这个问题,将解决方案记录在这里:
DoTween通过添加拓展方法的方式为Unity本身的类或对象添加了许多方法,这些方法使用DO、Set、On等开头,不同开头的方法都有特定的作用。xlua要识别DoTween,需要在相应的拓展类上添加[LuaCallCSharp]特性并生成代码,但是对于系统或插件的API,一般不能修改或不方便修改源码(如导出为dll格式使用的插件就不能修改源码),因此需要使用xlua提供的方法为这些API生成代码。
参考文件:1)xLua中导出DoTween;2)热更新解决方案--xlua学习笔记 五.lua调用C# 9.特殊问题
代码:1)自定义静态类,包含静态的list属性,在list中添加要生成代码的类型
/// <summary> /// 在Xlua中使用DoTween /// </summary> public static class DoTweenCallXLua { [LuaCallCSharp] [ReflectionUse] public static List<Type> luaCallCsharpList = new List<Type>(){ typeof(DG.Tweening.AutoPlay), typeof(DG.Tweening.AxisConstraint), typeof(DG.Tweening.Ease), typeof(DG.Tweening.LogBehaviour), typeof(DG.Tweening.LoopType), typeof(DG.Tweening.PathMode), typeof(DG.Tweening.PathType), typeof(DG.Tweening.RotateMode), typeof(DG.Tweening.ScrambleMode), typeof(DG.Tweening.TweenType), typeof(DG.Tweening.UpdateType), typeof(DG.Tweening.DOTween), typeof(DG.Tweening.DOVirtual), typeof(DG.Tweening.EaseFactory), typeof(DG.Tweening.Tweener), typeof(DG.Tweening.Tween), typeof(DG.Tweening.Sequence), typeof(DG.Tweening.TweenParams), typeof(DG.Tweening.Core.ABSSequentiable), typeof(DG.Tweening.Core.TweenerCore<Vector3, Vector3, DG.Tweening.Plugins.Options.VectorOptions>), typeof(DG.Tweening.TweenCallback), typeof(DG.Tweening.TweenExtensions), typeof(DG.Tweening.TweenSettingsExtensions), typeof(DG.Tweening.ShortcutExtensions), typeof(DG.Tweening.ShortcutExtensions43), typeof(DG.Tweening.ShortcutExtensions46), typeof(DG.Tweening.ShortcutExtensions50), }; }
2)在Unity中生成代码
3)在xlua中调用相关方法即可
注意事项:在调用过程中发现了一个以前都没有注意到的问题,就是DoTween的DO系列方法DO都是大写的,如果方法名称不正确无法调用
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!