协同程序(coroutine)
来源:互联网 发布:如何加入淘宝网 编辑:程序博客网 时间:2024/05/09 04:15
什么是协同程序?
协同程序,即在主程序运行时同时开启另一段逻辑处理,来协同当前程序的执行。换句话说,开启协同程序就是开启一个线程。
1. Coroutines顾名思议是用来协助主要进程的,在Unity中感觉就是一个可动态添加和移除的Update()函数。它的调用在所有Update函数之后。
2. yield就像是一个红绿灯,在满足紧跟在它后面的条件之前,这个协程会挂起,把执行权交给调用它的父函数,满足条件时就可以执行yield下面的代码。
总结起来就是一句话:控制代码在特定的时机执行。
yield 后面可以有的表达式:
a) null - the coroutine executes the next time that it is eligible
b) WaitForEndOfFrame - the coroutine executes on the frame, after all of the rendering and GUI is complete
c) WaitForFixedUpdate - causes this coroutine to execute at the next physics step, after all physics is calculated
d) WaitForSeconds - causes the coroutine not to execute for a given game time period
e) WWW - waits for a web request to complete (resumes as if WaitForSeconds or null)
f) Another coroutine - in which case the new coroutine will run to completion before the yielder is resumed
值得注意的是 WaitForSeconds()受Time.timeScale影响,当Time.timeScale = 0f 时,yield return new WaitForSecond(x) 将不会满足。
协同程序,即在主程序运行时同时开启另一段逻辑处理,来协同当前程序的执行。换句话说,开启协同程序就是开启一个线程。
1. Coroutines顾名思议是用来协助主要进程的,在Unity中感觉就是一个可动态添加和移除的Update()函数。它的调用在所有Update函数之后。
2. yield就像是一个红绿灯,在满足紧跟在它后面的条件之前,这个协程会挂起,把执行权交给调用它的父函数,满足条件时就可以执行yield下面的代码。
总结起来就是一句话:控制代码在特定的时机执行。
yield 后面可以有的表达式:
a) null - the coroutine executes the next time that it is eligible
b) WaitForEndOfFrame - the coroutine executes on the frame, after all of the rendering and GUI is complete
c) WaitForFixedUpdate - causes this coroutine to execute at the next physics step, after all physics is calculated
d) WaitForSeconds - causes the coroutine not to execute for a given game time period
e) WWW - waits for a web request to complete (resumes as if WaitForSeconds or null)
f) Another coroutine - in which case the new coroutine will run to completion before the yielder is resumed
值得注意的是 WaitForSeconds()受Time.timeScale影响,当Time.timeScale = 0f 时,yield return new WaitForSecond(x) 将不会满足。
0 0
- 协同程序(coroutine)
- Unity3D--协同程序(Coroutine)
- Unity3D协同程序(Coroutine)
- Unity3D协同程序(Coroutine)
- Unity3D协同程序(Coroutine)
- Unity3D协同程序(Coroutine)
- Unity3D协同程序(Coroutine)
- Unity3D协同程序(Coroutine)
- Unity3D--协同程序(Coroutine)
- Unity3D协同程序(Coroutine)
- Lua 协同程序(coroutine)
- Unity3D协同程序(Coroutine)
- Lua 协同程序(coroutine)
- unity3d的协同程序(Coroutine)思考
- Lua协同程序coroutine
- Unity Coroutine协同程序
- 协同程序Coroutine
- Lua 协同程序(coroutine)
- Ajax 完整教程1
- Longest Substring Without Repeating Characters
- java中遍历属性字段及值
- 机器学习算法
- PHP生成条形码
- 协同程序(coroutine)
- 新的环境新的学期新的开始
- 创建可复用单链表
- SQL Server备份、完整备份,差异备份、日志备份
- 黑马北京新闻项目连载(4)--->ViewPagerIndicator结合FragmentPagerAdapter(开源库的Git上的demo)
- 家谱 解题报告
- UI_无限滚动相册
- Xcode 7 App Transport Security has blocked a cleartext HTTP 报错解决办法
- Linux下Eclipse里用gdb调试JNI里C/C++