Unity3d 协程、调用函数、委托
(一)协程
开启方法:StartCoroutine("函数名");
结束方法StopCoroutine("函数名"),StopAllCoroutines();
IEnumerator TestIEnumerator()
{
Debug.Log("协程");
//等待游戏界面绘制完成
yield return new WaitForEndOfFrame();
Debug.Log("游戏界面绘制完成");
//等待1秒后
yield return new WaitForSeconds(1F);
Debug.Log("1秒后");
//等待0.5秒后
yield return new WaitForSeconds(0.5F);
Debug.Log("0.5秒后");
while(true)
{
//等待固定更新
yield return new WaitForFixedUpdate();
Debug.Log("固定更新");
}
}
// Use this for initialization
void Start () {
StartCoroutine("TestIEnumerator");
}
(二)调用函数
开启方法
不重复调用
Invoke("函数名",“延迟时间”); 重复调用 InvokeRepeating("函数名",“延迟时间”,“重复间隔时间”);
结束方法
CancelInvoke("函数名"),CancelInvoke();
是否在有在调用的函数
IsInvoking(); 指定函数是否在调用 IsInvoking("函数名");
void TestInvokeRepeating()
{
Debug.Log("重复调用");
m_round++;
if (m_round > 15)
{
//结束所有调用
//CancelInvoke();
//结束指定调用
CancelInvoke("TestInvokeRepeating");
} if (IsInvoking("TestInvokeRepeating"))
{
Debug.Log("调用中");
}
else
{
Debug.Log("不在调用中");
}
}
void TestInvokeRepeating2()
{
Debug.Log("重复调用TestInvokeRepeating2"); }
// Use this for initialization
void Start () {
m_round = 0;
InvokeRepeating("TestInvokeRepeating",0f,1f);
InvokeRepeating("TestInvokeRepeating2", 0f, 1f);
}
(二)委托
public class GameManager : MonoBehaviour
{
//定义一个委托
delegate int TestEntrust(int a); public int ReceiveLogic(int a)
{
Debug.Log("参数a="+a);
return 0;
}
// Use this for initialization
void Start () {
//创建委托对象
TestEntrust rl = new TestEntrust(ReceiveLogic);
//调用
rl(3);
}
}
Unity3d 协程、调用函数、委托的更多相关文章
- Unity3D 协程 Coroutine
协程(Coroutine)的概念存在于很多编程语言,例如Lua.ruby等.而由于Unity3D是单线程的,因此它同样实现了协程机制来实现一些类似于多线程的功能,但是要明确一点协程不是进程或线程,其执 ...
- Unity3D协程yield的理解
Unity3D的协程概括地将就是:对于一段程序,你可以加上yield标明哪里需要暂停,然后在下一帧或者一段时间后,系统会继续执行这段代码.协程的作用:①延迟一段时间执行代码.②等某个操作完成之后再执行 ...
- 二、深入asyncio协程(任务对象,协程调用原理,协程并发)
由于才开始写博客,之前都是写笔记自己看,所以可能会存在表述不清,过于啰嗦等各种各样的问题,有什么疑问或者批评欢迎在评论区留言. 如果你初次接触协程,请先阅读上一篇文章初识asyncio协程对asy ...
- Unity3D 协程 浅谈
协程 理解:协程不是线程,也不是异步执行(知道就行). 1.协程和MonoBehaviour的Update函数一样,也是在MainThread中执行的(一定得明白这句话意思). void Start ...
- Unity3d 协程
参考文章: http://blog.csdn.net/onafioo/article/details/48979939 http://www.cnblogs.com/zhaoqingqing/p/37 ...
- [转]Unity3D协程介绍 以及 使用
作者ChevyRay ,2013年9月28日,snaker7译 原文地址:http://unitypatterns.com/introduction-to-coroutines/ 在Unity中,协 ...
- Unity3d 协程的注意问题(新手须注意,老手须加勉)
关于unity3d的协程,非常的好用,比如等待几秒执行,等待下一帧执行等! 但是也有潜在的问题: 1.协程是单线程的,在主线程中完成 2.如果发现yield, 那么这一帧会结束,那么等下一帧调用此脚本 ...
- Unity3D协程
协程介绍 Unity的协程系统是基于C#的一个简单而强大的接口 ,IEnumerator,它允许你为自己的集合类型编写枚举器.这一点你不必关注太多,我们直接进入一个简单的例子来看看协程到底能干什么.首 ...
- Unity3D协程介绍 以及 使用
作者ChevyRay ,2013年9月28日,snaker7译 原文地址:http://unitypatterns.com/introduction-to-coroutines/ 在Unity中,协 ...
随机推荐
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 【思路、优化】UVa 11491 - Erasing and Winning
Juliano is a fan of the TV show Erasing and Winning, where participants are selected in a draw and r ...
- Microsoft.SharePoint.Security的问题
请求“Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0 ...
- 原生javascript焦点轮播图
刚刚学会,写了一个轮播图效果,不过bug蛮多,请高手指点一下,谢谢 <!DOCTYPE html> <html> <head> <meta charset=& ...
- ActiveMQ(5.10.0) - 使用 JDBC 持久化消息
1. 编辑 ACTIVEMQ_HOME/conf/activemq.xml. <beans> <broker brokerName="localhost" per ...
- Jersey(1.19.1) - Use of @Context
Previous sections have introduced the use of @Context. The JAX-RS specification presents all the sta ...
- iOS开发——毛玻璃透明
主要实现的代码如下: self.rateInfoView是定义好的控制属性控件 可以改变透明度的值来改变毛玻璃透明的效果 // 虚拟交易费率弹窗 - (void)showRateInfo{ self. ...
- abstract
/// <summary> /// 抽象类不能被直接实例化 /// is a /// </summary> public abstract class BasePhone { ...
- eclipse中英文切换--四种方式
若转载,请注明出处 http://www.cnblogs.com/last_hunter/p/5627009.html 谢谢! ------------------------------------ ...
- TransparentBlt函数的使用注意事项
今天客户需要在软件上需要添加一个自己公司的Logo,要求使用镂空透明的形式展现,本来以为很简单的工作没想到在MFC下这么复杂.Logo为BMP格式,白色背景. 以为和在按钮上显示控件差不多,先导入BI ...