using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
namespace YooAsset
{
public static partial class YooAssets
{
private static ResourcePackage _defaultPackage;
///
/// 设置默认的资源包
///
public static void SetDefaultPackage(ResourcePackage package)
{
_defaultPackage = package;
}
#region 资源信息
///
/// 是否需要从远端更新下载
///
/// 资源的定位地址
public static bool IsNeedDownloadFromRemote(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.IsNeedDownloadFromRemote(location);
}
///
/// 是否需要从远端更新下载
///
/// 资源的定位地址
public static bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.IsNeedDownloadFromRemote(assetInfo);
}
///
/// 获取资源信息列表
///
/// 资源标签
public static AssetInfo[] GetAssetInfos(string tag)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfos(tag);
}
///
/// 获取资源信息列表
///
/// 资源标签列表
public static AssetInfo[] GetAssetInfos(string[] tags)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfos(tags);
}
///
/// 获取资源信息
///
/// 资源的定位地址
public static AssetInfo GetAssetInfo(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfo(location);
}
///
/// 获取资源信息
///
/// 资源的定位地址
/// 资源类型
public static AssetInfo GetAssetInfo(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfo(location, type);
}
///
/// 获取资源信息
///
/// 资源GUID
public static AssetInfo GetAssetInfoByGUID(string assetGUID)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfoByGUID(assetGUID);
}
///
/// 获取资源信息
///
/// 资源GUID
/// 资源类型
public static AssetInfo GetAssetInfoByGUID(string assetGUID, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfoByGUID(assetGUID, type);
}
///
/// 检查资源定位地址是否有效
///
/// 资源的定位地址
public static bool CheckLocationValid(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CheckLocationValid(location);
}
#endregion
#region 原生文件
///
/// 同步加载原生文件
///
/// 资源信息
public static RawFileHandle LoadRawFileSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileSync(assetInfo);
}
///
/// 同步加载原生文件
///
/// 资源的定位地址
public static RawFileHandle LoadRawFileSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileSync(location);
}
///
/// 异步加载原生文件
///
/// 资源信息
public static RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(assetInfo, priority);
}
///
/// 异步加载原生文件
///
/// 资源的定位地址
public static RawFileHandle LoadRawFileAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(location, priority);
}
#endregion
#region 场景加载
///
/// 同步加载场景
///
/// 场景的定位地址
/// 场景加载模式
/// 场景物理模式
public static SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneSync(location, sceneMode, physicsMode);
}
///
/// 同步加载场景
///
/// 场景的资源信息
/// 场景加载模式
/// 场景物理模式
public static SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneSync(assetInfo, sceneMode, physicsMode);
}
///
/// 异步加载场景
///
/// 场景的定位地址
/// 场景加载模式
/// 场景物理模式
/// 场景加载到90%自动挂起
/// 优先级
public static SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 100)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(location, sceneMode, physicsMode, suspendLoad, priority);
}
///
/// 异步加载场景
///
/// 场景的资源信息
/// 场景加载模式
/// 场景物理模式
/// 场景加载到90%自动挂起
/// 优先级
public static SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 100)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, physicsMode, suspendLoad, priority);
}
#endregion
#region 资源加载
///
/// 同步加载资源对象
///
/// 资源信息
public static AssetHandle LoadAssetSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(assetInfo);
}
///
/// 同步加载资源对象
///
/// 资源类型
/// 资源的定位地址
public static AssetHandle LoadAssetSync(string location) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(location);
}
///
/// 同步加载资源对象
///
/// 资源的定位地址
/// 资源类型
public static AssetHandle LoadAssetSync(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(location, type);
}
///
/// 同步加载资源对象
///
/// 资源的定位地址
public static AssetHandle LoadAssetSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(location);
}
///
/// 异步加载资源对象
///
/// 资源信息
public static AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(assetInfo, priority);
}
///
/// 异步加载资源对象
///
/// 资源类型
/// 资源的定位地址
public static AssetHandle LoadAssetAsync(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location, priority);
}
///
/// 异步加载资源对象
///
/// 资源的定位地址
/// 资源类型
public static AssetHandle LoadAssetAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location, type, priority);
}
///
/// 异步加载资源对象
///
/// 资源的定位地址
public static AssetHandle LoadAssetAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location, priority);
}
#endregion
#region 资源加载
///
/// 同步加载子资源对象
///
/// 资源信息
public static SubAssetsHandle LoadSubAssetsSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(assetInfo);
}
///
/// 同步加载子资源对象
///
/// 资源类型
/// 资源的定位地址
public static SubAssetsHandle LoadSubAssetsSync(string location) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(location);
}
///
/// 同步加载子资源对象
///
/// 资源的定位地址
/// 子对象类型
public static SubAssetsHandle LoadSubAssetsSync(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(location, type);
}
///
/// 同步加载子资源对象
///
/// 资源的定位地址
public static SubAssetsHandle LoadSubAssetsSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(location);
}
///
/// 异步加载子资源对象
///
/// 资源信息
public static SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(assetInfo, priority);
}
///
/// 异步加载子资源对象
///
/// 资源类型
/// 资源的定位地址
public static SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location, priority);
}
///
/// 异步加载子资源对象
///
/// 资源的定位地址
/// 子对象类型
public static SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location, type, priority);
}
///
/// 异步加载子资源对象
///
/// 资源的定位地址
public static SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location, priority);
}
#endregion
#region 资源加载
///
/// 同步加载资源包内所有资源对象
///
/// 资源信息
public static AllAssetsHandle LoadAllAssetsSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync(assetInfo);
}
///
/// 同步加载资源包内所有资源对象
///
/// 资源类型
/// 资源的定位地址
public static AllAssetsHandle LoadAllAssetsSync(string location) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync(location);
}
///
/// 同步加载资源包内所有资源对象
///
/// 资源的定位地址
/// 子对象类型
public static AllAssetsHandle LoadAllAssetsSync(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync(location, type);
}
///
/// 同步加载资源包内所有资源对象
///
/// 资源的定位地址
public static AllAssetsHandle LoadAllAssetsSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync(location);
}
///
/// 异步加载资源包内所有资源对象
///
/// 资源信息
public static AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(assetInfo, priority);
}
///
/// 异步加载资源包内所有资源对象
///
/// 资源类型
/// 资源的定位地址
public static AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(location, priority);
}
///
/// 异步加载资源包内所有资源对象
///
/// 资源的定位地址
/// 子对象类型
public static AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(location, type, priority);
}
///
/// 异步加载资源包内所有资源对象
///
/// 资源的定位地址
public static AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(location, priority);
}
#endregion
#region 资源下载
///
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
///
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceDownloader(downloadingMaxNumber, failedTryAgain);
}
///
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
///
/// 资源标签
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain);
}
///
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
///
/// 资源标签列表
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceDownloader(tags, downloadingMaxNumber, failedTryAgain);
}
///
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
///
/// 资源定位地址
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(location, downloadingMaxNumber, failedTryAgain);
}
///
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
///
/// 资源定位地址列表
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(locations, downloadingMaxNumber, failedTryAgain);
}
///
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
///
/// 资源信息
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(assetInfo, downloadingMaxNumber, failedTryAgain);
}
///
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
///
/// 资源信息列表
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(assetInfos, downloadingMaxNumber, failedTryAgain);
}
#endregion
#region 资源解压
///
/// 创建内置资源解压器,用于解压当前资源版本所有的资源包文件
///
/// 同时解压的最大文件数
/// 解压失败的重试次数
public static ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceUnpacker(unpackingMaxNumber, failedTryAgain);
}
///
/// 创建内置资源解压器,用于解压指定的资源标签关联的资源包文件
///
/// 资源标签
/// 同时解压的最大文件数
/// 解压失败的重试次数
public static ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceUnpacker(tag, unpackingMaxNumber, failedTryAgain);
}
///
/// 创建内置资源解压器,用于解压指定的资源标签列表关联的资源包文件
///
/// 资源标签列表
/// 同时解压的最大文件数
/// 解压失败的重试次数
public static ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceUnpacker(tags, unpackingMaxNumber, failedTryAgain);
}
#endregion
#region 资源导入
///
/// 创建资源导入器
/// 注意:资源文件名称必须和资源服务器部署的文件名称一致!
///
/// 资源路径列表
/// 同时导入的最大文件数
/// 导入失败的重试次数
public static ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceImporter(filePaths, importerMaxNumber, failedTryAgain);
}
#endregion
#region 调试方法
[Conditional("DEBUG")]
private static void DebugCheckDefaultPackageValid()
{
if (_defaultPackage == null)
throw new Exception($"Default package is null. Please use {nameof(YooAssets.SetDefaultPackage)} !");
}
#endregion
}
}