博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
unity,下面两个协程不等价
阅读量:7136 次
发布时间:2019-06-28

本文共 409 字,大约阅读时间需要 1 分钟。

//代码1

IEnumerator A(){

  Debug.Log(“hi1”);
  {
    yield return new WaitForSeconds(1f);
    Debug.Log(“hi2”);
  }

  Debug.Log(“hi3”);

}

//代码2

IEnumerator A(){

  Debug.Log(“hi1”);
  yield return StartCoroutine (B());

  Debug.Log(“hi3”);

}

IEnumerator B(){

  yield return new WaitForSeconds(1f);
  Debug.Log(“hi2”);

}

代码1和代码2的打印顺序相同,都是hi1 hi2 hi3

但两者并不等价,体现在:

如果我调用StopCoroutine("A"),代码1会全部中止;而代码2只有A被停掉,B不会被停掉。

转载地址:http://ytvrl.baihongyu.com/

你可能感兴趣的文章
Eclipse中Spring插件的安装
查看>>
Unity3d导出安卓版本
查看>>
LAMP第四部分mysql操作
查看>>
Python之旅.第九章.并发编程
查看>>
复习模块
查看>>
Codeforces 691C Exponential notation(模拟)
查看>>
spring-excel-导出
查看>>
利用jenkins打造通过自定义参数更新svn 指定文件任务
查看>>
PID三种参数的理解
查看>>
07.移动端类库
查看>>
nginx支持https
查看>>
target与currentTarget与this的区别
查看>>
查看进程信息
查看>>
转载:DIV+CSS有可能遇到的问题
查看>>
protocol buffer
查看>>
web常用模块测试用例
查看>>
【转】分布式数据层 TDDL 来自:阿里巴巴
查看>>
swing常用布局
查看>>
#学习笔记#e2e学习使用(二)
查看>>
LeetCode 222.完全二叉树的节点个数(C++)
查看>>