Update runtime code

pull/51/head
hevinci 2022-10-14 11:49:32 +08:00
parent e9af0c7042
commit bd8ecab31b
7 changed files with 94 additions and 121 deletions

View File

@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
namespace YooAsset namespace YooAsset
{ {
public class YooAssetPackage public class AssetsPackage
{ {
private bool _isInitialize = false; private bool _isInitialize = false;
private string _initializeError = string.Empty; private string _initializeError = string.Empty;
@ -33,13 +33,10 @@ namespace YooAsset
} }
/// <summary> internal AssetsPackage()
/// 拒绝外部实例化
/// </summary>
internal YooAssetPackage()
{ {
} }
internal YooAssetPackage(string packageName) internal AssetsPackage(string packageName)
{ {
PackageName = packageName; PackageName = packageName;
} }
@ -136,10 +133,10 @@ namespace YooAsset
private void CheckInitializeParameters(InitializeParameters parameters) private void CheckInitializeParameters(InitializeParameters parameters)
{ {
if (_isInitialize) if (_isInitialize)
throw new Exception($"{nameof(YooAssetPackage)} is initialized yet."); throw new Exception($"{nameof(AssetsPackage)} is initialized yet.");
if (parameters == null) if (parameters == null)
throw new Exception($"{nameof(YooAssetPackage)} create parameters is null."); throw new Exception($"{nameof(AssetsPackage)} create parameters is null.");
#if !UNITY_EDITOR #if !UNITY_EDITOR
if (parameters is EditorSimulateModeParameters) if (parameters is EditorSimulateModeParameters)

View File

@ -6,6 +6,6 @@ namespace YooAsset
/// <summary> /// <summary>
/// 定位地址转换为资源路径 /// 定位地址转换为资源路径
/// </summary> /// </summary>
string ConvertLocationToAssetPath(YooAssetPackage package, string location); string ConvertLocationToAssetPath(AssetsPackage package, string location);
} }
} }

View File

@ -3,7 +3,7 @@ namespace YooAsset
{ {
public class AddressLocationServices : ILocationServices public class AddressLocationServices : ILocationServices
{ {
string ILocationServices.ConvertLocationToAssetPath(YooAssetPackage package, string location) string ILocationServices.ConvertLocationToAssetPath(AssetsPackage package, string location)
{ {
return package.MappingToAssetPath(location); return package.MappingToAssetPath(location);
} }

View File

@ -11,7 +11,7 @@ namespace YooAsset
_resourceRoot = PathHelper.GetRegularPath(resourceRoot); _resourceRoot = PathHelper.GetRegularPath(resourceRoot);
} }
string ILocationServices.ConvertLocationToAssetPath(YooAssetPackage package, string location) string ILocationServices.ConvertLocationToAssetPath(AssetsPackage package, string location)
{ {
if (string.IsNullOrEmpty(_resourceRoot)) if (string.IsNullOrEmpty(_resourceRoot))
{ {

View File

@ -9,7 +9,7 @@ namespace YooAsset
public static partial class YooAssets public static partial class YooAssets
{ {
private static bool _isInitialize = false; private static bool _isInitialize = false;
private static readonly List<YooAssetPackage> _packages = new List<YooAssetPackage>(); private static readonly List<AssetsPackage> _packages = new List<AssetsPackage>();
/// <summary> /// <summary>
/// 初始化资源系统 /// 初始化资源系统
@ -81,27 +81,27 @@ namespace YooAsset
/// 创建资源包 /// 创建资源包
/// </summary> /// </summary>
/// <param name="packageName">资源包名称</param> /// <param name="packageName">资源包名称</param>
public static YooAssetPackage CreateAssetPackage(string packageName) public static AssetsPackage CreateAssetsPackage(string packageName)
{ {
if (_isInitialize == false) if (_isInitialize == false)
throw new Exception($"{nameof(YooAssets)} not initialize !"); throw new Exception($"{nameof(YooAssets)} not initialize !");
if (string.IsNullOrEmpty(packageName)) if (string.IsNullOrEmpty(packageName))
throw new Exception("PackageName is null or empty !"); throw new Exception("Package name is null or empty !");
if (HasAssetPackage(packageName)) if (HasAssetsPackage(packageName))
throw new Exception($"Package {packageName} already existed !"); throw new Exception($"Package {packageName} already existed !");
YooAssetPackage component = new YooAssetPackage(packageName); AssetsPackage assetsPackage = new AssetsPackage(packageName);
_packages.Add(component); _packages.Add(assetsPackage);
return component; return assetsPackage;
} }
/// <summary> /// <summary>
/// 获取资源包 /// 获取资源包
/// </summary> /// </summary>
/// <param name="packageName">资源包名称</param> /// <param name="packageName">资源包名称</param>
public static YooAssetPackage GetAssetPackage(string packageName) public static AssetsPackage GetAssetsPackage(string packageName)
{ {
if (_isInitialize == false) if (_isInitialize == false)
throw new Exception($"{nameof(YooAssets)} not initialize !"); throw new Exception($"{nameof(YooAssets)} not initialize !");
@ -115,7 +115,7 @@ namespace YooAsset
return package; return package;
} }
YooLogger.Warning($"Not found asset package : {packageName}"); YooLogger.Warning($"Not found assets package : {packageName}");
return null; return null;
} }
@ -123,7 +123,7 @@ namespace YooAsset
/// 检测资源包是否存在 /// 检测资源包是否存在
/// </summary> /// </summary>
/// <param name="packageName">资源包名称</param> /// <param name="packageName">资源包名称</param>
public static bool HasAssetPackage(string packageName) public static bool HasAssetsPackage(string packageName)
{ {
if (_isInitialize == false) if (_isInitialize == false)
throw new Exception($"{nameof(YooAssets)} not initialize !"); throw new Exception($"{nameof(YooAssets)} not initialize !");
@ -135,7 +135,7 @@ namespace YooAsset
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 开启一个异步操作 /// 开启一个异步操作
/// </summary> /// </summary>

View File

@ -8,80 +8,16 @@ namespace YooAsset
{ {
public static partial class YooAssets public static partial class YooAssets
{ {
private static YooAssetPackage _mainPackage; private static AssetsPackage _defaultPackage;
/// <summary> /// <summary>
/// 初始化状态 /// 设置默认的资源包
/// </summary> /// </summary>
public static EOperationStatus InitializeStatus public static void SetDefaultAssetsPackage(AssetsPackage assetsPackage)
{ {
get _defaultPackage = assetsPackage;
{
if (_mainPackage == null)
return EOperationStatus.None;
return _mainPackage.InitializeStatus;
}
} }
/// <summary>
/// 异步初始化
/// </summary>
public static InitializationOperation InitializeAsync(InitializeParameters parameters, string packageName = "DefaultPackage")
{
if (_mainPackage != null)
throw new Exception("Main package is initialized yet.");
_mainPackage = CreateAssetPackage(packageName);
return _mainPackage.InitializeAsync(parameters);
}
/// <summary>
/// 向网络端请求静态资源版本
/// </summary>
/// <param name="timeout">超时时间默认值60秒</param>
public static UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60)
{
return _mainPackage.UpdateStaticVersionAsync(timeout);
}
/// <summary>
/// 向网络端请求并更新补丁清单
/// </summary>
/// <param name="packageCRC">更新的资源包裹版本</param>
/// <param name="timeout">超时时间默认值60秒</param>
public static UpdateManifestOperation UpdateManifestAsync(string packageCRC, int timeout = 60)
{
return _mainPackage.UpdateManifestAsync(packageCRC, timeout);
}
/// <summary>
/// 弱联网情况下加载补丁清单
/// 注意:当指定版本内容验证失败后会返回失败。
/// </summary>
/// <param name="packageCRC">指定的资源包裹版本</param>
public static UpdateManifestOperation WeaklyUpdateManifestAsync(string packageCRC)
{
return _mainPackage.WeaklyUpdateManifestAsync(packageCRC);
}
/// <summary>
/// 资源回收(卸载引用计数为零的资源)
/// </summary>
public static void UnloadUnusedAssets()
{
_mainPackage.UnloadUnusedAssets();
}
/// <summary>
/// 强制回收所有资源
/// </summary>
public static void ForceUnloadAllAssets()
{
_mainPackage.ForceUnloadAllAssets();
}
#region 资源信息 #region 资源信息
/// <summary> /// <summary>
/// 是否需要从远端更新下载 /// 是否需要从远端更新下载
@ -89,7 +25,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static bool IsNeedDownloadFromRemote(string location) public static bool IsNeedDownloadFromRemote(string location)
{ {
return _mainPackage.IsNeedDownloadFromRemote(location); DebugCheckDefaultPackageValid();
return _defaultPackage.IsNeedDownloadFromRemote(location);
} }
/// <summary> /// <summary>
@ -98,7 +35,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static bool IsNeedDownloadFromRemote(AssetInfo assetInfo) public static bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
{ {
return _mainPackage.IsNeedDownloadFromRemote(assetInfo); DebugCheckDefaultPackageValid();
return _defaultPackage.IsNeedDownloadFromRemote(assetInfo);
} }
/// <summary> /// <summary>
@ -107,7 +45,8 @@ namespace YooAsset
/// <param name="tag">资源标签</param> /// <param name="tag">资源标签</param>
public static AssetInfo[] GetAssetInfos(string tag) public static AssetInfo[] GetAssetInfos(string tag)
{ {
return _mainPackage.GetAssetInfos(tag); DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfos(tag);
} }
/// <summary> /// <summary>
@ -116,7 +55,8 @@ namespace YooAsset
/// <param name="tags">资源标签列表</param> /// <param name="tags">资源标签列表</param>
public static AssetInfo[] GetAssetInfos(string[] tags) public static AssetInfo[] GetAssetInfos(string[] tags)
{ {
return _mainPackage.GetAssetInfos(tags); DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfos(tags);
} }
/// <summary> /// <summary>
@ -125,7 +65,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static AssetInfo GetAssetInfo(string location) public static AssetInfo GetAssetInfo(string location)
{ {
return _mainPackage.GetAssetInfo(location); DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfo(location);
} }
/// <summary> /// <summary>
@ -135,7 +76,8 @@ namespace YooAsset
/// <returns>如果location地址无效则返回空字符串</returns> /// <returns>如果location地址无效则返回空字符串</returns>
public static string GetAssetPath(string location) public static string GetAssetPath(string location)
{ {
return _mainPackage.GetAssetPath(location); DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetPath(location);
} }
#endregion #endregion
@ -147,7 +89,8 @@ namespace YooAsset
/// <param name="copyPath">拷贝路径</param> /// <param name="copyPath">拷贝路径</param>
public static RawFileOperation GetRawFileAsync(string location, string copyPath = null) public static RawFileOperation GetRawFileAsync(string location, string copyPath = null)
{ {
return _mainPackage.GetRawFileAsync(location, copyPath); DebugCheckDefaultPackageValid();
return _defaultPackage.GetRawFileAsync(location, copyPath);
} }
/// <summary> /// <summary>
@ -157,7 +100,8 @@ namespace YooAsset
/// <param name="copyPath">拷贝路径</param> /// <param name="copyPath">拷贝路径</param>
public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null) public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null)
{ {
return _mainPackage.GetRawFileAsync(assetInfo, copyPath); DebugCheckDefaultPackageValid();
return _defaultPackage.GetRawFileAsync(assetInfo, copyPath);
} }
#endregion #endregion
@ -171,7 +115,8 @@ namespace YooAsset
/// <param name="priority">优先级</param> /// <param name="priority">优先级</param>
public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
return _mainPackage.LoadSceneAsync(location, sceneMode, activateOnLoad, priority); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(location, sceneMode, activateOnLoad, priority);
} }
/// <summary> /// <summary>
@ -183,7 +128,8 @@ namespace YooAsset
/// <param name="priority">优先级</param> /// <param name="priority">优先级</param>
public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
return _mainPackage.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority);
} }
#endregion #endregion
@ -194,7 +140,8 @@ namespace YooAsset
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public static AssetOperationHandle LoadAssetSync(AssetInfo assetInfo) public static AssetOperationHandle LoadAssetSync(AssetInfo assetInfo)
{ {
return _mainPackage.LoadAssetSync(assetInfo); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(assetInfo);
} }
/// <summary> /// <summary>
@ -204,7 +151,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : UnityEngine.Object public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : UnityEngine.Object
{ {
return _mainPackage.LoadAssetSync<TObject>(location); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync<TObject>(location);
} }
/// <summary> /// <summary>
@ -214,7 +162,8 @@ namespace YooAsset
/// <param name="type">资源类型</param> /// <param name="type">资源类型</param>
public static AssetOperationHandle LoadAssetSync(string location, System.Type type) public static AssetOperationHandle LoadAssetSync(string location, System.Type type)
{ {
return _mainPackage.LoadAssetSync(location, type); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(location, type);
} }
@ -224,7 +173,8 @@ namespace YooAsset
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo) public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo)
{ {
return _mainPackage.LoadAssetAsync(assetInfo); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(assetInfo);
} }
/// <summary> /// <summary>
@ -234,7 +184,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static AssetOperationHandle LoadAssetAsync<TObject>(string location) where TObject : UnityEngine.Object public static AssetOperationHandle LoadAssetAsync<TObject>(string location) where TObject : UnityEngine.Object
{ {
return _mainPackage.LoadAssetAsync<TObject>(location); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync<TObject>(location);
} }
/// <summary> /// <summary>
@ -244,7 +195,8 @@ namespace YooAsset
/// <param name="type">资源类型</param> /// <param name="type">资源类型</param>
public static AssetOperationHandle LoadAssetAsync(string location, System.Type type) public static AssetOperationHandle LoadAssetAsync(string location, System.Type type)
{ {
return _mainPackage.LoadAssetAsync(location, type); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location, type);
} }
#endregion #endregion
@ -255,7 +207,8 @@ namespace YooAsset
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public static SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo) public static SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo)
{ {
return _mainPackage.LoadSubAssetsSync(assetInfo); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(assetInfo);
} }
/// <summary> /// <summary>
@ -265,7 +218,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
{ {
return _mainPackage.LoadSubAssetsSync<TObject>(location); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync<TObject>(location);
} }
/// <summary> /// <summary>
@ -275,7 +229,8 @@ namespace YooAsset
/// <param name="type">子对象类型</param> /// <param name="type">子对象类型</param>
public static SubAssetsOperationHandle LoadSubAssetsSync(string location, System.Type type) public static SubAssetsOperationHandle LoadSubAssetsSync(string location, System.Type type)
{ {
return _mainPackage.LoadSubAssetsSync(location, type); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(location, type);
} }
@ -285,7 +240,8 @@ namespace YooAsset
/// <param name="assetInfo">资源信息</param> /// <param name="assetInfo">资源信息</param>
public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo) public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo)
{ {
return _mainPackage.LoadSubAssetsAsync(assetInfo); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(assetInfo);
} }
/// <summary> /// <summary>
@ -295,7 +251,8 @@ namespace YooAsset
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
{ {
return _mainPackage.LoadSubAssetsAsync<TObject>(location); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync<TObject>(location);
} }
/// <summary> /// <summary>
@ -305,7 +262,8 @@ namespace YooAsset
/// <param name="type">子对象类型</param> /// <param name="type">子对象类型</param>
public static SubAssetsOperationHandle LoadSubAssetsAsync(string location, System.Type type) public static SubAssetsOperationHandle LoadSubAssetsAsync(string location, System.Type type)
{ {
return _mainPackage.LoadSubAssetsAsync(location, type); DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location, type);
} }
#endregion #endregion
@ -318,7 +276,8 @@ namespace YooAsset
/// <param name="failedTryAgain">下载失败的重试次数</param> /// <param name="failedTryAgain">下载失败的重试次数</param>
public static PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) public static PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain);
} }
/// <summary> /// <summary>
@ -329,7 +288,8 @@ namespace YooAsset
/// <param name="failedTryAgain">下载失败的重试次数</param> /// <param name="failedTryAgain">下载失败的重试次数</param>
public static PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) public static PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreatePatchDownloader(tags, downloadingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreatePatchDownloader(tags, downloadingMaxNumber, failedTryAgain);
} }
/// <summary> /// <summary>
@ -339,7 +299,8 @@ namespace YooAsset
/// <param name="failedTryAgain">下载失败的重试次数</param> /// <param name="failedTryAgain">下载失败的重试次数</param>
public static PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain) public static PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreatePatchDownloader(downloadingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreatePatchDownloader(downloadingMaxNumber, failedTryAgain);
} }
@ -351,7 +312,8 @@ namespace YooAsset
/// <param name="failedTryAgain">下载失败的重试次数</param> /// <param name="failedTryAgain">下载失败的重试次数</param>
public static PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) public static PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreateBundleDownloader(locations, downloadingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(locations, downloadingMaxNumber, failedTryAgain);
} }
/// <summary> /// <summary>
@ -362,7 +324,8 @@ namespace YooAsset
/// <param name="failedTryAgain">下载失败的重试次数</param> /// <param name="failedTryAgain">下载失败的重试次数</param>
public static PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain) public static PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreateBundleDownloader(assetInfos, downloadingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(assetInfos, downloadingMaxNumber, failedTryAgain);
} }
#endregion #endregion
@ -375,7 +338,8 @@ namespace YooAsset
/// <param name="failedTryAgain">解压失败的重试次数</param> /// <param name="failedTryAgain">解压失败的重试次数</param>
public static PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain) public static PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreatePatchUnpacker(tag, unpackingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreatePatchUnpacker(tag, unpackingMaxNumber, failedTryAgain);
} }
/// <summary> /// <summary>
@ -386,7 +350,8 @@ namespace YooAsset
/// <param name="failedTryAgain">解压失败的重试次数</param> /// <param name="failedTryAgain">解压失败的重试次数</param>
public static PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain) public static PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreatePatchUnpacker(tags, unpackingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreatePatchUnpacker(tags, unpackingMaxNumber, failedTryAgain);
} }
/// <summary> /// <summary>
@ -396,7 +361,8 @@ namespace YooAsset
/// <param name="failedTryAgain">解压失败的重试次数</param> /// <param name="failedTryAgain">解压失败的重试次数</param>
public static PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain) public static PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain)
{ {
return _mainPackage.CreatePatchUnpacker(unpackingMaxNumber, failedTryAgain); DebugCheckDefaultPackageValid();
return _defaultPackage.CreatePatchUnpacker(unpackingMaxNumber, failedTryAgain);
} }
#endregion #endregion
@ -408,7 +374,17 @@ namespace YooAsset
/// <param name="timeout">超时时间</param> /// <param name="timeout">超时时间</param>
public static UpdatePackageOperation UpdatePackageAsync(string packageCRC, int timeout = 60) public static UpdatePackageOperation UpdatePackageAsync(string packageCRC, int timeout = 60)
{ {
return _mainPackage.UpdatePackageAsync(packageCRC, timeout); DebugCheckDefaultPackageValid();
return _defaultPackage.UpdatePackageAsync(packageCRC, timeout);
}
#endregion
#region 调试方法
[Conditional("DEBUG")]
private static void DebugCheckDefaultPackageValid()
{
if (_defaultPackage == null)
throw new Exception($"Default package is null. Please use {nameof(YooAssets.SetDefaultAssetsPackage)} !");
} }
#endregion #endregion
} }