From d5a4b3365f15f529d92547fa1aa58ab7e8b616f7 Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 20 Jul 2022 10:57:56 +0800 Subject: [PATCH] Update YooAssets.cs --- Assets/YooAsset/Runtime/YooAssets.cs | 84 ++++++++++++++++------------ 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 0fa3b4e..b7dc14c 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -404,10 +404,7 @@ namespace YooAsset DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); if (assetInfo.IsInvalid) - { - YooLogger.Warning(assetInfo.Error); return false; - } BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) @@ -469,38 +466,7 @@ namespace YooAsset } #endregion - #region 场景加载 - /// - /// 异步加载场景 - /// - /// 场景的定位地址 - /// 场景加载模式 - /// 加载完毕时是否主动激活 - /// 优先级 - public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) - { - DebugCheckInitialize(); - AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); - return handle; - } - - /// - /// 异步加载场景 - /// - /// 场景的资源信息 - /// 场景加载模式 - /// 加载完毕时是否主动激活 - /// 优先级 - public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) - { - DebugCheckInitialize(); - var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); - return handle; - } - #endregion - - #region 资源加载 + #region 原生文件 /// /// 异步获取原生文件 /// @@ -521,6 +487,8 @@ namespace YooAsset public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null) { DebugCheckInitialize(); + if (assetInfo.IsInvalid) + YooLogger.Warning(assetInfo.Error); return GetRawFileInternal(assetInfo, copyPath); } @@ -529,7 +497,6 @@ namespace YooAsset { if (assetInfo.IsInvalid) { - YooLogger.Warning(assetInfo.Error); RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath); OperationSystem.StartOperaiton(operation); return operation; @@ -570,6 +537,39 @@ namespace YooAsset } #endregion + #region 场景加载 + /// + /// 异步加载场景 + /// + /// 场景的定位地址 + /// 场景加载模式 + /// 加载完毕时是否主动激活 + /// 优先级 + public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) + { + DebugCheckInitialize(); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); + return handle; + } + + /// + /// 异步加载场景 + /// + /// 场景的资源信息 + /// 场景加载模式 + /// 加载完毕时是否主动激活 + /// 优先级 + public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) + { + DebugCheckInitialize(); + if (assetInfo.IsInvalid) + YooLogger.Warning(assetInfo.Error); + var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); + return handle; + } + #endregion + #region 资源加载 /// /// 同步加载资源对象 @@ -578,6 +578,8 @@ namespace YooAsset public static AssetOperationHandle LoadAssetSync(AssetInfo assetInfo) { DebugCheckInitialize(); + if (assetInfo.IsInvalid) + YooLogger.Warning(assetInfo.Error); return LoadAssetInternal(assetInfo, true); } @@ -613,6 +615,8 @@ namespace YooAsset public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo) { DebugCheckInitialize(); + if (assetInfo.IsInvalid) + YooLogger.Warning(assetInfo.Error); return LoadAssetInternal(assetInfo, false); } @@ -658,6 +662,8 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo) { DebugCheckInitialize(); + if (assetInfo.IsInvalid) + YooLogger.Warning(assetInfo.Error); return LoadSubAssetsInternal(assetInfo, true); } @@ -693,6 +699,8 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo) { DebugCheckInitialize(); + if (assetInfo.IsInvalid) + YooLogger.Warning(assetInfo.Error); return LoadSubAssetsInternal(assetInfo, false); } @@ -1056,6 +1064,10 @@ namespace YooAsset #endregion #region 私有方法 + /// + /// 资源定位地址转换为资源信息类,失败时内部会发出错误日志。 + /// + /// 如果转换失败会返回一个无效的资源信息类 private static AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType) { DebugCheckLocation(location);