当前位置:网站首页>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)
边栏推荐
- 微信小程序开发 – 用户授权登陆「建议收藏」
- openinstall:微信小程序跳转H5配置业务域名教程
- Istio, ebpf and rsocket Broker: in depth study of service grid
- 指纹浏览器工作原理、使用场景以及重要性简单讲解
- Value/set in redis
- Question: what professional qualities should test engineers have?
- solo 可以通过 IPV6 访问吗?
- Botu V15 add GSD file
- Building external modules
- [Maui] add click events for label, image and other controls
猜你喜欢

S7-1500PLC仿真

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

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

Rural guys earn from more than 2000 a month to hundreds of thousands a year. Most brick movers can walk my way ǃ

Neo4j Chinese developer monthly - issue 202206

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS

2022/6/29学习总结

Redis' attack tactics
![[classic example] classic list questions @ list](/img/d8/a259e5f9d08eacbef31254d1bc3304.jpg)
[classic example] classic list questions @ list

基于IMDB评论数据集的情感分析
随机推荐
Ultra detailed black apple installation graphic tutorial sent to EFI configuration collection and system
小米手机解BL锁教程
Value/sortedset in redis
Interpretation of R & D effectiveness measurement framework
想问问,证券开户有优惠吗手机开户是安全么?
Goldfish rhca memoirs: do447 uses ansible to communicate with API -- using ansible tower API to start jobs
solo 可以通过 IPV6 访问吗?
Implementation of address book management system with C language
C#依赖注入(直白明了)讲解 一看就会系列
Introduction to unittest framework and the first demo
Is it safe for Huatai Securities to open an account online?
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Width and widthstep of iplimage
陈珙:微服务,它还那么纯粹吗?
C summary of knowledge points 1
自组织是管理者和成员的双向奔赴
深入理解 grpc part1
Understanding of MVVM and MVC
Value/set in redis
Learning summary on June 30, 2022