当前位置:网站首页>Unity xlua co process packaging
Unity xlua co process packaging
2022-07-01 11:53:00 【Handsome_ shuai_】
Unity XLua Co process packaging
- Attachment Unity Medium MonoBehaviour Object to start the collaboration
- MonoBehaviour The object only needs to be an empty script , Mainly to start the process
- When used by the outside world, you only need to operate the collaboration object
1. encapsulation cs_coroutine
local util = require("xlua.util")
local obj = CS.UnityEngine.GameObject("Coroutine")
CS.UnityEngine.Object.DontDestroyOnLoad(obj)
[email protected] UnityEngine.MonoBehaviour
local mono = obj:AddComponent(typeof(CS.TestMono))
return{
start = function(...)
return mono:StartCoroutine(util.cs_generator(...))
end,
stop = function(co)
mono:StopCoroutine(co)
end,
stopAll = function()
mono:StopAllCoroutines()
end
}
2. Use cs_coroutine(1)
local cs_coroutine = require("Lesson23")
local co_a = cs_coroutine.start(function()
print("coroutine a started")
coroutine.yield(cs_coroutine.start(function()
print("coroutine b stated inside coroutine a")
coroutine.yield(CS.UnityEngine.WaitForSeconds(1))
print("i am coroutine b")
end))
print("coroutine b finish")
while true do
coroutine.yield(CS.UnityEngine.WaitForSeconds(1))
print("i am coroutine a")
end
end)
cs_coroutine.start(function()
print("stop coroutine a after 5 seconds")
coroutine.yield(CS.UnityEngine.WaitForSeconds(5))
cs_coroutine.stop(co_a)
print("coroutine a stop")
end)
3. Use cs_coroutine(2)
- Meet the conditions and stop the process
local cs_coroutine = require("Lesson23")
co = cs_coroutine.start(function()
local a = 0
while true do
print(a)
a = a + 1
if a >= 5 then
cs_coroutine.stop(co)
co = nil
for i, v in pairs(_G) do
print(i,v)
end
end
coroutine.yield(CS.UnityEngine.WaitForSeconds(0.2))
end
end)
边栏推荐
- 对于mvvm和mvc的理解
- CPU 上下文切换的机制和类型 (CPU Context Switch)
- 自定义 grpc 插件
- Why must we move from Devops to bizdevops?
- redis中value/set
- Brief explanation of the working principle, usage scenarios and importance of fingerprint browser
- Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
- Mingchuang plans to be listed on July 13: the highest issue price is HK $22.1, and the net profit in a single quarter decreases by 19%
- 耐克如何常年霸榜第一名?最新财报答案来了
- Custom grpc plug-in
猜你喜欢
![[MCU] [nixie tube] nixie tube display](/img/5e/9e14302b4e4f5e03601392ac90479d.png)
[MCU] [nixie tube] nixie tube display

Jd.com renewed its cooperation with Tencent: issuing class A shares to Tencent with a maximum value of US $220million

Skip the test cases to be executed in the unittest framework

Learning summary on June 28, 2022

Seckill system 03 - redis cache and distributed lock

强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐

Learning summary on June 29, 2022

华为HMS Core携手超图为三维GIS注入新动能

Redis' attack tactics

如何看懂开发的查询语句
随机推荐
邻接矩阵无向图(一) - 基本概念与C语言
CPI tutorial - asynchronous interface creation and use
[MCU] [nixie tube] nixie tube display
Wechat applet development - user authorization to log in to "suggestions collection"
Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
Question: what professional qualities should test engineers have?
sshd_config 中 PermitRootLogin 的探讨
About keil compiler, "file has been changed outside the editor, reload?" Solutions for
Kafuka learning path (I) Kafuka installation and simple use
微信小程序开发 – 用户授权登陆「建议收藏」
Why must we move from Devops to bizdevops?
NOV Schedule for . Net to display and organize appointments and recurring events
Mechanism and type of CPU context switch
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Building external modules
Custom grpc plug-in
CAD如何設置標注小數比特
redis常识
基于IMDB评论数据集的情感分析
Openinstall: wechat applet jump to H5 configuration service domain name tutorial