Browse Source

UI界面改为同步加载

guodong 1 year ago
parent
commit
1adf3bf6ca

+ 39 - 38
GameClient/Assets/Game/HotUpdate/FairyGUI/GFGUIPackage.cs

@@ -24,51 +24,52 @@ namespace GFGGame
             var handle = YooAssets.LoadAssetSync<TextAsset>($"{descFilePath}_fui.bytes");
             TextAsset textAsset = handle.AssetObject as TextAsset;
             CacheAssetHandle(descFilePath, handle);
-            //var uiPackage = UIPackage.AddPackage(textAsset.bytes, descFilePath, (string name, string extension, System.Type type, out DestroyMethod destroyMethod) =>
-            //{
-            //    string location = name + extension;
-            //    destroyMethod = DestroyMethod.None; //注意:这里一定要设置为None
-            //    if(!YooAssets.CheckDressUpResExist(location))
-            //    {
-            //        return null;
-            //    }
-            //    var handle = YooAssets.LoadAssetSync(location, type);
-            //    CacheAssetHandle(descFilePath, handle);
-            //    return handle.AssetObject;
-            //});
-
-            var uiPackage = UIPackage.AddPackage(textAsset.bytes, descFilePath, (string name, string extension, System.Type type, PackageItem item) =>
+            //同步
+            var uiPackage = UIPackage.AddPackage(textAsset.bytes, descFilePath, (string name, string extension, System.Type type, out DestroyMethod destroyMethod) =>
             {
                 string location = name + extension;
+                destroyMethod = DestroyMethod.None; //注意:这里一定要设置为None
                 if (!YooAssets.CheckResExist(location))
                 {
-                    return;
+                    return null;
                 }
-                AssetOperationHandle handle = YooAssets.LoadAssetAsync(location, type);
+                var handle = YooAssets.LoadAssetSync(location, type);
                 CacheAssetHandle(descFilePath, handle);
-                handle.Completed += (handle) =>
-                {
-                    if (handle.AssetObject == null) return;
-                    Texture tex = handle.AssetObject as Texture;
-                    if (tex != null)
-                    {
-                        string location = name + "!a" + extension;
-                        if (YooAssets.CheckResExist(location))
-                        {
-                            AssetOperationHandle handleAlpha = YooAssets.LoadAssetAsync(location, type);
-                            CacheAssetHandle(descFilePath, handleAlpha);
-                            handleAlpha.Completed += (handle1) =>
-                            {
-                                if (handle1.AssetObject == null) return;
-                                Texture alphaTex = handle1.AssetObject as Texture;
-                                item.owner.SetItemAsset(item, tex, alphaTex, DestroyMethod.None);//注意:这里一定要设置为None
-                            };
-                            return;
-                        }
-                    }
-                    item.owner.SetItemAsset(item, handle.AssetObject, null, DestroyMethod.None);//注意:这里一定要设置为None
-                };
+                return handle.AssetObject;
             });
+            //异步
+            //var uiPackage = UIPackage.AddPackage(textAsset.bytes, descFilePath, (string name, string extension, System.Type type, PackageItem item) =>
+            //{
+            //    string location = name + extension;
+            //    if (!YooAssets.CheckResExist(location))
+            //    {
+            //        return;
+            //    }
+            //    AssetOperationHandle handle = YooAssets.LoadAssetAsync(location, type);
+            //    CacheAssetHandle(descFilePath, handle);
+            //    handle.Completed += (handle) =>
+            //    {
+            //        if (handle.AssetObject == null) return;
+            //        Texture tex = handle.AssetObject as Texture;
+            //        if (tex != null)
+            //        {
+            //            string location = name + "!a" + extension;
+            //            if (YooAssets.CheckResExist(location))
+            //            {
+            //                AssetOperationHandle handleAlpha = YooAssets.LoadAssetAsync(location, type);
+            //                CacheAssetHandle(descFilePath, handleAlpha);
+            //                handleAlpha.Completed += (handle1) =>
+            //                {
+            //                    if (handle1.AssetObject == null) return;
+            //                    Texture alphaTex = handle1.AssetObject as Texture;
+            //                    item.owner.SetItemAsset(item, tex, alphaTex, DestroyMethod.None);//注意:这里一定要设置为None
+            //                };
+            //                return;
+            //            }
+            //        }
+            //        item.owner.SetItemAsset(item, handle.AssetObject, null, DestroyMethod.None);//注意:这里一定要设置为None
+            //    };
+            //});
             _packages.Add(descFilePath, uiPackage);
         }
 

+ 5 - 0
GameClient/Assets/Game/Launcher/FairyGUI/GFGGLoader.cs

@@ -14,8 +14,12 @@ namespace GFGGame
             {
                 return;
             }
+            //异步
             handle = YooAssets.LoadAssetAsync<Texture2D>(this.url);
             handle.Completed += Handle_Completed;
+            //同步
+            //handle = YooAssets.LoadAssetSync<Texture2D>(this.url);
+            //Handle_Completed(handle);
         }
 
         protected override void FreeExternal(NTexture texture)
@@ -24,6 +28,7 @@ namespace GFGGame
             if(handle != null)
             {
                 handle.Release();
+                handle = null;
             }
         }
         void Handle_Completed(AssetOperationHandle handle)