zoukankan      html  css  js  c++  java
  • xlua 实现协程替换Unity中的协程

    C#中的协程:

     1      IEnumerator ShowSpiritInfo()
     2         {
     3             UIMessageMgr.ShowMsgWait(true);
     4 
     5             DestroyUIModelInfo();
     6 
     7             bool isLoad = false;
     8             AppInterface.GUIModule.CreateUISpirit(currSpiritId, delegate(UISpirit sp)
     9             {
    10                 infoTextureCtrl.TargetSpirit = sp;
    11                 infoTextureCtrl.ui_Tx.width = 720;
    12                 infoTextureCtrl.ui_Tx.height = 720;
    13                 isLoad = true;
    14             });
    15             while (!isLoad)
    16                 yield return null;
    17             modelTex.enabled = true;
    18             UIMessageMgr.ShowMsgWait(false);
    19         }

    xlua中实现以上协程:

     1 local ShowSpiritInfo = function(previewWnd)    
     2     return util.cs_generator(function()
     3         CS.UIMessageMgr.ShowMsgWait(true);
     4 
     5         previewWnd:DestroyUIModelInfo();
     6 
     7         -- 加载精灵
     8         local PlayerManager = CS.Common.AppInterface.GUIModule.PlayerManager;
     9         local root = PlayerManager.m_ModelRoot;
    10         local spirit = CS.UISpirit(PlayerManager.m_ModelRoot, previewWnd.currSpiritId);
    11         PlayerManager.listSpirit:Add(spirit);
    12         PlayerManager.dicSpirit:Add(spirit.number, spirit);
    13         local isLoad = false;
    14         spirit:BeginLoad(function() 
    15             isLoad = true;
    16         end);
    17         while false == isLoad do 
    18             coroutine.yield(CS.UnityEngine.WaitForSeconds(0.01));
    19         end
    20 
    21         previewWnd.infoTextureCtrl.TargetSpirit = spirit;
    22         previewWnd.infoTextureCtrl.ui_Tx.width = 720;
    23         previewWnd.infoTextureCtrl.ui_Tx.height = 720;
    24         previewWnd.modelTex.enabled = true;
    25 
    26         CS.UIMessageMgr.ShowMsgWait(false);
    27     end)
    28 end;

    xlua中主要是 1、2、17、18、19行的写法。

    调用(第10行实现):

     1 xlua.hotfix(CS.Modules.UI.UI_SpiritPreviewWnd, "OnChooseHandle", function(self, index)
     2     if index >= 0 and index <= self.currSpiritConfigList.Count then
     3         self.currSpiritConfig = self.currSpiritConfigList[index];
     4         self.currSpiritId = self.currSpiritConfig.f_SpiritID;
     5         self.currSpiritData = CS.ClientData.ClientSpiritData.CreateSpiritData(self.currSpiritId);
     6         self:RefreshSpiritInfo();
     7         if 0 == self.currSpiritConfigList[index].f_NextStarID then
     8             CS.GameDefine.Mono:StartCoroutine(ShowCharacterInfo(self));
     9         else
    10             CS.GameDefine.Mono:StartCoroutine(ShowSpiritInfo(self));
    11         end
    12     end
    13 end)
  • 相关阅读:
    洛谷 P2048 [NOI2010]超级钢琴(优先队列,RMQ)
    洛谷P1074 靶形数独(跳舞链)
    洛谷P1337 [JSOI2004]平衡点 / 吊打XXX(模拟退火)
    洛谷P4003 无限之环(费用流)
    洛谷P3264 [JLOI2015]管道连接(斯坦纳树)
    洛谷P3190 [HNOI2007]神奇游乐园(插头dp)
    洛谷P3272 [SCOI2011]地板(插头dp)
    常用的端口配置
    Win7+Eclipse+Hadoop2.6.4开发环境搭建
    Windows10+eclipse+hadoop2.7.1环境配置+wordcount-折腾笔记
  • 原文地址:https://www.cnblogs.com/luguoshuai/p/10332394.html
Copyright © 2011-2022 走看看