当前位置:网站首页>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);
}
}
边栏推荐
- 项目总结笔记系列 wsTax KT Session2 代码分析
- Cron表达式(七子表达式)
- 分类TAB商品流多目标排序模型的演进
- [LeetCode] Wildcard Matching 外卡匹配
- PHP中Array的hash函数实现
- Web API配置自定义路由
- 7 大主题、9 位技术大咖!龙蜥大讲堂7月硬核直播预告抢先看,明天见
- AutoCAD -- mask command, how to use CAD to locally enlarge drawings
- Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
- go语言学习笔记-初识Go语言
猜你喜欢

Evolution of multi-objective sorting model for classified tab commodity flow

7.2 daily study 4

2022 t elevator repair operation certificate examination questions and answers

【Office】Excel中IF函数的8种用法

AUTOCAD——遮罩命令、如何使用CAD对图纸进行局部放大

Harbor image warehouse construction
![[office] eight usages of if function in Excel](/img/ce/ea481ab947b25937a28ab5540ce323.png)
[office] eight usages of if function in Excel

Ddrx addressing principle
![[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output](/img/96/b8585205b3faf503686c5bbdcecc53.png)
[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output

【广告系统】增量训练 & 特征准入/特征淘汰
随机推荐
使用GBase 8c数据库过程中报错:80000305,Host ips belong to different cluster ,怎么解决?
Beego cross domain problem solution - successful trial
[first release in the whole network] (tips for big tables) sometimes it takes only 1 minute for 2 hours of SQL operation
The art of communication III: Listening between people
[Oracle] use DataGrid to connect to Oracle Database
COMSOL--建立几何模型---二维图形的建立
技术管理进阶——什么是管理者之体力、脑力、心力
力扣(LeetCode)185. 部门工资前三高的所有员工(2022.07.04)
Detailed explanation of DDR4 hardware schematic design
Dspic33ep clock initialization program
分类TAB商品流多目标排序模型的演进
7.2 daily study 4
解决访问国外公共静态资源速度慢的问题
Summary of websites of app stores / APP markets
Ziguang zhanrui's first 5g R17 IOT NTN satellite in the world has been measured on the Internet of things
DDoS attack principle, the phenomenon of being attacked by DDoS
MySQL 巨坑:update 更新慎用影响行数做判断!!!
Deepfake tutorial
基础篇——REST风格开发
[there may be no default font]warning: imagettfbbox() [function.imagettfbbox]: invalid font filename