lua 懒注入

使用场景:要修的脚本在很多地方使用,但要修复的内容只在某个特定的地方被调用,这个时候直接修这个脚本会造成很多不必要的消耗。

解决方案:

local FixFun= function(self)     local txt1 = self.transform:Find("HaveDropGun/Image/UI_Text"):GetComponent(typeof(CS.ExText));     print(1111) end local Awake= function(self)     self:Awake();     xlua.hotfix(CS.Script_2,'Awake',FixFun) end local _OnDestroy = function(self)     xlua.hotfix(CS.Script_2,'Awake',nil)     self:OnDestroy(); end util.hotfix_ex(CS.Script_1,'InitUIElements',_InitUIElements) util.hotfix_ex(CS.Script_1,'OnDestroy',_OnDestroy)   FixFun : Script_2 要修的函数 Script_2 : 要修的类 Script_1:要使用FixFun的地方 大概意思就是在用的场景的awake注入,场景销毁就去掉。

相关文章

1.github代码实践源代码是lua脚本语言,下载th之后运行thmai...
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/...
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能...
localfunctiongenerate_action(params)localscale_action=cc...
2022年1月11日13:57:45 官方:https://opm.openresty.org/官...
在Lua中的table(表),就像c#中的HashMap(哈希表),key和...