您当前的位置: 首页 >  unity

Peter_Gao_

暂无认证

  • 0浏览

    0关注

    621博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

UnityAction异步回调导致的方法执行时机错误

Peter_Gao_ 发布时间:2021-04-22 17:12:24 ,浏览量:0

 

   else if(reply.upcomingEventsItem.Count > 0)
            {
                Debug.Log("reply.buyPackage == null 或 this.eventsReply == null");
                UpComingBuffer.GetInstance().UpComingEventList = reply.upcomingEventsItem;
                this.eventsReply = reply;
                //ResourcesLoader.Load("UI/prefab/UIdailyItem", onLoaded:(obj) =>
                ResourcesLoader.Load("UI/prefab/UIActivityHubItemCell", (obj) =>
                {
                    this.updateEventCell(this.eventsReply);
                });
                Debug.Log("初始reply.upcomingEventsItem.Count = "+reply.upcomingEventsItem.Count + 
                          "  已加载完左侧条目cell列表,cellList.Count =  " + cellList.Count);
                
                //触发一下第一次打开时选中第一个itemCell
                if (!isFirstCellSelected && CellListWonderful.Count > 0)
                {
                    CellListWonderful.LastOrDefault().GetComponent().onClick.Invoke();
                    isFirstCellSelected = true;
                }
            }
            else
            {
                Debug.Log("reply.upcomingEventsItem和reply.upcomingEventsBuy都为空");
            }
        }
        else
        {
            Debug.Log("反信失败" );
        }

实际运行时机是 1,2,3, 但目的是 1, 3, 2

把 上面的步骤2 移动回调就可以了:

            else if(reply.upcomingEventsItem.Count > 0)
            {
                Debug.Log("reply.buyPackage == null 或 this.eventsReply == null");
                UpComingBuffer.GetInstance().UpComingEventList = reply.upcomingEventsItem;
                this.eventsReply = reply;
                //ResourcesLoader.Load("UI/prefab/UIdailyItem", (obj) =>
                ResourcesLoader.Load("UI/prefab/UIActivityHubItemCell", (obj) =>
                {
                    this.updateEventCell(this.eventsReply);
                    //触发一下第一次打开时选中第一个itemCell
                    if (!isFirstCellSelected && CellListWonderful.Count > 0)
                    {
                        CellListWonderful.LastOrDefault().GetComponent().onClick.Invoke();
                        isFirstCellSelected = true;
                    }
                });
                Debug.Log("初始reply.upcomingEventsItem.Count = "+reply.upcomingEventsItem.Count + 
                          "  已加载完左侧条目cell列表,cellList.Count =  " + cellList.Count);
            }
            else
            {
                Debug.Log("reply.upcomingEventsItem和reply.upcomingEventsBuy都为空");
            }

 

关注
打赏
1664521772
查看更多评论
立即登录/注册

微信扫码登录

0.0382s