当前位置:网站首页>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)
边栏推荐
- The Missing Semester
- Value/hush in redis
- 强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
- Software project management 9.2 Software project configuration management process
- TMUX usage
- Theoretical basis of graph
- Ultra detailed black apple installation graphic tutorial sent to EFI configuration collection and system
- 自定义 grpc 插件
- C summary of knowledge points 1
- Botu V15 add GSD file
猜你喜欢

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

2022/6/29学习总结

Computer graduation project asp Net attendance management system vs developing SQLSERVER database web structure c programming computer web page source code project

二叉堆(一) - 原理与C实现

MQ prevent message loss and repeated consumption

基于IMDB评论数据集的情感分析

Mechanism and type of CPU context switch

Redis' attack tactics

About keil compiler, "file has been changed outside the editor, reload?" Solutions for

Redis configuration environment variables
随机推荐
Value/string in redis
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Botu V15 add GSD file
uniapp 使用 uni-upgrade-center
基于IMDB评论数据集的情感分析
Introduction to unittest framework and the first demo
Redis' attack tactics
openinstall:微信小程序跳转H5配置业务域名教程
Is it safe for Huatai Securities to open an account online?
Comment Cao définit la décimale de dimension
Use set_ Handler filters out specific SystemC wrapping & error messages
微信小程序开发 – 用户授权登陆「建议收藏」
Activity workflow engine
How to set decimal places in CAD
Can solo be accessed through IPv6?
[buuctf.reverse] 144_ [xman2018 qualifying]easyvm
Explore the contour detection function findcontours() of OpenCV in detail with practical examples, and thoroughly understand the real role and meaning of each parameter and mode
Can I open a securities account anywhere? Is it safe to open an account
C#依赖注入(直白明了)讲解 一看就会系列
IPlImage的width和widthStep