当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢
7.2 daily study 4
comsol--三维图形随便画----回转
CDGA|数据治理不得不坚持的六个原则
Stop saying that microservices can solve all problems!
In the last process before the use of the risk control model, 80% of children's shoes are trampled here
分类TAB商品流多目标排序模型的演进
紫光展锐全球首个5G R17 IoT NTN卫星物联网上星实测完成
Go language learning notes - analyze the first program
Wechat nucleic acid detection appointment applet system graduation design completion (8) graduation design thesis template
Bidirectional RNN and stacked bidirectional RNN
随机推荐
Deepfake tutorial
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
【爬虫】wasm遇到的bug
[first release in the whole network] (tips for big tables) sometimes it takes only 1 minute for 2 hours of SQL operation
Beego cross domain problem solution - successful trial
[Oracle] use DataGrid to connect to Oracle Database
Wechat nucleic acid detection appointment applet system graduation design completion (6) opening defense ppt
About the use of Vray 5.2 (self research notes)
[advertising system] incremental training & feature access / feature elimination
How to understand super browser? What scenarios can it be used in? What brands are there?
2022 Pengcheng cup Web
Solve the problem of slow access to foreign public static resources
Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in
Data types ntext and varchar are incompatible in the not equal to operator - 95 small pang
spark调优(一):从hql转向代码
The ninth Operation Committee meeting of dragon lizard community was successfully held
DDRx寻址原理
[SWT component] content scrolledcomposite
Bidirectional RNN and stacked bidirectional RNN
【Oracle】使用DataGrip连接Oracle数据库