xlua 实现协程替换Unity中的协程
C#中的协程:
IEnumerator ShowSpiritInfo()
{
UIMessageMgr.ShowMsgWait(true); DestroyUIModelInfo(); bool isLoad = false;
AppInterface.GUIModule.CreateUISpirit(currSpiritId, delegate(UISpirit sp)
{
infoTextureCtrl.TargetSpirit = sp;
infoTextureCtrl.ui_Tx.width = ;
infoTextureCtrl.ui_Tx.height = ;
isLoad = true;
});
while (!isLoad)
yield return null;
modelTex.enabled = true;
UIMessageMgr.ShowMsgWait(false);
}
xlua中实现以上协程:
local ShowSpiritInfo = function(previewWnd)
return util.cs_generator(function()
CS.UIMessageMgr.ShowMsgWait(true); previewWnd:DestroyUIModelInfo(); -- 加载精灵
local PlayerManager = CS.Common.AppInterface.GUIModule.PlayerManager;
local root = PlayerManager.m_ModelRoot;
local spirit = CS.UISpirit(PlayerManager.m_ModelRoot, previewWnd.currSpiritId);
PlayerManager.listSpirit:Add(spirit);
PlayerManager.dicSpirit:Add(spirit.number, spirit);
local isLoad = false;
spirit:BeginLoad(function()
isLoad = true;
end);
while false == isLoad do
coroutine.yield(CS.UnityEngine.WaitForSeconds(0.01));
end previewWnd.infoTextureCtrl.TargetSpirit = spirit;
previewWnd.infoTextureCtrl.ui_Tx.width = ;
previewWnd.infoTextureCtrl.ui_Tx.height = ;
previewWnd.modelTex.enabled = true; CS.UIMessageMgr.ShowMsgWait(false);
end)
end;
xlua中主要是 1、2、17、18、19行的写法。
调用(第10行实现):
xlua.hotfix(CS.Modules.UI.UI_SpiritPreviewWnd, "OnChooseHandle", function(self, index)
if index >= and index <= self.currSpiritConfigList.Count then
self.currSpiritConfig = self.currSpiritConfigList[index];
self.currSpiritId = self.currSpiritConfig.f_SpiritID;
self.currSpiritData = CS.ClientData.ClientSpiritData.CreateSpiritData(self.currSpiritId);
self:RefreshSpiritInfo();
if == self.currSpiritConfigList[index].f_NextStarID then
CS.GameDefine.Mono:StartCoroutine(ShowCharacterInfo(self));
else
CS.GameDefine.Mono:StartCoroutine(ShowSpiritInfo(self));
end
end
end)
xlua 实现协程替换Unity中的协程的更多相关文章
- Unity中的协程(一)
这篇文章很不错的问题,推荐阅读英文原版: Introduction to Coroutines Scripting with Coroutines 这篇文章转自:http://blog.csdn. ...
- Unity中的协程是什么?
什么是协程? 1.协程是一个分部执行,遇到条件(yield return 语句)会挂起,直到条件满足才会被唤醒继续执行后面的代码. 2.Unity在每一帧(Frame)都会去处理对象上的协程.Unit ...
- 协程及Python中的协程
1 协程 1.1协程的概念 协程,又称微线程,纤程.英文名Coroutine.一句话说明什么是线程:协程是一种用户态的轻量级线程.(其实并没有说明白~) 我觉得单说协程,比较抽象,如果对线程有一定了解 ...
- Unity中使用协程进行服务端数据验证手段
近期在做项目中的个人中心的一些事情,用户头像上传,下载,本地缓存,二级缓存,压缩,这些都要做,麻雀虽小五脏俱全啊,也是写的浑浑噩噩的, 当我们在上传用户头像的时候,向服务端发送上传头像请求之前,一般都 ...
- unity 中的协程
//The coroutine will continue after all Update functionshave been calledon the next frame. ; //Conti ...
- Unity C#笔记 协程
什么是协程 协同程序,在主程序运行的同时,开启另外一段逻辑处理,来协同当前程序的执行. 可能看了这段文字介绍还是有点模糊,其实可以用多线程来比较. 多线程 多线程,顾名思义,多条同时执行的线程. 最初 ...
- Unity中巧用协程和游戏对象的生命周期处理游戏重启的问题
主要用到协程(Coroutines)和游戏对象的生命周期(GameObject Lifecycle)基础知识,巧妙解决了游戏重启的问题. 关于协程,这里有篇文章我觉得写的非常好,理解起来也很容易.推荐 ...
- 【Unity3D基础教程】给初学者看的Unity教程(五):详解Unity3D中的协程(Coroutine)
作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 为什么需要协程 在游戏中有许多过程(Proc ...
- C#中的yield return与Unity中的Coroutine(协程)(下)
Unity中的Coroutine(协程) 估计熟悉Unity的人看过或者用过StartCoroutine() 假设我们在场景中有一个UGUI组件, Image: 将以下代码绑定到Image using ...
随机推荐
- Linux一些基本配置
Linux发行版:centos 6.5 配置yum源 wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -P /etc/yum.repos ...
- 使用mac自带终端修改hosts
修改mac host文件绑定域名 打开终端 在终端terminal中输入sudo vi/etc/hosts sudo与vi之间有一个空格 上一步输入完成之后按enter回车键,如果当前用户账号有密码, ...
- Getting started with Kaggle -- Kaggle Competitions
1: The Competition We'll be learning how to generate a submission for a Kaggle competition. Kaggle i ...
- Flask学习【第4篇】:用Flask的扩展实现的简单的页面登录
from flask import Flask,render_template,request,redirect,session app = Flask(__name__,template_folde ...
- How to Install LibreOffice 6.0 on Ubuntu 16.04 LTS +
1. Add the LibreOffice 6.0 PPA The LibreOffice Fresh PPA is maintained by LibreOffice. It provides l ...
- vim插件的安装方式 -- vim注释插件和doxygen函数注释生成插件-ctrlp插件-tabular等号对齐 插件
使用unzip的时候 指定 -d选项, 是说明解压到的 目标地址. 这个参数还是比较方便的, 比直接unzip到当前目录, 然后在去拷贝到目标目录, 然后再删除当前目录中的解压文件夹, 方便多了. 使 ...
- IntelliJ IDEA 中SpringBoot对Run/Debug Configurations配置 SpringBoot热部署
运行一个SpringBoot多模块应用 使用SpringBoot配置启动: Use classpath of module选中要运行的模块 VM options:内部配置参数 -Dserver.por ...
- CentOS 7.3 上安装docker
Docker,分为社区版CE和企业版EE.社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务. 一.安装docker 1.Docker 要求 CentOS 系统的内核版本高于 3 ...
- AtCoder Beginner Contest 120 解题报告
为啥最近都没有arc啊... A - Favorite Sound #include <algorithm> #include <iostream> #include < ...
- P1948 [USACO08JAN]电话线Telephone Lines(二分答案+最短路)
思路 考虑题目要求求出最小的第k+1大的边权,想到二分答案 然后二分第k+1大的边权wx 把所有边权<=wx的边权变为0,边权>wx的边权变为0,找出最短路之后,如果dis[T]<= ...