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中有些元素是不能操作的.这个时候能够使用协程来完毕. 使 ...
随机推荐
- UpdateLayeredWindow是炫效果的关键
自绘——是的,输入框每个字都自己绘制,计算行宽,行高,模拟光标闪烁,处理输入法的各种事件,以及选中,拖动等功能. 支持支持一下,实际上无句柄的,就是多行富文本编辑比较麻烦,其他的,都不复杂.很容易实现 ...
- jQuery Validate 验证,校验规则写在控件中的具体例子
将校验规则写到控件中 <script src="../js/jquery.js" type="text/javascript"></scrip ...
- 「Poetize7」电话线路
描述 每台电话都有一个独一无二的号码,用一个十位的十进制数字串表示.电话a和b之间能直接通信,当且仅当“a与b之间仅有一个数字不同”,或者“交换a的某 两位上的数字后,a与b相同”.而a.b之间建立通 ...
- 教您怎么从spring 官网下载参考文档
假如您使用spring,那么本经验可能帮助到您. 假如您使用spring的过程中,需要查询一些文档,那么本经验可能帮助到您. 假如您对下载spring的文档有疑惑,那么本经验可能帮助到您. 教您怎么从 ...
- 【转】Android--广播BroadcastReceiver
原文网址:http://www.cnblogs.com/plokmju/p/android_broadcastreceiver.html 前言 Android四大组件,Activity.Service ...
- 2015第37周二foxmail邮箱客户端迁移
foxmail7.0邮箱客户端迁移风波浪费我下午不少时间,不知为何做完foxmail客户端在卡的时候我将其强制关闭,然后将整个邮箱目录拷贝到一台新电脑上,运行客户端居然我要新建账户(账户信息丢失),将 ...
- AC自动机(Aho-Corasick automation)模板 HDU:2222
#include <iostream> #include <cstdio> #include <cstring> #include <queue> us ...
- 导出Excel文件,npoi方式和通过microsoft.visual basic.dll
一:例子截图: 二:NPOI截图 三:EmployeeListWindow.cs代码 using System; using System.Collections.Generic; using Sys ...
- 《JavaScript语言精髓与编程实践》读书笔记二
第3章非函数式语言特性 这一章首先介绍了语言的分类,命令式(结构化编程,面向对象编程),说明式(函数式等).而这一章,主要介绍JS的非函数式特点. 在开始之前,首先介绍了由“结构化编程”向“面向对象编 ...
- mysql5.5 对触发器,函数,存储引擎,事件进行主从复制情况.(转)
mysql5.5 对触发器,函数,存储引擎,事件进行主从复制情况. 转(http://blog.csdn.net/m582445672/article/details/7670802) 一.My ...