当前位置: 首页 > news >正文

wordpress外贸站gdpr国外搜索引擎大全

wordpress外贸站gdpr,国外搜索引擎大全,网站 无限下拉菜单,怎么用挂靠的公司做网站一.携程概述 官方的解释是,携程允许你可以在多个帧中执行任务。在Unity中,携程是一个可以暂停并在后续帧中从暂停处继续执行的方法。 二.携程写法 下面示例使用携程和Update打印前5帧的时间间隔,展示了携程的基础写法 using System.Colle…

一.携程概述

官方的解释是,携程允许你可以在多个帧中执行任务。在Unity中,携程是一个可以暂停并在后续帧中从暂停处继续执行的方法。

二.携程写法

下面示例使用携程和Update打印前5帧的时间间隔,展示了携程的基础写法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class demo2 : MonoBehaviour
{private int frameNum = 1;void Start(){StartCoroutine("coroutine");}public IEnumerator coroutine(){Debug.Log("coroutine frame1:" + Time.deltaTime);yield return null;Debug.Log("coroutine frame2:" + Time.deltaTime);yield return null;Debug.Log("coroutine frame3:" + Time.deltaTime);yield return null;Debug.Log("coroutine frame4:" + Time.deltaTime);yield return null;Debug.Log("coroutine frame5:" + Time.deltaTime);yield return null;}void Update(){if (frameNum <= 5){Debug.Log("------ Update:" + frameNum + "  " + Time.deltaTime);frameNum++;}}
}

  • 从打印结果来看,携程和Update一样会每帧调用一次
  • StartCoroutine用于开启携程
  • 返回值类型固定为IEnumerator
  • 返回值yield return null表示下一帧从此处之后开始执行,等同于yield return 一个数字

这里IEnumerator接口和yield关键字是C#的,不了解的可查看前两篇文章

三.Unity规定的携程返回值含义(标红的较为常用)

代码含义
yield return null;  yield retun x(x代表任意数字)下一帧再执行后续代码

yield return new WaitForSeconds(0.1f);

yield return new WaitForSecondsRealtime(0.1f); //不受timescale影响

等待固定时间执行后续代码
yield return FunctionName();函数执行完毕后执行后续代码
yield return Coroutine;协程执行完毕后执行后续代码
yield return new WaitForEndOfFrame();帧渲染完成后执行后续代码
yield return new WaitForFixedUpdate();物理帧更新后执行后续代码
yield break;结束该协程
yield return startCoroutine("funcName")等携程funName结束后执行后续代码

四.携程在事件函数中的执行顺序

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class demo1 : MonoBehaviour
{private bool logStart = true;void Start(){StartCoroutine("coroutine1");}void Update(){if (Input.GetKeyDown(KeyCode.S)){logStart = !logStart;Debug.Log(logStart);}if (logStart){Debug.Log("-------------------");Debug.Log("Update:" + Time.deltaTime);}}void LateUpdate(){if (logStart){Debug.Log("LateUpdate:" + Time.deltaTime);}}public IEnumerator coroutine1(){while (true){if (Input.GetKeyDown(KeyCode.S)){yield break;}else{Debug.Log("coroutine1:" + Time.deltaTime);yield return null;}}}
}

从打印结果来看,携程在Update之后,LateUpdate之前执行,官网的事件函数示意图也说明了这一点

五.携程的作用

1.替代Update处理一些耗时,按帧执行的任务,避免Update过于复杂

2.处理调用耗时API(比如切换场景)完成后在做什么的情况

六.携程可以传参可以嵌套

下面例子演示了crt1等待crt2结束后再执行后续,并给crt2传递参数

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class demo2 : MonoBehaviour
{void Start(){StartCoroutine("crt1");}public IEnumerator crt1(){Debug.Log("crt1 do task1");//携程2传参,等待携程2执行完成后,再执行后续代码yield return StartCoroutine("crt2", 3.0f);Debug.Log("crt1 do task2");}public IEnumerator crt2(float time){yield return new WaitForSeconds(time);Debug.Log("crt2 do task after " + time + "sec");yield return new WaitForSeconds(2);Debug.Log("crt2 finish");}void Update(){if (Input.GetKeyDown(KeyCode.S)){StopCoroutine("crt2");Debug.Log("crt2 is stopped");}if (Input.GetKeyDown(KeyCode.A)){StopAllCoroutines();Debug.Log("All crt stopped");}}
}

七.停止携程

StopCoroutine("funcName");  //停止携程funcName
StopAllCoroutines();        //停止脚本内所有携程
http://www.zhongyajixie.com/news/29802.html

相关文章:

  • 南宁哪里有做网站的公司湖南有实力seo优化哪家好
  • 如何为网站做seo体检中文域名
  • 世纪购网站开发招聘中国seo排行榜
  • 海口建网站公司网站的seo 如何优化
  • 无限制的网站访问厦门谷歌seo公司
  • 网站建设中企动力推荐首页百度
  • wordpress站点如何适应手机环球军事网最新军事新闻最新消息
  • wordpress前台修改网站seo哪家公司好
  • 教学互动网站的设计互联网营销推广公司
  • 亚洲网站正在建设中广告公司
  • 如何用ai给网站做logo百度网盘官网
  • 网站建设的功能百度爱采购关键词优化
  • wordpress 段子模板2020 惠州seo服务
  • wordpress缓存文件在优化手机性能的软件
  • 做网站 花园路国贸淘宝补流量平台
  • wordpress关于本站中国免费网站服务器下载
  • 腾讯云网站安全认证seo推广绩效考核指标是什么
  • 无锡seo网站建设费用谷歌推广真有效果吗
  • 网站开发者 敬请期待时事新闻热点
  • 汽配做的最好的网站网络营销成功的案例及其原因
  • 杭州公司招聘比较好的网络优化公司
  • 山东食品行业网站开发成都企业网站seo技术
  • 做外贸用什么网站搜索引擎推广简称
  • 做特产的网站seo流量排行榜神器
  • php 怎么做网站超链接公司推广渠道
  • 用jsp做的网站前后端交互企业网站推广方案
  • 顾村网站建设中国人民银行网站
  • 网站个人信息页面布局怎么让百度快速收录网站
  • 网站开发图标营销推广
  • 精品网站开发公司网站推广的要点