当前位置:网站首页>Unity Xlua MonoProxy Mono代理类
Unity Xlua MonoProxy Mono代理类
2022-07-05 11:24:00 【帅_shuai_】
Unity Xlua Mono代理类(MonoProxy)
- Xlua用于映射Unity的声明周期函数
- 使用UniRx 可以实现 update的多次绑定,可以在需要时绑定Update来提升性能
public class MonoProxy : MonoBehaviour
{
public LuaTable luaTable;
private Action<LuaTable> luaStart;
private Action<LuaTable> luaOnDestroy;
public LuaTable BindScript(string moduleName, string scriptPath)
{
Main.Instance.LuaEnv.DoString($"require('{
scriptPath}')");
string[] arr = scriptPath.Split('/');
luaTable = Main.Instance.LuaEnv.Global.Get<LuaTable>(arr[arr.Length - 1]);
luaTable.Set("MonoProxy", this);
Action<LuaTable> luaAwake = luaTable.Get<Action<LuaTable>>("Awake");
luaAwake?.Invoke(luaTable);
luaTable.Get("Start", out luaStart);
luaTable.Get("OnDestroy", out luaOnDestroy);
return luaTable;
}
public void BindUpdate(Action action)
{
Observable.EveryUpdate().Subscribe(_ =>
{
action?.Invoke();
}).AddTo(this);
}
private void Start()
{
luaStart?.Invoke(luaTable);
}
private void OnDestroy()
{
luaOnDestroy?.Invoke(luaTable);
}
}
边栏推荐
- Pytorch training process was interrupted
- What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
- How to understand super browser? What scenarios can it be used in? What brands are there?
- MFC pet store information management system
- 基础篇——REST风格开发
- 力扣(LeetCode)185. 部门工资前三高的所有员工(2022.07.04)
- About the use of Vray 5.2 (self research notes)
- 分类TAB商品流多目标排序模型的演进
- AUTOCAD——遮罩命令、如何使用CAD对图纸进行局部放大
- Basic part - basic project analysis
猜你喜欢
购买小间距LED显示屏的三个建议
How did the situation that NFT trading market mainly uses eth standard for trading come into being?
【广告系统】Parameter Server分布式训练
How to close the log window in vray5.2
技术管理进阶——什么是管理者之体力、脑力、心力
2022 mobile crane driver examination question bank and simulation examination
CDGA|数据治理不得不坚持的六个原则
Wechat nucleic acid detection appointment applet system graduation design completion (7) Interim inspection report
Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022
Operation of simulated examination platform of special operation certificate examination question bank for safety production management personnel of hazardous chemical production units in 2022
随机推荐
Modulenotfounderror: no module named 'scratch' ultimate solution
如何通俗理解超级浏览器?可以用于哪些场景?有哪些品牌?
Repair animation 1K to 8K
Intelligent metal detector based on openharmony
【全网首发】(大表小技巧)有时候 2 小时的 SQL 操作,可能只要 1 分钟
spark调优(一):从hql转向代码
How to close the log window in vray5.2
我用开天平台做了一个城市防疫政策查询系统【开天aPaaS大作战】
Cron表达式(七子表达式)
Four departments: from now on to the end of October, carry out the "100 day action" on gas safety
Lombok 同时使⽤@Data和@Builder 的坑,你中招没?
DDR4硬件原理图设计详解
Manage multiple instagram accounts and share anti Association tips
[LeetCode] Wildcard Matching 外卡匹配
The ninth Operation Committee meeting of dragon lizard community was successfully held
技术管理进阶——什么是管理者之体力、脑力、心力
MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
PHP中Array的hash函数实现
【爬虫】charles unknown错误
【广告系统】Parameter Server分布式训练