XLUA的上手比toLua要快,并且使用也比较简单直接,最大的亮点在于热补丁技术。git
1.关于热补丁技术github
思路相似JAVA的AOP思想,在不破坏影响原结构的同时,进行选择性热更新。目前腾讯已经将XLUA开源出来。 数组
官方此句:函数
“xLua热补丁技术支持在运行时把一个C#实现(函数,操做符,属性,事件,或者整个类)替换成Lua实现”oop
XLUA的热补丁为已经上线或者主体为C#代码的项目带来福音,能够事先在类前添加[HotFix],但注意此段官方给的:性能
这样的变动极有可能致使苹果审核不经过,其实一切热更都须要绕过苹果才能经过,但这样明显API变更会很易被苹果检查出来的。学习
热补丁官方文档以下:测试
https://github.com/Tencent/xLua/blob/master/Assets/XLua/Doc/hotfix.mdui
2.项目中的实践方案编码
任何阶段的项目均可以随时导入XLUA方案,只须要将xlua库中的Assets目录中的Plugins和XLua整合到项目就能够了。此时的咱们在这里只须要好好学习Doc文件夹下的文档就能够熟练使用了,这比toLua上手快多了。使用以前须要先创建一个本身的LuaGenConfig文件,能够直接将ExampleGenConfig复制出来,再本身添加编辑。好比添加一个DOTween组件:
/// <summary> /// dotween的扩展方法在lua中调用 /// </summary> [LuaCallCSharp] [ReflectionUse] public static List<Type> dotween_lua_call_cs_list = 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), //dotween pro 的功能 //typeof(DG.Tweening.DOTweenPath), //typeof(DG.Tweening.DOTweenVisualManager), };
Examples中的实例与toLua的例子基本操做方面相似,区别在于二者封装的类名,如虚拟机类LuaState与LuaEnv。
这里说说教程里的三种经常使用的XLUA使用方式。
1.CSharpCallLua。在LuaEnv对象执行完LUA代码后,对LUA中的:
Table类型
Function类型
2.LoadLuaScript
3.LuaCallSharp
若是须要第三方库,如JSON ,这时可参考文档中的说明官方提供的自动化脚本可打出对应不一样平台的xlua库。主要可能遇到的问题就是在路径的配置上,尽可能跟文档中的保持一致便可。
至此,大概的项目中的XLUA使用已经足够了。整体来讲比tolua配置更快速简单好用,但根据网上诸多大佬们的测试,性能各方面表现都不如tolua,好在其很牛X的热补丁方案,不过惋惜的是,IOS开发人员可能并不会采用。