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開發人員可能並不會採用。