Эх сурвалжийг харах

修复UI换装中,异步操作导致的异步资源加载后,显示不正常问题

yun200895 1 долоо хоног өмнө
parent
commit
55701b9a00

+ 7 - 7
GameClient/Assets/Game/HotUpdate/DressUp/DressUpLayerOperation.cs

@@ -24,8 +24,8 @@ namespace GFGGame
         private int layerId;
         private bool needSetMask;
         private bool showAni;
-        private string resPath;
-        private string effectResPath;
+        public string resPath;
+        public string effectResPath;
 
         private int preRendering;
         private ResourceDownloaderOperation downloaderOperation;
@@ -124,7 +124,7 @@ namespace GFGGame
             Error = "User cancel.";
         }
 
-        internal override void UpdateView()
+        internal override void UpdateView(Action action = null)
         {
             if (parentObj == null)
             {
@@ -137,13 +137,13 @@ namespace GFGGame
             switch (actionType)
             {
                 case EAction.Layer:
-                    UpdateLayer();
+                    UpdateLayer(action);
                     break;
                 case EAction.Body:
-                    UpdateBody();
+                    UpdateBody(action);
                     break;
                 case EAction.Head:
-                    UpdateHead();
+                    UpdateHead(action);
                     break;
                 default:
                     break;
@@ -386,7 +386,7 @@ namespace GFGGame
                         resPath,
                         aniObjName,
                         parentObj,
-                        sortingOrder,
+                        5,
                         (gameObj) =>
                         {
                             if (gameObj != null)

+ 86 - 19
GameClient/Assets/Game/HotUpdate/DressUp/DressUpObj.cs

@@ -34,6 +34,13 @@ namespace GFGGame
             OnSuitPutOnComplete += callback;
         }
 
+        public void ResetOnSuitPutOnComplete()
+        {
+            _activeLayerOperationCount = 0;
+            _completedLayerOperationCount = 0;
+            OnSuitPutOnComplete = null; ;
+        }
+
         public int bgId
         {
             get { return _dressUpData.bgId; }
@@ -742,18 +749,22 @@ namespace GFGGame
                 }
             }
 
+
             CheckCurDressIsSuit();
+            UpdateBodyView(itemIdLianYiQun, action);
+
             var handler = DressUpUtil.UpdateHeadAsync(!hasZhuangRong, _sceneObj, _needSetMask, _roleObj);
+            //handler.Completed += (aob) => { UpdateBodyView(itemIdLianYiQun, action); };
             TryAddHandler(handler);
-            if (action == null)
-            {
-                UpdateBodyView(itemIdLianYiQun);
-            }
-            else
-            {
-                handler.Completed += (aob) => { UpdateBodyView(itemIdLianYiQun, action); };
-                //UpdateBodyView(itemIdLianYiQun, action);
-            }
+            //if (action == null)
+            //{
+            //    UpdateBodyView(itemIdLianYiQun);
+            //}
+            //else
+            //{
+            //    //handler.Completed += (aob) => { UpdateBodyView(itemIdLianYiQun, action); };
+            //    UpdateBodyView(itemIdLianYiQun, action);
+            //}
         }
 
         //更新整个身体
@@ -768,7 +779,9 @@ namespace GFGGame
             }
 
             var handler = DressUpUtil.UpdateBodyAsync(actionRes, _sceneObj, _needSetMask, _roleObj, itemIdLianYiQun);
-            handler.Completed += (aob) => { action?.Invoke(needYooAsseetDown); };
+            //handler.Completed += (aob) => { 
+            //    action?.Invoke(needYooAsseetDown);
+            //};
             TryAddHandler(handler);
         }
 
@@ -796,29 +809,82 @@ namespace GFGGame
                 if (draw)
                 {
                     var t = handlers.ToArray();
-                    handlers.Clear();
+                    Debug.Log($"===draw:{handlers.Count}");
+                    //_activeLayerOperationCount = handlers.Count;
+                    int w = 0;
+                    int q = 0;
                     foreach (var handler in t)
                     {
                         if (handler.Status == YooAsset.EOperationStatus.Succeed)
                         {
-                            handler.UpdateView();
-                            _completedLayerOperationCount++;
+                            if (handler is DressUpLayerOperation)
+                            {
+                                var duo = (DressUpLayerOperation)handler;
+                                Debug.Log($"{duo.actionType}, {duo.resPath}, {duo.effectResPath}");
+                                handler.UpdateView(() =>
+                                {
+                                    _completedLayerOperationCount++;
+                                    //_activeLayerOperationCount + 2 ,是因为update head和body没有_activeLayerOperationCount++???所以handlers.Count总是多两个
+                                    Debug.Log($"upLayer:{_completedLayerOperationCount}/{_activeLayerOperationCount + 2}");
+                                    if (_isPuttingOnSuit &&
+                                        _activeLayerOperationCount > 0 &&
+                                        _completedLayerOperationCount >= _activeLayerOperationCount + 2)
+                                    {
+                                        Debug.Log("进入uplayer的最终回调");
+                                        _isPuttingOnSuit = false;
+                                        OnSuitPutOnComplete?.Invoke();
+                                        ResetOnSuitPutOnComplete();
+                                    }
+                                });
+
+                                w++;
+                            }
+                            else if (handler is DressUpRemoveOperation)
+                            {
+                                var duo = (DressUpRemoveOperation)handler;
+                                Debug.Log(duo.itemID);
+                                //q++;
+                                handler.UpdateView(() =>
+                                {
+                                    //_completedLayerOperationCount++;
+                                    //Debug.Log($"remove:{_completedLayerOperationCount}/{_activeLayerOperationCount}");
+                                    //if (_isPuttingOnSuit &&
+                                    //   _activeLayerOperationCount > 0 &&
+                                    //   _completedLayerOperationCount >= _activeLayerOperationCount)
+                                    //{
+                                    //    Debug.Log("进入remove的最终回调");
+                                    //    _isPuttingOnSuit = false;
+                                    //    OnSuitPutOnComplete?.Invoke();
+                                    //    ResetOnSuitPutOnComplete();
+                                    //}
+                                });
+                            }
+                            else
+                            {
+                                Debug.Log("漏了");
+                            }
+                            //handler.UpdateView();
+                            // _completedLayerOperationCount++;
                         }
 
+                        
                         handler.Release();
                     }
+                    //Debug.Log($"WWWWWWW:{w}");
+                    //Debug.Log($"WWWWWWW:{q}");
 
                     onUpdateAction?.Invoke();
+                    handlers.Clear();
                     //LogUtil.LogEditor($"draw    {TimeHelper.ClientNow()}");
                 }
             }
 
-            if (_isPuttingOnSuit && _activeLayerOperationCount > 0 &&
-                _completedLayerOperationCount >= _activeLayerOperationCount)
-            {
-                _isPuttingOnSuit = false;
-                OnSuitPutOnComplete?.Invoke();
-            }
+            //if (_isPuttingOnSuit && _activeLayerOperationCount > 0 &&
+            //    _completedLayerOperationCount >= _activeLayerOperationCount)
+            //{
+            //    _isPuttingOnSuit = false;
+            //    OnSuitPutOnComplete?.Invoke();
+            //}
         }
 
         private void TryAddHandlers(List<DressUpLayerOperation> t)
@@ -827,6 +893,7 @@ namespace GFGGame
             {
                 foreach (var h in t)
                 {
+                    Debug.Log("_activeLayerOperationCount++");
                     _activeLayerOperationCount++;
                     TryAddHandler(h);
                 }

+ 1 - 1
GameClient/Assets/Game/HotUpdate/DressUp/DressUpObjUI.cs

@@ -86,8 +86,8 @@ namespace GFGGame
 
         public void UpdateWrapper(GGraph holder)
         {
-            holder.SetNativeObject(wrapper);
             wrapper.wrapTarget = sceneObject;
+            holder.SetNativeObject(wrapper);
         }
 
         public void Dispose()

+ 1 - 1
GameClient/Assets/Game/HotUpdate/DressUp/DressUpOperationBase.cs

@@ -23,7 +23,7 @@ namespace GFGGame
             }
         }
 
-        internal abstract void UpdateView();
+        internal abstract void UpdateView(Action action = null);
 
         internal abstract void Release();
         internal abstract bool CheckRepeated(DressUpOperationBase t);

+ 4 - 2
GameClient/Assets/Game/HotUpdate/DressUp/DressUpRemoveOperation.cs

@@ -1,4 +1,5 @@
-using UnityEngine;
+using System;
+using UnityEngine;
 using YooAsset;
 using static FairyGUI.ControllerAction;
 
@@ -53,7 +54,7 @@ namespace GFGGame
                 && removeOperation.parentObj == this.parentObj);
         }
 
-        internal override void UpdateView()
+        internal override void UpdateView(Action action = null)
         {
             if(parentObj == null)
             {
@@ -62,6 +63,7 @@ namespace GFGGame
             }
             //LogUtil.LogEditor($"remove UpdateView {itemID}");
             DressUpUtil.RemoveItem(this.itemID, this.parentObj);
+            action?.Invoke();
         }
     }
 }

+ 4 - 0
GameClient/Assets/Game/HotUpdate/DressUp/DressUpUtil.cs

@@ -424,6 +424,7 @@ namespace GFGGame
 
                 SetRenderersOrder(loadedObj, sortingOrder);
 
+                Debug.Log($"UpdateBody UpdateLayer 结束");
                 callback?.Invoke(loadedObj);
             });
         }
@@ -677,6 +678,7 @@ namespace GFGGame
                 if (renderer != null)
                 {
                     renderer.sortingOrder = sortingOrder;
+                    //renderer.gameObject.layer = LayerMask.NameToLayer("UI");
                 }
             }
 
@@ -687,6 +689,7 @@ namespace GFGGame
                 if (renderer != null)
                 {
                     renderer.sortingOrder = sortingOrder;
+                   // renderer.gameObject.layer = LayerMask.NameToLayer("UI");
                 }
             }
 
@@ -695,6 +698,7 @@ namespace GFGGame
             {
                 var spriteRender = spritesRenderers[i];
                 spriteRender.sortingOrder = sortingOrder;
+                //spriteRender.gameObject.layer = LayerMask.NameToLayer("UI");
             }
         }