当前位置:网站首页>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);
}
}
边栏推荐
- SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
- 【爬虫】wasm遇到的bug
- About the use of Vray 5.2 (self research notes) (II)
- 如何通俗理解超级浏览器?可以用于哪些场景?有哪些品牌?
- Home office things community essay
- COMSOL--三维随便画--扫掠
- Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template
- 9、 Disk management
- [first release in the whole network] (tips for big tables) sometimes it takes only 1 minute for 2 hours of SQL operation
- 2022 mobile crane driver examination question bank and simulation examination
猜你喜欢

无密码身份验证如何保障用户隐私安全?

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

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

如何让全彩LED显示屏更加节能环保

【爬虫】wasm遇到的bug

Basic testing process of CSDN Software Testing Introduction

Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022

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

DDRx寻址原理

CDGA|数据治理不得不坚持的六个原则
随机推荐
Msfconsole command encyclopedia and instructions
POJ 3176-Cow Bowling(DP||记忆化搜索)
Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template
四部门:从即日起至10月底开展燃气安全“百日行动”
Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022
Cron表达式(七子表达式)
C # to obtain the filtered or sorted data of the GridView table in devaexpress
FFmpeg调用avformat_open_input时返回错误 -22(Invalid argument)
基于OpenHarmony的智能金属探测器
Basic part - basic project analysis
Risc-v-qemu-virt in FreeRTOS_ Scheduling opportunity of GCC
NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
How to make full-color LED display more energy-saving and environmental protection
[first release in the whole network] (tips for big tables) sometimes it takes only 1 minute for 2 hours of SQL operation
How to introduce devsecops into enterprises?
Summary of thread and thread synchronization under window
[Oracle] use DataGrid to connect to Oracle Database
TSQL – identity column, guid, sequence
c#操作xml文件
2022 Pengcheng cup Web