|
|
@@ -44,7 +44,7 @@ namespace GFGGame
|
|
|
// _packages.Add(descFilePath, uiPackage);
|
|
|
// }
|
|
|
|
|
|
- public static async Task AddPackageAsync(string descFilePath)
|
|
|
+ public static void AddPackage(string descFilePath, Action onComplete = null, Action<string> onError = null)
|
|
|
{
|
|
|
// 打印开始加载信息
|
|
|
Debug.Log($"开始加载UI包: {descFilePath}");
|
|
|
@@ -54,108 +54,104 @@ namespace GFGGame
|
|
|
{
|
|
|
_assetCount[descFilePath] = count + 1;
|
|
|
Debug.Log($"{descFilePath} 已引用,引用计数+1 (当前: {count + 1})");
|
|
|
+ onComplete?.Invoke();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
_assetCount.Add(descFilePath, count + 1);
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- // 加载主资源
|
|
|
- Debug.Log($"正在加载描述文件: {descFilePath}_fui.bytes");
|
|
|
- var handle = YooAssets.LoadAssetAsync<TextAsset>($"{descFilePath}_fui.bytes");
|
|
|
- await handle.Task;
|
|
|
+ // 加载主资源
|
|
|
+ Debug.Log($"正在加载描述文件: {descFilePath}_fui.bytes");
|
|
|
+ var handle = YooAssets.LoadAssetAsync<TextAsset>($"{descFilePath}_fui.bytes");
|
|
|
|
|
|
- if (handle.Status == EOperationStatus.Succeed)
|
|
|
+ handle.Completed += (mainHandle) =>
|
|
|
+ {
|
|
|
+ if (mainHandle.Status != EOperationStatus.Succeed)
|
|
|
{
|
|
|
- Debug.Log($"描述文件加载成功: {descFilePath}_fui.bytes");
|
|
|
- TextAsset textAsset = handle.AssetObject as TextAsset;
|
|
|
- CacheAssetHandle(descFilePath, handle);
|
|
|
-
|
|
|
- // 添加UI包
|
|
|
- Debug.Log($"正在添加UI包: {descFilePath}");
|
|
|
- var uiPackage = UIPackage.AddPackage(textAsset.bytes, descFilePath,
|
|
|
- (string name, string extension, System.Type type, PackageItem item) =>
|
|
|
+ string error = $"描述文件加载失败: {descFilePath}_fui.bytes, 错误: {mainHandle.LastError}";
|
|
|
+ Debug.LogError(error);
|
|
|
+ onError?.Invoke(error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log($"描述文件加载成功: {descFilePath}_fui.bytes");
|
|
|
+ TextAsset textAsset = mainHandle.AssetObject as TextAsset;
|
|
|
+ CacheAssetHandle(descFilePath, mainHandle);
|
|
|
+
|
|
|
+ // 添加UI包
|
|
|
+ Debug.Log($"正在添加UI包: {descFilePath}");
|
|
|
+ var uiPackage = UIPackage.AddPackage(textAsset.bytes, descFilePath,
|
|
|
+ (string name, string extension, System.Type type, PackageItem item) =>
|
|
|
+ {
|
|
|
+ string location = name + extension;
|
|
|
+ Debug.Log($"正在加载依赖资源: {location}");
|
|
|
+
|
|
|
+ if (!YooAssets.CheckResExist(location))
|
|
|
{
|
|
|
- string location = name + extension;
|
|
|
- Debug.Log($"正在加载依赖资源: {location}");
|
|
|
+ Debug.LogWarning($"依赖资源不存在: {location}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (!YooAssets.CheckResExist(location))
|
|
|
+ AssetOperationHandle depHandle = YooAssets.LoadAssetAsync(location, type);
|
|
|
+ CacheAssetHandle(descFilePath, depHandle);
|
|
|
+ depHandle.Completed += (depHandle) =>
|
|
|
+ {
|
|
|
+ if (depHandle.Status != EOperationStatus.Succeed)
|
|
|
{
|
|
|
- Debug.LogWarning($"依赖资源不存在: {location}");
|
|
|
+ Debug.LogError($"依赖资源加载失败: {location}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- AssetOperationHandle handle = YooAssets.LoadAssetAsync(location, type);
|
|
|
- CacheAssetHandle(descFilePath, handle);
|
|
|
- handle.Completed += (handle) =>
|
|
|
+ if (depHandle.AssetObject == null)
|
|
|
{
|
|
|
- if (handle.Status != EOperationStatus.Succeed)
|
|
|
- {
|
|
|
- Debug.LogError($"依赖资源加载失败: {location}");
|
|
|
- return;
|
|
|
- }
|
|
|
+ Debug.LogWarning($"依赖资源为空: {location}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (handle.AssetObject == null)
|
|
|
- {
|
|
|
- Debug.LogWarning($"依赖资源为空: {location}");
|
|
|
- return;
|
|
|
- }
|
|
|
+ Debug.Log($"依赖资源加载成功: {location}");
|
|
|
+ Texture tex = depHandle.AssetObject as Texture;
|
|
|
+ if (tex != null)
|
|
|
+ {
|
|
|
+ string alphaLocation = name + "!a" + extension;
|
|
|
+ Debug.Log($"检测透明通道资源: {alphaLocation}");
|
|
|
|
|
|
- Debug.Log($"依赖资源加载成功: {location}");
|
|
|
- Texture tex = handle.AssetObject as Texture;
|
|
|
- if (tex != null)
|
|
|
+ if (YooAssets.CheckResExist(alphaLocation))
|
|
|
{
|
|
|
- string location = name + "!a" + extension;
|
|
|
- Debug.Log($"检测透明通道资源: {location}");
|
|
|
-
|
|
|
- if (YooAssets.CheckResExist(location))
|
|
|
+ AssetOperationHandle alphaHandle = YooAssets.LoadAssetAsync(alphaLocation, type);
|
|
|
+ CacheAssetHandle(descFilePath, alphaHandle);
|
|
|
+ alphaHandle.Completed += (alphaHandle) =>
|
|
|
{
|
|
|
- AssetOperationHandle handleAlpha = YooAssets.LoadAssetAsync(location, type);
|
|
|
- CacheAssetHandle(descFilePath, handleAlpha);
|
|
|
- handleAlpha.Completed += (handle1) =>
|
|
|
+ if (alphaHandle.Status != EOperationStatus.Succeed)
|
|
|
+ {
|
|
|
+ Debug.LogError($"透明通道资源加载失败: {alphaLocation}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (alphaHandle.AssetObject == null)
|
|
|
{
|
|
|
- if (handle1.Status != EOperationStatus.Succeed)
|
|
|
- {
|
|
|
- Debug.LogError($"透明通道资源加载失败: {location}");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (handle1.AssetObject == null)
|
|
|
- {
|
|
|
- Debug.LogWarning($"透明通道资源为空: {location}");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Debug.Log($"透明通道资源加载成功: {location}");
|
|
|
- Texture alphaTex = handle1.AssetObject as Texture;
|
|
|
- item.owner.SetItemAsset(item, tex, alphaTex, DestroyMethod.None);
|
|
|
- };
|
|
|
- return;
|
|
|
- }
|
|
|
+ Debug.LogWarning($"透明通道资源为空: {alphaLocation}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Debug.Log($"透明通道资源加载成功: {alphaLocation}");
|
|
|
+ Texture alphaTex = alphaHandle.AssetObject as Texture;
|
|
|
+ item.owner.SetItemAsset(item, tex, alphaTex, DestroyMethod.None);
|
|
|
+ };
|
|
|
+ return;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- item.owner.SetItemAsset(item, handle.AssetObject, null, DestroyMethod.None);
|
|
|
- };
|
|
|
- });
|
|
|
+ item.owner.SetItemAsset(item, depHandle.AssetObject, null, DestroyMethod.None);
|
|
|
+ };
|
|
|
+ });
|
|
|
|
|
|
- _packages.Add(descFilePath, uiPackage);
|
|
|
- Debug.Log($"UI包添加完成: {descFilePath}");
|
|
|
- CheckRemovePackage(descFilePath);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Debug.LogError($"描述文件加载失败: {descFilePath}_fui.bytes, 错误: {handle.LastError}");
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Debug.LogError($"加载UI包异常: {descFilePath}, 错误: {ex.Message}");
|
|
|
- throw;
|
|
|
- }
|
|
|
+ _packages.Add(descFilePath, uiPackage);
|
|
|
+ Debug.Log($"UI包添加完成: {descFilePath}");
|
|
|
+ CheckRemovePackage(descFilePath);
|
|
|
+ onComplete?.Invoke();
|
|
|
+ };
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
public static void ReleasePackage(string descFilePath)
|
|
|
{
|
|
|
_assetCount.TryGetValue(descFilePath, out var count);
|