StartCoroutine/StopCoroutineInvoke
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_Coroutine.html
using UnityEngine;
using System.Collections; public class CoroutineTest : MonoBehaviour { void Start () {
print("Starting " + Time.time);
StartCoroutine(WaitAndPrint(0.2F));
print("Before WaitAndPrint Finishes " + Time.time);
} IEnumerator WaitAndPrint(float waitTime) {
print("StartCoroutine1 " + Time.time);
StartCoroutine("DoSomething", 2.0f);
print("StartCoroutine2 " + Time.time);
yield return new WaitForSeconds(waitTime);
print("StopCoroutine1 " + Time.time);
StopCoroutine("DoSomething");
print("StopCoroutine2 " + Time.time);
} IEnumerator DoSomething(float someParameter) {
while (true) {
print("DoSomething Loop");
yield return null;
}
} void Projectile() {
print("Projectile " + Time.time);
} void LaunchProjectile() {
print("LaunchProjectile " + Time.time);
} // Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Space) && !IsInvoking("LaunchProjectile")) {
InvokeRepeating("LaunchProjectile", 2f, 0.5f);
Invoke("Projectile", 2f);
}
if (Input.GetKeyDown(KeyCode.X)) {
Debug.Log("CancelInvoke");
CancelInvoke("LaunchProjectile");
}
}
}
#region Assembly UnityEngine.dll, v0.0.0.0
// D:\Program\Unity Project\test\Library\UnityAssemblies\UnityEngine.dll
#endregion using System;
using System.Collections;
using UnityEngine.Internal;
using UnityEngine.Scripting; namespace UnityEngine {
// Summary:
// MonoBehaviour is the base class every script derives from.
[RequiredByNativeCode]
public class MonoBehaviour : Behaviour {
[WrapperlessIcall]
public MonoBehaviour(); // Summary:
// Disabling this lets you skip the GUI layout phase.
public bool useGUILayout { get; set; } // Summary:
// Cancels all Invoke calls on this MonoBehaviour.
public void CancelInvoke();
//
// Summary:
// Cancels all Invoke calls with name methodName on this behaviour.
//
// Parameters:
// methodName:
[WrapperlessIcall]
public void CancelInvoke(string methodName);
//
// Summary:
// Invokes the method methodName in time seconds.
//
// Parameters:
// methodName:
//
// time:
[WrapperlessIcall]
public void Invoke(string methodName, float time);
//
// Summary:
// Invokes the method methodName in time seconds, then repeatedly every repeatRate
// seconds.
//
// Parameters:
// methodName:
//
// time:
//
// repeatRate:
[WrapperlessIcall]
public void InvokeRepeating(string methodName, float time, float repeatRate);
//
// Summary:
// Is any invoke pending on this MonoBehaviour?
public bool IsInvoking();
//
// Summary:
// Is any invoke on methodName pending?
//
// Parameters:
// methodName:
[WrapperlessIcall]
public bool IsInvoking(string methodName);
//
// Summary:
// Logs message to the Unity Console (identical to Debug.Log).
//
// Parameters:
// message:
public static void print(object message);
//
// Summary:
// Starts a coroutine.
//
// Parameters:
// routine:
public Coroutine StartCoroutine(IEnumerator routine);
//
// Summary:
// Starts a coroutine named methodName.
//
// Parameters:
// methodName:
//
// value:
[ExcludeFromDocs]
public Coroutine StartCoroutine(string methodName);
//
// Summary:
// Starts a coroutine named methodName.
//
// Parameters:
// methodName:
//
// value:
[WrapperlessIcall]
public Coroutine StartCoroutine(string methodName, object value);
[WrapperlessIcall]
public Coroutine StartCoroutine_Auto(IEnumerator routine);
//
// Summary:
// Stops all coroutines running on this behaviour.
[WrapperlessIcall]
public void StopAllCoroutines();
public void StopCoroutine(Coroutine routine);
//
// Summary:
// Stops the first coroutine named methodName, or the coroutine stored in routine
// running on this behaviour.
//
// Parameters:
// methodName:
// Name of coroutine.
//
// routine:
// Name of the function in code.
public void StopCoroutine(IEnumerator routine);
//
// Summary:
// Stops the first coroutine named methodName, or the coroutine stored in routine
// running on this behaviour.
//
// Parameters:
// methodName:
// Name of coroutine.
//
// routine:
// Name of the function in code.
[WrapperlessIcall]
public void StopCoroutine(string methodName);
}
}
- yield; The coroutine will continue after all Update functions have been called on the next frame.
yield:协程在所有的Update函数于下一帧调用后继续执行。 - yield WaitForSeconds(2); Continue after a specified time delay, after all Update functions have been called for the frame
yield WaitForSeconds(2):在一个指定的时间延迟后继续执行,在所有的Update函数被调用之后。 - yield WaitForFixedUpdate(); Continue after all FixedUpdate has been called on all scripts
yield WaitForFixedUpdate():在所有脚本上所有的FixedUpdate被调用之后继续执行。 - yield WWW Continue after a WWW download has completed.
yield WWW:在WWW加载完成之后继续执行。 - yield StartCoroutine(MyFunc); Chains the coroutine, and will wait for the MyFunc coroutine to complete first.
yield StartCoroutine(MyFunc):用于链接协程,此将等待MyFunc协程完成先
yield WaitForEndOfFrame(); 用于本帧渲染完
yield return new WaitForEndOfFrame(); // 本帧渲染完后
StartCoroutine/StopCoroutineInvoke的更多相关文章
- 关于StartCoroutine的简单线程使用
StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,但是在unity中有些元素是不能操作的.这个时候可以使用协程来完成. 使 ...
- 9. MonoBehaviour.StartCoroutine 开始协同程序
function StartCoroutine (routine : IEnumerator) : Coroutine 描述:开始协同程序. 一个协同程序在执行过程中,可以在任意位置使用yield语句 ...
- 使用startCoroutine制定倒计时
使用startCoroutine制定倒计时 using UnityEngine; using System.Collections; public class TimerCoroutine : Mon ...
- 【错误总结1:unity StartCoroutine 报 NullReferenceException 错误】
今天在一个项目中,写了一个单例的全局类,该类的作用是使用协程加载场景.但在StartCoroutine 这一步报了NullReferenceException 的错.仔细分析和搜索之后,得到错误原因. ...
- StartCoroutine 和 StopCoroutine
我的Unity版本是2017.2.0p4(64-bit) StartCoroutine的两个版本: StartCoroutine(string methodName) StartCoroutine(I ...
- 问题记录,StartCoroutine(“str")问题
StartCoroutine参数为函数字符串名,运行时出错,错误是:无法启动协程函数. 调用格式如下: gameManager.StartCoroutine(LuaOnLevelwasloaded() ...
- unity, StartCoroutine and StopCoroutine
startCoroutine("func",1.0f)可以用stopCoroutine("func")来停. startCoroutine(func(1.0f) ...
- unity关于StartCoroutine的简单线程使用
StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,但是在unity中有些元素是不能操作的.这个时候可以使用协程来完成. 使 ...
- StartCoroutine的使用
StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,可是在unity中有些元素是不能操作的.这个时候能够使用协程来完毕. 使 ...
随机推荐
- weblogic重置密码
1.备份DefaultAuthenticatorInit.ldift文件 cd /app/weblogic_cs/Oracle/Middleware/user_projects/domains/ntf ...
- SharePoint Server 2007 Enterprise Key
正式版 key SN: Tkjcb-3wkhk-2ty2t-qymk2-9xm2y 这个版本也是通过Key来区分是否是测试版还是正式版的 也就是说你输入正式版的Key他就是正式版,输入Enterpri ...
- 关于sed中的Pattern Space和Hold Space的随笔
首先是一部分概念和示例,这部分转自:http://coolshell.cn/articles/9104.html Pattern Space 第零个是关于-n参数的,大家也许没看懂,没关系,我们来看一 ...
- VMware: windows8 与 虚拟机ubuntu 14.04 共享文件夹
假设当前用户为xxx 安装 VMwareTools 1. 打开 VMwareworkstation窗口,选择”虚拟机” -> “重新安装VMwareTools(T)”. 点击之后,会发现 Ubu ...
- Hdu 3887 Counting Offspring \ Poj 3321 Apple Tree \BZOJ 1103 [POI2007]大都市meg
这几个题练习DFS序的一些应用. 问题引入: 给定一颗n(n <= 10^5)个节点的有根树,每个节点标有权值,现有如下两种操作: 1.C x y 以节点x的权值修改为y. 2.Q x ...
- Tomcat Server Locations
- 《Web 前端面试指南》2、JavaScript 的 Bind 函数进阶
使用 Bind() 设置方法中 this 对象 //<button>获取随机的人</button> //<input type="text"> ...
- ios使用openUrl进行应用跳转
1.拨打电话: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://68979"]]; ...
- Cocos2d-x 3.0 实例学习教程 前沿
前一段时间学过cocos2d-x 2.x ,后来去做了一些别的项目.近期又想开发自己的游戏了,但是cocos2d-x 已经升级到3.0 ,好多API都变了.所以决定再把cocos2d-x学一遍,一是 ...
- [转] 多线程下变量-gcc原子操作 __sync_fetch_and_add等
http://blog.sina.com.cn/s/blog_6f5b220601013zw3.html 非常好的原子操作,不用加锁:__sync_fetch_and_add GCC 提供的原子操作 ...