Sfoglia il codice sorgente

优化商店加载速度

lzx 2 giorni fa
parent
commit
c5df8a65d1
1 ha cambiato i file con 30 aggiunte e 13 eliminazioni
  1. 30 13
      Assets/Scripts/GameUI/UI/ShopPanel/ShopGroupWidgetType1.cs

+ 30 - 13
Assets/Scripts/GameUI/UI/ShopPanel/ShopGroupWidgetType1.cs

@@ -45,7 +45,8 @@ namespace Fort23.Mono
                 }
                 else
                 {
-                    Text_RefenceTime.text = PlayerManager.TimeToHSM((this.shopData.refreshTime - PlayerManager.Instance.serverTime) / 1000);
+                    Text_RefenceTime.text =
+                        PlayerManager.TimeToHSM((this.shopData.refreshTime - PlayerManager.Instance.serverTime) / 1000);
                 }
             }
         }
@@ -70,7 +71,8 @@ namespace Fort23.Mono
             Text_Title.text = LanguageManager.Instance.Text(_shopConfig.shopName);
             if (this.shopData.refreshTime != -1)
             {
-                Text_RefenceTime.text = PlayerManager.TimeToHSM((this.shopData.refreshTime - PlayerManager.Instance.serverTime) / 1000);
+                Text_RefenceTime.text =
+                    PlayerManager.TimeToHSM((this.shopData.refreshTime - PlayerManager.Instance.serverTime) / 1000);
                 RefenceTimeRoot.gameObject.SetActive(true);
             }
             else
@@ -79,21 +81,36 @@ namespace Fort23.Mono
             }
 
 
-            foreach (var shopItem in shopData.shopItemList)
+            using (CTaskAwaitBuffer<ShopItemWidgetType2> cts = new CTaskAwaitBuffer<ShopItemWidgetType2>())
             {
-                // if (shopData.id == 1 || shopData.id == 5)
-                // {
-                //     ShopItemWidgetType1 shopItemWidgetType1 = await UIManager.Instance.CreateGComponent<ShopItemWidgetType1>(null, Connect);
-                //     shopItemWidgetType1.CustomInit(shopItem);
-                //     _shopItemWidgetType1s.Add(shopItemWidgetType1);
-                // }
-                // else
+                foreach (var shopItem in shopData.shopItemList)
                 {
-                    ShopItemWidgetType2 shopItemWidgetType1 = await UIManager.Instance.CreateGComponent<ShopItemWidgetType2>(null, Connect);
-                    shopItemWidgetType1.CustomInit(shopItem);
-                    _shopItemWidgetType2s.Add(shopItemWidgetType1);
+                    cts.AddTask(UIManager.Instance.CreateGComponent<ShopItemWidgetType2>(null, Connect));
                 }
+
+                _shopItemWidgetType2s = await cts.WaitAll();
             }
+
+            for (var i = 0; i < shopData.shopItemList.Count; i++)
+            {
+                _shopItemWidgetType2s[i].CustomInit(shopData.shopItemList[i]);
+            }
+
+            // foreach (var shopItem in shopData.shopItemList)
+            // {
+            //     // if (shopData.id == 1 || shopData.id == 5)
+            //     // {
+            //     //     ShopItemWidgetType1 shopItemWidgetType1 = await UIManager.Instance.CreateGComponent<ShopItemWidgetType1>(null, Connect);
+            //     //     shopItemWidgetType1.CustomInit(shopItem);
+            //     //     _shopItemWidgetType1s.Add(shopItemWidgetType1);
+            //     // }
+            //     // else
+            //     {
+            //         ShopItemWidgetType2 shopItemWidgetType1 = await UIManager.Instance.CreateGComponent<ShopItemWidgetType2>(null, Connect);
+            //         shopItemWidgetType1.CustomInit(shopItem);
+            //         _shopItemWidgetType2s.Add(shopItemWidgetType1);
+            //     }
+            // }
             LayoutRebuilder.ForceRebuildLayoutImmediate(Connect);
             LayoutRebuilder.ForceRebuildLayoutImmediate(transform);
         }