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中的协程的更多相关文章

  1. Unity中的协程(一)

    这篇文章很不错的问题,推荐阅读英文原版: Introduction to Coroutines Scripting with Coroutines   这篇文章转自:http://blog.csdn. ...

  2. Unity中的协程是什么?

    什么是协程? 1.协程是一个分部执行,遇到条件(yield return 语句)会挂起,直到条件满足才会被唤醒继续执行后面的代码. 2.Unity在每一帧(Frame)都会去处理对象上的协程.Unit ...

  3. 协程及Python中的协程

    1 协程 1.1协程的概念 协程,又称微线程,纤程.英文名Coroutine.一句话说明什么是线程:协程是一种用户态的轻量级线程.(其实并没有说明白~) 我觉得单说协程,比较抽象,如果对线程有一定了解 ...

  4. Unity中使用协程进行服务端数据验证手段

    近期在做项目中的个人中心的一些事情,用户头像上传,下载,本地缓存,二级缓存,压缩,这些都要做,麻雀虽小五脏俱全啊,也是写的浑浑噩噩的, 当我们在上传用户头像的时候,向服务端发送上传头像请求之前,一般都 ...

  5. unity 中的协程

    //The coroutine will continue after all Update functionshave been calledon the next frame. ; //Conti ...

  6. Unity C#笔记 协程

    什么是协程 协同程序,在主程序运行的同时,开启另外一段逻辑处理,来协同当前程序的执行. 可能看了这段文字介绍还是有点模糊,其实可以用多线程来比较. 多线程 多线程,顾名思义,多条同时执行的线程. 最初 ...

  7. Unity中巧用协程和游戏对象的生命周期处理游戏重启的问题

    主要用到协程(Coroutines)和游戏对象的生命周期(GameObject Lifecycle)基础知识,巧妙解决了游戏重启的问题. 关于协程,这里有篇文章我觉得写的非常好,理解起来也很容易.推荐 ...

  8. 【Unity3D基础教程】给初学者看的Unity教程(五):详解Unity3D中的协程(Coroutine)

    作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 为什么需要协程 在游戏中有许多过程(Proc ...

  9. C#中的yield return与Unity中的Coroutine(协程)(下)

    Unity中的Coroutine(协程) 估计熟悉Unity的人看过或者用过StartCoroutine() 假设我们在场景中有一个UGUI组件, Image: 将以下代码绑定到Image using ...

随机推荐

  1. direct加载之ora-39782一例

    近日,我们有个环境在数据加载到oracle的时候出现ora-39782异常,版本是11.2.经google,几乎没有什么先例,因为我们是使用oci直接写的,可见现在还使用oci接口并不多,也或者我们的 ...

  2. debug代码时遇到循环时提高效率方法

    在循环时,需要查看uid=uid=12007255时的代码执行情况 可以在循环代码中加入 if((Long)map.get("uid") == 12007255){ System. ...

  3. opencv学习之路(14)、形态学之膨胀腐蚀

    一.膨胀腐蚀概述(对高亮部分进行操作) 二.膨胀 三.腐蚀 四.代码 1.查看结构元素 #include<opencv2/opencv.hpp> #include<iostream& ...

  4. docker 容器配置tocmat时间不统一

    1.在tomcat配置文件bin下 vim   setenv.sh #!/bin/bashCATALINA_OPTS='-Duser.timezone=Asia/Shanghai'export CAT ...

  5. 【python021-函数lambda表达式】

    一.匿名函数 1.lambda表达式 >>> g = lambda x:x*2+1>>> g(5)11>>> ---冒号前面的x是函数的参数,冒号 ...

  6. topcoder srm 420 div1

    problem1 link 暴力即可.因为即便所有数字的和是50,50所有的不同的划分数只有204226中.所以最长的循环也就这么大. problem2 link 令$f[i][j]$表示有$i$个红 ...

  7. linux下如何使make只输出执行过程中的命令序列

    答: make -n (-n.--just-print.--dry-run.--recon等价)

  8. Java日期时间(Date/Time)

    获取当前日期和时间 在Java中容易得到当前的日期和时间.可以使用一个简单的Date对象的toString()方法,如下所示打印当前日期和时间: import java.util.Date; publ ...

  9. html 之 td valign 和 align

    1.align属性趋向于左右对齐,其值包含:left.right.center 2.valign属性趋向于垂直对齐,其值包含:top.bottom.middle.baseline 兼容性 在 HTML ...

  10. 题解——洛谷P3390 【模板】矩阵快速幂(矩阵乘法)

    模板题 留个档 #include <cstdio> #include <algorithm> #include <cstring> #define int long ...