当前位置:网站首页>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)
边栏推荐
- Kernel synchronization mechanism
- 自定义 grpc 插件
- Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
- 流动性质押挖矿系统开发如何制作,dapp丨defi丨nft丨lp流动性质押挖矿系统开发案例分析及源码
- MQ-防止消息丢失及重复消费
- Y48. Chapter III kubernetes from introduction to mastery -- pod status and probe (21)
- Is it safe for Huatai Securities to open an account online?
- Impressive bug summary (continuously updated)
- 邻接矩阵无向图(一) - 基本概念与C语言
- 深入理解 grpc part1
猜你喜欢
Exploration and practice of inress in kubernetes
Comment Cao définit la décimale de dimension
ABBIRB120工业机器人机械零点位置
Abbirb120 industrial robot mechanical zero position
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
C knowledge point form summary 2
Software project management 9.2 Software project configuration management process
Seckill system 03 - redis cache and distributed lock
CAD如何設置標注小數比特
Prepare for the Blue Bridge Cup Day10__ PWM control light brightness
随机推荐
241. Design priority for operational expressions: DFS application questions
C summary of knowledge points 3
ACLY与代谢性疾病
Can I open a securities account anywhere? Is it safe to open an account
Xiaomi mobile phone unlocking BL tutorial
Question: what professional qualities should test engineers have?
About keil compiler, "file has been changed outside the editor, reload?" Solutions for
自组织是管理者和成员的双向奔赴
微信小程序开发 – 用户授权登陆「建议收藏」
自定義 grpc 插件
Theoretical basis of graph
Exploration and practice of inress in kubernetes
Use set_ Handler filters out specific SystemC wrapping & error messages
Deep understanding of grpc part1
sshd_ Discussion on permitrotlogin in config
Raspberry pie 4B installation tensorflow2.0[easy to understand]
Redis启动与库进入
S7-1500PLC仿真
伸展树(一) - 概念和C实现
On recursion and Fibonacci sequence