当前位置:网站首页>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);
}
}
边栏推荐
- MFC pet store information management system
- 边缘计算如何与物联网结合在一起?
- 购买小间距LED显示屏的三个建议
- MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
- Question and answer 45: application of performance probe monitoring principle node JS probe
- 解决grpc连接问题Dial成功状态为TransientFailure
- SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
- Zcmu--1390: queue problem (1)
- Redis如何实现多可用区?
- In the last process before the use of the risk control model, 80% of children's shoes are trampled here
猜你喜欢
不要再说微服务可以解决一切问题了!
Ziguang zhanrui's first 5g R17 IOT NTN satellite in the world has been measured on the Internet of things
NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
Question bank and answers of special operation certificate examination for main principals of hazardous chemical business units in 2022
【爬虫】wasm遇到的bug
[JS] extract the scores in the string, calculate the average score after summarizing, compare with each score, and output
Advanced technology management - what is the physical, mental and mental strength of managers
Go language learning notes - analyze the first program
Operation of simulated examination platform of special operation certificate examination question bank for safety production management personnel of hazardous chemical production units in 2022
随机推荐
Stop saying that microservices can solve all problems!
Ziguang zhanrui's first 5g R17 IOT NTN satellite in the world has been measured on the Internet of things
不要再说微服务可以解决一切问题了!
Home office things community essay
分类TAB商品流多目标排序模型的演进
Sklearn model sorting
ibatis的动态sql
无密码身份验证如何保障用户隐私安全?
About the use of Vray 5.2 (self research notes) (II)
Oneforall installation and use
[TCP] TCP connection status JSON output on the server
DDR4硬件原理图设计详解
shell脚本文件遍历 str转数组 字符串拼接
uboot的启动流程:
Golang application topic - channel
Three suggestions for purchasing small spacing LED display
基于Lucene3.5.0怎样从TokenStream获得Token
【爬虫】charles unknown错误
Summary of websites of app stores / APP markets
C # to obtain the filtered or sorted data of the GridView table in devaexpress