惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
L
LangChain Blog
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
月光博客
月光博客
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
量子位
AWS News Blog
AWS News Blog
Jina AI
Jina AI
Webroot Blog
Webroot Blog
L
Lohrmann on Cybersecurity
Cisco Talos Blog
Cisco Talos Blog
Latest news
Latest news
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
NISL@THU
NISL@THU
The Register - Security
The Register - Security
美团技术团队
博客园 - 三生石上(FineUI控件)
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
Netflix TechBlog - Medium
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Exploit Database - CXSecurity.com
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
S
Securelist
Know Your Adversary
Know Your Adversary
MyScale Blog
MyScale Blog
C
CERT Recently Published Vulnerability Notes
D
Darknet – Hacking Tools, Hacker News & Cyber Security
U
Unit 42
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
雷峰网
雷峰网
B
Blog
P
Privacy International News Feed
W
WeLiveSecurity
T
Threatpost
P
Palo Alto Networks Blog
O
OpenAI News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
K
Kaspersky official blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
B
Blog RSS Feed

博客园 - 鱼丸粗面

《Unity預計算即時GI》笔记:三、Clusters和总结 《Unity預計算即時GI》笔记:二、光照图 - 鱼丸粗面 - 博客园 《Unity預計算即時GI》笔记:一、基本概念与一些设置 - 鱼丸粗面 - 博客园 我所了解的法线贴图 - 鱼丸粗面 - 博客园 游戏设计模式读书笔记:命令模式 - 鱼丸粗面 - 博客园 游戏设计模式读书笔记:架构、性能、游戏 一个美术需求引发的Custom Inspector 代码生成AnimatorController unity生成的WP8.1工程的Title本地化实现 unity生成WP工程后ExtendedSplashImage显示不正确的问题 Unity5.x在WP8.1中无法使用Reflection API的解决方法 使用uGUI制作游戏内2D动画 Unity3D Editor模式下批量修改prefab 3D touch在Unity3D中的使用 Unity3D脚本调用Objective C代码实现游戏内购买 WindowsPhone8拍照功能实现简介 WindowsPhone App如何扩展能够使用的内存 prism关键概念: objective-c:继承
Unity中的协程是什么?
鱼丸粗面 · 2015-07-30 · via 博客园 - 鱼丸粗面

什么是协程?

1、协程是一个分部执行,遇到条件(yield return 语句)会挂起,直到条件满足才会被唤醒继续执行后面的代码。

2、Unity在每一帧(Frame)都会去处理对象上的协程。Unity主要是在Update后去处理协程(检查协程的条件是否满足),但也有写特例。

什么情况是条件满足?

在协程方法中使用 yield return 其实就是为了返回 IEnumerator对象,只有当这个对象的 MoveNext() 返回 false 时,即该 IEnumertator 的 Current 已经迭代到最后一个元素了,才会执行 yield return 后面的语句。也就是说, yield return 被会“翻译”为一个 IEnmerator 对象。

var request = new WWW();
yield return request;

为例应该有以下内容才对:

int state;

bool MoveNext()

{

     if(state == 0)

   {

        var request = new WWW();

        state = 1;

     }

     return request.isDone ? false : true;

}

当请求完成后,MoveNext返回false,认为IEnumerator已经迭代完成,此时开始执行后续代码。

感谢这样的好文章:http://dsqiu.iteye.com/blog/2029701