当前位置:网站首页>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);
}
}
边栏推荐
- Summary of thread and thread synchronization under window
- Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
- DDoS attack principle, the phenomenon of being attacked by DDoS
- sklearn模型整理
- Ziguang zhanrui's first 5g R17 IOT NTN satellite in the world has been measured on the Internet of things
- Lombok 同时使⽤@Data和@Builder 的坑,你中招没?
- CDGA|数据治理不得不坚持的六个原则
- Redis如何实现多可用区?
- Intelligent metal detector based on openharmony
- 如何将 DevSecOps 引入企业?
猜你喜欢
How did the situation that NFT trading market mainly uses eth standard for trading come into being?
不要再说微服务可以解决一切问题了!
数据库三大范式
COMSOL--建立几何模型---二维图形的建立
About the use of Vray 5.2 (self research notes)
9、 Disk management
[office] eight usages of if function in Excel
pytorch训练进程被中断了
技术管理进阶——什么是管理者之体力、脑力、心力
【Oracle】使用DataGrip连接Oracle数据库
随机推荐
About the use of Vray 5.2 (self research notes) (II)
Leetcode 185 All employees with the top three highest wages in the Department (July 4, 2022)
Summary of thread and thread synchronization under window
msfconsole命令大全,以及使用说明
解决readObjectStart: expect { or n, but found N, error found in #1 byte of ...||..., bigger context ..
idea设置打开文件窗口个数
NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
Three suggestions for purchasing small spacing LED display
MFC pet store information management system
数据库三大范式
【全网首发】(大表小技巧)有时候 2 小时的 SQL 操作,可能只要 1 分钟
C#实现WinForm DataGridView控件支持叠加数据绑定
使用GBase 8c数据库过程中报错:80000305,Host ips belong to different cluster ,怎么解决?
【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
uboot的启动流程:
POJ 3176-Cow Bowling(DP||记忆化搜索)
-26374 and -26377 errors during coneroller execution
CDGA|数据治理不得不坚持的六个原则
I used Kaitian platform to build an urban epidemic prevention policy inquiry system [Kaitian apaas battle]
边缘计算如何与物联网结合在一起?