当前位置:网站首页>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)
边栏推荐
猜你喜欢

【单片机】【数码管】数码管显示

Comment Cao définit la décimale de dimension

MQ-防止消息丢失及重复消费

Summary of JFrame knowledge points 1
![[MCU] [nixie tube] nixie tube display](/img/5e/9e14302b4e4f5e03601392ac90479d.png)
[MCU] [nixie tube] nixie tube display

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

陈珙:微服务,它还那么纯粹吗?

Chen Gong: Micro service, is it still so pure?

On recursion and Fibonacci sequence

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%
随机推荐
Compile and debug net6 source code
Neo4j 中文开发者月刊 - 202206期
Understanding of MVVM and MVC
华为HMS Core携手超图为三维GIS注入新动能
Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
Kernel synchronization mechanism
redis中value/SortedSet
Can solo be accessed through IPv6?
241. Design priority for operational expressions: DFS application questions
sshd_ Discussion on permitrotlogin in config
如何看懂开发的查询语句
JS date format conversion method
Istio, ebpf and rsocket Broker: in depth study of service grid
uniapp 使用 uni-upgrade-center
Mechanism and type of CPU context switch
流动性质押挖矿系统开发如何制作,dapp丨defi丨nft丨lp流动性质押挖矿系统开发案例分析及源码
2022/6/30学习总结
Deep understanding of grpc part1
小米手机解BL锁教程
On recursion and Fibonacci sequence