2022-09-28 14:39:58 +08:00
using System ;
using System.Diagnostics ;
using System.Collections ;
using System.Collections.Generic ;
using UnityEngine.SceneManagement ;
namespace YooAsset
{
2023-03-11 00:06:40 +08:00
public class ResourcePackage
2022-09-28 14:39:58 +08:00
{
private bool _isInitialize = false ;
private string _initializeError = string . Empty ;
private EOperationStatus _initializeStatus = EOperationStatus . None ;
private EPlayMode _playMode ;
private IBundleServices _bundleServices ;
2022-12-17 22:37:39 +08:00
private IPlayModeServices _playModeServices ;
2022-09-29 18:40:43 +08:00
private AssetSystemImpl _assetSystemImpl ;
2022-09-28 14:39:58 +08:00
2022-09-29 18:40:43 +08:00
/// <summary>
/// 包裹名
/// </summary>
public string PackageName { private set ; get ; }
2022-09-28 14:39:58 +08:00
/// <summary>
2022-10-12 15:01:39 +08:00
/// 初始化状态
2022-09-28 14:39:58 +08:00
/// </summary>
2022-10-12 15:01:39 +08:00
public EOperationStatus InitializeStatus
2022-09-28 14:39:58 +08:00
{
2022-10-12 15:01:39 +08:00
get { return _initializeStatus ; }
2022-09-28 14:39:58 +08:00
}
2022-09-29 18:40:43 +08:00
2023-03-11 00:06:40 +08:00
private ResourcePackage ( )
2022-09-28 14:39:58 +08:00
{
2022-09-29 18:40:43 +08:00
}
2023-03-11 00:06:40 +08:00
internal ResourcePackage ( string packageName )
2022-09-29 18:40:43 +08:00
{
PackageName = packageName ;
}
2022-09-28 14:39:58 +08:00
2022-09-29 18:40:43 +08:00
/// <summary>
/// 更新资源包裹
/// </summary>
internal void UpdatePackage ( )
{
if ( _assetSystemImpl ! = null )
_assetSystemImpl . Update ( ) ;
}
2022-09-28 14:39:58 +08:00
2022-09-29 18:40:43 +08:00
/// <summary>
/// 销毁资源包裹
/// </summary>
internal void DestroyPackage ( )
{
2022-09-28 14:39:58 +08:00
if ( _isInitialize )
{
2022-09-29 18:40:43 +08:00
_isInitialize = false ;
_initializeError = string . Empty ;
_initializeStatus = EOperationStatus . None ;
_bundleServices = null ;
2022-12-17 22:37:39 +08:00
_playModeServices = null ;
2022-09-28 14:39:58 +08:00
2022-09-29 18:40:43 +08:00
if ( _assetSystemImpl ! = null )
{
2023-07-12 20:56:11 +08:00
_assetSystemImpl . ForceUnloadAllAssets ( ) ;
2022-09-29 18:40:43 +08:00
_assetSystemImpl = null ;
}
2022-09-28 14:39:58 +08:00
}
2022-09-29 18:40:43 +08:00
}
2022-09-28 14:39:58 +08:00
2022-09-29 18:40:43 +08:00
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync ( InitializeParameters parameters )
{
2022-11-29 11:06:24 +08:00
// 注意: WebGL平台因为网络原因可能会初始化失败!
ResetInitializeAfterFailed ( ) ;
2022-09-29 18:40:43 +08:00
// 检测初始化参数合法性
CheckInitializeParameters ( parameters ) ;
2022-09-28 14:39:58 +08:00
2023-07-05 14:56:18 +08:00
// 重写持久化根目录
var persistent = PersistentTools . GetOrCreatePersistent ( PackageName ) ;
persistent . OverwriteRootDirectory ( parameters . BuildinRootDirectory , parameters . SandboxRootDirectory ) ;
2022-09-28 14:39:58 +08:00
// 初始化资源系统
InitializationOperation initializeOperation ;
2022-09-29 18:40:43 +08:00
_assetSystemImpl = new AssetSystemImpl ( ) ;
2022-09-28 14:39:58 +08:00
if ( _playMode = = EPlayMode . EditorSimulateMode )
{
2022-12-17 22:37:39 +08:00
var editorSimulateModeImpl = new EditorSimulateModeImpl ( ) ;
_bundleServices = editorSimulateModeImpl ;
_playModeServices = editorSimulateModeImpl ;
2023-03-22 17:14:58 +08:00
_assetSystemImpl . Initialize ( PackageName , true ,
2023-03-24 17:01:35 +08:00
parameters . LoadingMaxTimeSlice , parameters . DownloadFailedTryAgain ,
2023-03-22 17:14:58 +08:00
parameters . DecryptionServices , _bundleServices ) ;
2022-12-17 22:37:39 +08:00
2022-09-29 18:40:43 +08:00
var initializeParameters = parameters as EditorSimulateModeParameters ;
2023-06-26 18:30:29 +08:00
initializeOperation = editorSimulateModeImpl . InitializeAsync ( initializeParameters . SimulateManifestFilePath ) ;
2022-09-28 14:39:58 +08:00
}
else if ( _playMode = = EPlayMode . OfflinePlayMode )
{
2022-12-17 22:37:39 +08:00
var offlinePlayModeImpl = new OfflinePlayModeImpl ( ) ;
_bundleServices = offlinePlayModeImpl ;
_playModeServices = offlinePlayModeImpl ;
2023-03-22 17:14:58 +08:00
_assetSystemImpl . Initialize ( PackageName , false ,
2023-03-24 17:01:35 +08:00
parameters . LoadingMaxTimeSlice , parameters . DownloadFailedTryAgain ,
2023-03-22 17:14:58 +08:00
parameters . DecryptionServices , _bundleServices ) ;
2022-12-17 22:37:39 +08:00
2022-09-29 18:40:43 +08:00
var initializeParameters = parameters as OfflinePlayModeParameters ;
2023-06-26 18:30:29 +08:00
initializeOperation = offlinePlayModeImpl . InitializeAsync ( PackageName ) ;
2022-09-28 14:39:58 +08:00
}
else if ( _playMode = = EPlayMode . HostPlayMode )
{
2022-12-17 22:37:39 +08:00
var hostPlayModeImpl = new HostPlayModeImpl ( ) ;
_bundleServices = hostPlayModeImpl ;
_playModeServices = hostPlayModeImpl ;
2023-03-22 17:14:58 +08:00
_assetSystemImpl . Initialize ( PackageName , false ,
2023-03-24 17:01:35 +08:00
parameters . LoadingMaxTimeSlice , parameters . DownloadFailedTryAgain ,
2023-03-22 17:14:58 +08:00
parameters . DecryptionServices , _bundleServices ) ;
2022-12-17 22:37:39 +08:00
2022-09-29 18:40:43 +08:00
var initializeParameters = parameters as HostPlayModeParameters ;
2022-12-17 22:37:39 +08:00
initializeOperation = hostPlayModeImpl . InitializeAsync (
PackageName ,
2023-07-12 19:15:10 +08:00
initializeParameters . QueryServices ,
initializeParameters . RemoteServices
2022-12-17 22:37:39 +08:00
) ;
2022-09-28 14:39:58 +08:00
}
2023-07-18 14:27:33 +08:00
else if ( _playMode = = EPlayMode . WebPlayMode )
{
var webPlayModeImpl = new WebPlayModeImpl ( ) ;
_bundleServices = webPlayModeImpl ;
_playModeServices = webPlayModeImpl ;
_assetSystemImpl . Initialize ( PackageName , false ,
parameters . LoadingMaxTimeSlice , parameters . DownloadFailedTryAgain ,
parameters . DecryptionServices , _bundleServices ) ;
var initializeParameters = parameters as WebPlayModeParameters ;
initializeOperation = webPlayModeImpl . InitializeAsync (
PackageName ,
initializeParameters . QueryServices ,
initializeParameters . RemoteServices
) ;
}
2022-09-28 14:39:58 +08:00
else
{
throw new NotImplementedException ( ) ;
}
// 监听初始化结果
2022-10-22 15:37:53 +08:00
_isInitialize = true ;
2022-09-28 14:39:58 +08:00
initializeOperation . Completed + = InitializeOperation_Completed ;
return initializeOperation ;
}
2022-11-29 11:06:24 +08:00
private void ResetInitializeAfterFailed ( )
{
2022-12-03 19:48:17 +08:00
if ( _isInitialize & & _initializeStatus = = EOperationStatus . Failed )
2022-11-29 11:06:24 +08:00
{
_isInitialize = false ;
_initializeStatus = EOperationStatus . None ;
_initializeError = string . Empty ;
_bundleServices = null ;
2022-12-17 22:37:39 +08:00
_playModeServices = null ;
2022-11-29 11:06:24 +08:00
_assetSystemImpl = null ;
}
}
2022-09-29 18:40:43 +08:00
private void CheckInitializeParameters ( InitializeParameters parameters )
{
if ( _isInitialize )
2023-03-11 00:06:40 +08:00
throw new Exception ( $"{nameof(ResourcePackage)} is initialized yet." ) ;
2022-09-29 18:40:43 +08:00
if ( parameters = = null )
2023-03-11 00:06:40 +08:00
throw new Exception ( $"{nameof(ResourcePackage)} create parameters is null." ) ;
2022-09-29 18:40:43 +08:00
#if ! UNITY_EDITOR
if ( parameters is EditorSimulateModeParameters )
throw new Exception ( $"Editor simulate mode only support unity editor." ) ;
#endif
2022-10-18 12:07:33 +08:00
if ( parameters is EditorSimulateModeParameters )
2022-09-29 18:40:43 +08:00
{
var editorSimulateModeParameters = parameters as EditorSimulateModeParameters ;
2023-03-11 00:06:40 +08:00
if ( string . IsNullOrEmpty ( editorSimulateModeParameters . SimulateManifestFilePath ) )
throw new Exception ( $"{nameof(editorSimulateModeParameters.SimulateManifestFilePath)} is null or empty." ) ;
2022-09-29 18:40:43 +08:00
}
if ( parameters is HostPlayModeParameters )
{
var hostPlayModeParameters = parameters as HostPlayModeParameters ;
if ( hostPlayModeParameters . QueryServices = = null )
throw new Exception ( $"{nameof(IQueryServices)} is null." ) ;
2023-07-12 19:15:10 +08:00
if ( hostPlayModeParameters . RemoteServices = = null )
throw new Exception ( $"{nameof(IRemoteServices)} is null." ) ;
2022-09-29 18:40:43 +08:00
}
// 鉴定运行模式
if ( parameters is EditorSimulateModeParameters )
_playMode = EPlayMode . EditorSimulateMode ;
else if ( parameters is OfflinePlayModeParameters )
_playMode = EPlayMode . OfflinePlayMode ;
else if ( parameters is HostPlayModeParameters )
_playMode = EPlayMode . HostPlayMode ;
2023-07-18 14:27:33 +08:00
else if ( parameters is WebPlayModeParameters )
_playMode = EPlayMode . WebPlayMode ;
2022-09-29 18:40:43 +08:00
else
throw new NotImplementedException ( ) ;
2023-07-18 14:27:33 +08:00
// 检测运行平台
if ( _playMode = = EPlayMode . HostPlayMode | | _playMode = = EPlayMode . OfflinePlayMode )
{
#if UNITY_WEBGL
throw new Exception ( $"WebGL plateform not support : {_playMode} ! Please use {nameof(EPlayMode.WebPlayMode)}" ) ;
#endif
}
2022-09-29 18:40:43 +08:00
// 检测参数范围
2023-03-24 17:01:35 +08:00
if ( parameters . LoadingMaxTimeSlice < 10 )
2022-09-29 18:40:43 +08:00
{
2023-03-24 17:01:35 +08:00
parameters . LoadingMaxTimeSlice = 10 ;
YooLogger . Warning ( $"{nameof(parameters.LoadingMaxTimeSlice)} minimum value is 10 milliseconds." ) ;
2022-09-29 18:40:43 +08:00
}
2023-03-22 17:14:58 +08:00
if ( parameters . DownloadFailedTryAgain < 1 )
{
parameters . DownloadFailedTryAgain = 1 ;
YooLogger . Warning ( $"{nameof(parameters.DownloadFailedTryAgain)} minimum value is 1" ) ;
}
2022-09-29 18:40:43 +08:00
}
2022-09-28 14:39:58 +08:00
private void InitializeOperation_Completed ( AsyncOperationBase op )
{
_initializeStatus = op . Status ;
_initializeError = op . Error ;
}
/// <summary>
2022-10-31 16:45:21 +08:00
/// 向网络端请求最新的资源版本
2022-09-28 14:39:58 +08:00
/// </summary>
2022-12-03 20:03:10 +08:00
/// <param name="appendTimeTicks">在URL末尾添加时间戳</param>
2022-12-17 22:37:39 +08:00
/// <param name="timeout">超时时间( 默认值: 60秒) </param>
public UpdatePackageVersionOperation UpdatePackageVersionAsync ( bool appendTimeTicks = true , int timeout = 60 )
2022-09-28 14:39:58 +08:00
{
2023-07-19 18:18:03 +08:00
DebugCheckInitialize ( false ) ;
2022-12-17 22:37:39 +08:00
return _playModeServices . UpdatePackageVersionAsync ( appendTimeTicks , timeout ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2023-03-11 00:06:40 +08:00
/// 向网络端请求并更新清单
2022-09-28 14:39:58 +08:00
/// </summary>
2022-10-26 21:02:25 +08:00
/// <param name="packageVersion">更新的包裹版本</param>
2023-04-22 17:20:23 +08:00
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
2022-09-28 14:39:58 +08:00
/// <param name="timeout">超时时间( 默认值: 60秒) </param>
2023-04-22 17:20:23 +08:00
public UpdatePackageManifestOperation UpdatePackageManifestAsync ( string packageVersion , bool autoSaveVersion = true , int timeout = 60 )
2022-09-28 14:39:58 +08:00
{
2023-07-19 18:18:03 +08:00
DebugCheckInitialize ( false ) ;
2022-09-28 14:39:58 +08:00
DebugCheckUpdateManifest ( ) ;
2023-04-22 17:20:23 +08:00
return _playModeServices . UpdatePackageManifestAsync ( packageVersion , autoSaveVersion , timeout ) ;
2022-09-28 14:39:58 +08:00
}
2022-12-26 00:48:56 +08:00
/// <summary>
/// 预下载指定版本的包裹资源
/// </summary>
/// <param name="packageVersion">下载的包裹版本</param>
/// <param name="timeout">超时时间( 默认值: 60秒) </param>
2023-03-11 00:06:40 +08:00
public PreDownloadContentOperation PreDownloadContentAsync ( string packageVersion , int timeout = 60 )
2022-12-26 00:48:56 +08:00
{
2023-07-19 18:18:03 +08:00
DebugCheckInitialize ( false ) ;
2023-03-11 00:06:40 +08:00
return _playModeServices . PreDownloadContentAsync ( packageVersion , timeout ) ;
2022-12-26 00:48:56 +08:00
}
2023-03-22 17:14:58 +08:00
2022-10-17 16:04:47 +08:00
/// <summary>
2022-12-20 16:17:01 +08:00
/// 清理包裹未使用的缓存文件
2022-11-18 21:33:58 +08:00
/// </summary>
2022-12-20 16:17:01 +08:00
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync ( )
2022-11-18 21:33:58 +08:00
{
DebugCheckInitialize ( ) ;
2022-12-20 16:17:01 +08:00
var operation = new ClearUnusedCacheFilesOperation ( this ) ;
2022-11-18 21:33:58 +08:00
OperationSystem . StartOperation ( operation ) ;
return operation ;
}
2023-05-12 14:30:08 +08:00
/// <summary>
/// 清理包裹本地所有的缓存文件
/// </summary>
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync ( )
{
DebugCheckInitialize ( ) ;
var operation = new ClearAllCacheFilesOperation ( this ) ;
OperationSystem . StartOperation ( operation ) ;
return operation ;
}
2022-11-18 21:33:58 +08:00
/// <summary>
/// 获取本地包裹的版本信息
2022-10-17 16:04:47 +08:00
/// </summary>
2022-10-26 21:02:25 +08:00
public string GetPackageVersion ( )
2022-10-17 16:04:47 +08:00
{
DebugCheckInitialize ( ) ;
2022-12-24 22:09:14 +08:00
return _playModeServices . ActiveManifest . PackageVersion ;
2022-10-17 16:04:47 +08:00
}
2022-09-28 14:39:58 +08:00
/// <summary>
/// 资源回收(卸载引用计数为零的资源)
/// </summary>
public void UnloadUnusedAssets ( )
{
2022-10-22 15:37:53 +08:00
DebugCheckInitialize ( ) ;
_assetSystemImpl . Update ( ) ;
_assetSystemImpl . UnloadUnusedAssets ( ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
/// 强制回收所有资源
/// </summary>
public void ForceUnloadAllAssets ( )
{
2022-10-22 15:37:53 +08:00
DebugCheckInitialize ( ) ;
_assetSystemImpl . ForceUnloadAllAssets ( ) ;
2022-09-28 14:39:58 +08:00
}
2023-07-05 14:56:18 +08:00
#region 沙 盒 相 关
/// <summary>
/// 获取包裹的内置文件根路径
/// </summary>
public string GetPackageBuildinRootDirectory ( )
{
DebugCheckInitialize ( ) ;
var persistent = PersistentTools . GetPersistent ( PackageName ) ;
return persistent . BuildinRoot ;
}
/// <summary>
/// 获取包裹的沙盒文件根路径
/// </summary>
public string GetPackageSandboxRootDirectory ( )
{
DebugCheckInitialize ( ) ;
var persistent = PersistentTools . GetPersistent ( PackageName ) ;
return persistent . SandboxRoot ;
}
/// <summary>
/// 清空包裹的沙盒目录
/// </summary>
public void ClearPackageSandbox ( )
{
DebugCheckInitialize ( ) ;
var persistent = PersistentTools . GetPersistent ( PackageName ) ;
persistent . DeleteSandboxPackageFolder ( ) ;
}
#endregion
2022-09-28 14:39:58 +08:00
#region 资 源 信 息
/// <summary>
/// 是否需要从远端更新下载
/// </summary>
/// <param name="location">资源的定位地址</param>
public bool IsNeedDownloadFromRemote ( string location )
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , null ) ;
if ( assetInfo . IsInvalid )
2022-10-21 18:36:03 +08:00
{
YooLogger . Warning ( assetInfo . Error ) ;
2022-09-28 14:39:58 +08:00
return false ;
2022-10-21 18:36:03 +08:00
}
2022-09-28 14:39:58 +08:00
BundleInfo bundleInfo = _bundleServices . GetBundleInfo ( assetInfo ) ;
if ( bundleInfo . LoadMode = = BundleInfo . ELoadMode . LoadFromRemote )
return true ;
else
return false ;
}
/// <summary>
/// 是否需要从远端更新下载
/// </summary>
/// <param name="location">资源的定位地址</param>
public bool IsNeedDownloadFromRemote ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
if ( assetInfo . IsInvalid )
{
YooLogger . Warning ( assetInfo . Error ) ;
return false ;
}
BundleInfo bundleInfo = _bundleServices . GetBundleInfo ( assetInfo ) ;
if ( bundleInfo . LoadMode = = BundleInfo . ELoadMode . LoadFromRemote )
return true ;
else
return false ;
}
/// <summary>
/// 获取资源信息列表
/// </summary>
/// <param name="tag">资源标签</param>
public AssetInfo [ ] GetAssetInfos ( string tag )
{
DebugCheckInitialize ( ) ;
string [ ] tags = new string [ ] { tag } ;
2022-12-25 00:25:41 +08:00
return _playModeServices . ActiveManifest . GetAssetsInfoByTags ( tags ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
/// 获取资源信息列表
/// </summary>
/// <param name="tags">资源标签列表</param>
public AssetInfo [ ] GetAssetInfos ( string [ ] tags )
{
DebugCheckInitialize ( ) ;
2022-12-25 00:25:41 +08:00
return _playModeServices . ActiveManifest . GetAssetsInfoByTags ( tags ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
/// 获取资源信息
/// </summary>
/// <param name="location">资源的定位地址</param>
public AssetInfo GetAssetInfo ( string location )
{
DebugCheckInitialize ( ) ;
2023-06-26 18:30:29 +08:00
return ConvertLocationToAssetInfo ( location , null ) ;
}
/// <summary>
/// 获取资源信息
/// </summary>
/// <param name="assetGUID">资源GUID</param>
public AssetInfo GetAssetInfoByGUID ( string assetGUID )
{
DebugCheckInitialize ( ) ;
return ConvertAssetGUIDToAssetInfo ( assetGUID , null ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2022-10-21 18:36:03 +08:00
/// 检查资源定位地址是否有效
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="location">资源的定位地址</param>
2022-10-21 18:36:03 +08:00
public bool CheckLocationValid ( string location )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2022-12-25 00:25:41 +08:00
string assetPath = _playModeServices . ActiveManifest . TryMappingToAssetPath ( location ) ;
2022-10-21 18:36:03 +08:00
return string . IsNullOrEmpty ( assetPath ) = = false ;
2022-09-28 14:39:58 +08:00
}
#endregion
#region 原 生 文 件
/// <summary>
2022-11-19 17:54:09 +08:00
/// 同步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
public RawFileOperationHandle LoadRawFileSync ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
return LoadRawFileInternal ( assetInfo , true ) ;
}
/// <summary>
/// 同步加载原生文件
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="location">资源的定位地址</param>
2022-11-19 17:54:09 +08:00
public RawFileOperationHandle LoadRawFileSync ( string location )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , null ) ;
2022-11-19 17:54:09 +08:00
return LoadRawFileInternal ( assetInfo , true ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2022-11-19 17:54:09 +08:00
/// 异步加载原生文件
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="assetInfo">资源信息</param>
2022-11-19 17:54:09 +08:00
public RawFileOperationHandle LoadRawFileAsync ( AssetInfo assetInfo )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2022-11-19 17:54:09 +08:00
return LoadRawFileInternal ( assetInfo , false ) ;
2022-09-28 14:39:58 +08:00
}
2022-11-19 17:54:09 +08:00
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public RawFileOperationHandle LoadRawFileAsync ( string location )
2022-09-28 14:39:58 +08:00
{
2022-11-19 17:54:09 +08:00
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , null ) ;
return LoadRawFileInternal ( assetInfo , false ) ;
}
2022-09-28 14:39:58 +08:00
2022-11-19 17:54:09 +08:00
private RawFileOperationHandle LoadRawFileInternal ( AssetInfo assetInfo , bool waitForAsyncComplete )
{
2022-09-28 14:39:58 +08:00
#if UNITY_EDITOR
2022-11-19 17:54:09 +08:00
if ( assetInfo . IsInvalid = = false )
2022-09-28 14:39:58 +08:00
{
2022-11-19 17:54:09 +08:00
BundleInfo bundleInfo = _bundleServices . GetBundleInfo ( assetInfo ) ;
if ( bundleInfo . Bundle . IsRawFile = = false )
throw new Exception ( $"Cannot load asset bundle file using {nameof(LoadRawFileAsync)} method !" ) ;
2022-09-28 14:39:58 +08:00
}
#endif
2022-11-19 17:54:09 +08:00
var handle = _assetSystemImpl . LoadRawFileAsync ( assetInfo ) ;
if ( waitForAsyncComplete )
handle . WaitForAsyncComplete ( ) ;
return handle ;
2022-09-28 14:39:58 +08:00
}
#endregion
#region 场 景 加 载
/// <summary>
/// 异步加载场景
/// </summary>
/// <param name="location">场景的定位地址</param>
/// <param name="sceneMode">场景加载模式</param>
2023-06-27 17:33:04 +08:00
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
2022-09-28 14:39:58 +08:00
/// <param name="priority">优先级</param>
2023-06-27 17:33:04 +08:00
public SceneOperationHandle LoadSceneAsync ( string location , LoadSceneMode sceneMode = LoadSceneMode . Single , bool suspendLoad = false , int priority = 100 )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , null ) ;
2023-06-27 17:33:04 +08:00
var handle = _assetSystemImpl . LoadSceneAsync ( assetInfo , sceneMode , suspendLoad , priority ) ;
2022-09-28 14:39:58 +08:00
return handle ;
}
/// <summary>
/// 异步加载场景
/// </summary>
/// <param name="assetInfo">场景的资源信息</param>
/// <param name="sceneMode">场景加载模式</param>
2023-06-27 17:33:04 +08:00
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
2022-09-28 14:39:58 +08:00
/// <param name="priority">优先级</param>
2023-06-27 17:33:04 +08:00
public SceneOperationHandle LoadSceneAsync ( AssetInfo assetInfo , LoadSceneMode sceneMode = LoadSceneMode . Single , bool suspendLoad = false , int priority = 100 )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-06-27 17:33:04 +08:00
var handle = _assetSystemImpl . LoadSceneAsync ( assetInfo , sceneMode , suspendLoad , priority ) ;
2022-09-28 14:39:58 +08:00
return handle ;
}
#endregion
#region 资 源 加 载
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public AssetOperationHandle LoadAssetSync ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
return LoadAssetInternal ( assetInfo , true ) ;
}
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public AssetOperationHandle LoadAssetSync < TObject > ( string location ) where TObject : UnityEngine . Object
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , typeof ( TObject ) ) ;
return LoadAssetInternal ( assetInfo , true ) ;
}
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">资源类型</param>
public AssetOperationHandle LoadAssetSync ( string location , System . Type type )
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAssetInternal ( assetInfo , true ) ;
}
2023-07-20 11:27:56 +08:00
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AssetOperationHandle LoadAssetSync ( string location )
{
DebugCheckInitialize ( ) ;
Type type = typeof ( UnityEngine . Object ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAssetInternal ( assetInfo , true ) ;
}
2022-09-28 14:39:58 +08:00
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public AssetOperationHandle LoadAssetAsync ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
return LoadAssetInternal ( assetInfo , false ) ;
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public AssetOperationHandle LoadAssetAsync < TObject > ( string location ) where TObject : UnityEngine . Object
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , typeof ( TObject ) ) ;
return LoadAssetInternal ( assetInfo , false ) ;
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">资源类型</param>
public AssetOperationHandle LoadAssetAsync ( string location , System . Type type )
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAssetInternal ( assetInfo , false ) ;
}
2023-07-20 11:27:56 +08:00
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AssetOperationHandle LoadAssetAsync ( string location )
{
DebugCheckInitialize ( ) ;
Type type = typeof ( UnityEngine . Object ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAssetInternal ( assetInfo , false ) ;
}
2022-09-28 14:39:58 +08:00
private AssetOperationHandle LoadAssetInternal ( AssetInfo assetInfo , bool waitForAsyncComplete )
{
#if UNITY_EDITOR
2022-10-21 18:36:03 +08:00
if ( assetInfo . IsInvalid = = false )
2022-09-28 14:39:58 +08:00
{
2022-10-21 18:36:03 +08:00
BundleInfo bundleInfo = _bundleServices . GetBundleInfo ( assetInfo ) ;
if ( bundleInfo . Bundle . IsRawFile )
2022-11-19 17:54:09 +08:00
throw new Exception ( $"Cannot load raw file using {nameof(LoadAssetAsync)} method !" ) ;
2022-09-28 14:39:58 +08:00
}
#endif
2022-09-29 18:40:43 +08:00
var handle = _assetSystemImpl . LoadAssetAsync ( assetInfo ) ;
2022-09-28 14:39:58 +08:00
if ( waitForAsyncComplete )
handle . WaitForAsyncComplete ( ) ;
return handle ;
}
#endregion
#region 资 源 加 载
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public SubAssetsOperationHandle LoadSubAssetsSync ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
return LoadSubAssetsInternal ( assetInfo , true ) ;
}
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public SubAssetsOperationHandle LoadSubAssetsSync < TObject > ( string location ) where TObject : UnityEngine . Object
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , typeof ( TObject ) ) ;
return LoadSubAssetsInternal ( assetInfo , true ) ;
}
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public SubAssetsOperationHandle LoadSubAssetsSync ( string location , System . Type type )
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadSubAssetsInternal ( assetInfo , true ) ;
}
2023-07-20 11:27:56 +08:00
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public SubAssetsOperationHandle LoadSubAssetsSync ( string location )
{
DebugCheckInitialize ( ) ;
Type type = typeof ( UnityEngine . Object ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadSubAssetsInternal ( assetInfo , true ) ;
}
2022-09-28 14:39:58 +08:00
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public SubAssetsOperationHandle LoadSubAssetsAsync ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
return LoadSubAssetsInternal ( assetInfo , false ) ;
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public SubAssetsOperationHandle LoadSubAssetsAsync < TObject > ( string location ) where TObject : UnityEngine . Object
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , typeof ( TObject ) ) ;
return LoadSubAssetsInternal ( assetInfo , false ) ;
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public SubAssetsOperationHandle LoadSubAssetsAsync ( string location , System . Type type )
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadSubAssetsInternal ( assetInfo , false ) ;
}
2023-07-20 11:27:56 +08:00
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public SubAssetsOperationHandle LoadSubAssetsAsync ( string location )
{
DebugCheckInitialize ( ) ;
Type type = typeof ( UnityEngine . Object ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadSubAssetsInternal ( assetInfo , false ) ;
}
2022-09-28 14:39:58 +08:00
private SubAssetsOperationHandle LoadSubAssetsInternal ( AssetInfo assetInfo , bool waitForAsyncComplete )
{
#if UNITY_EDITOR
2022-10-21 18:36:03 +08:00
if ( assetInfo . IsInvalid = = false )
2022-09-28 14:39:58 +08:00
{
2022-10-21 18:36:03 +08:00
BundleInfo bundleInfo = _bundleServices . GetBundleInfo ( assetInfo ) ;
if ( bundleInfo . Bundle . IsRawFile )
2022-11-19 17:54:09 +08:00
throw new Exception ( $"Cannot load raw file using {nameof(LoadSubAssetsAsync)} method !" ) ;
2022-09-28 14:39:58 +08:00
}
#endif
2022-09-29 18:40:43 +08:00
var handle = _assetSystemImpl . LoadSubAssetsAsync ( assetInfo ) ;
2022-09-28 14:39:58 +08:00
if ( waitForAsyncComplete )
handle . WaitForAsyncComplete ( ) ;
return handle ;
}
#endregion
2023-06-25 12:03:19 +08:00
#region 资 源 加 载
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public AllAssetsOperationHandle LoadAllAssetsSync ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
return LoadAllAssetsInternal ( assetInfo , true ) ;
}
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public AllAssetsOperationHandle LoadAllAssetsSync < TObject > ( string location ) where TObject : UnityEngine . Object
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , typeof ( TObject ) ) ;
return LoadAllAssetsInternal ( assetInfo , true ) ;
}
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public AllAssetsOperationHandle LoadAllAssetsSync ( string location , System . Type type )
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAllAssetsInternal ( assetInfo , true ) ;
}
2023-07-20 11:27:56 +08:00
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AllAssetsOperationHandle LoadAllAssetsSync ( string location )
{
DebugCheckInitialize ( ) ;
Type type = typeof ( UnityEngine . Object ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAllAssetsInternal ( assetInfo , true ) ;
}
2023-06-25 12:03:19 +08:00
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public AllAssetsOperationHandle LoadAllAssetsAsync ( AssetInfo assetInfo )
{
DebugCheckInitialize ( ) ;
return LoadAllAssetsInternal ( assetInfo , false ) ;
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public AllAssetsOperationHandle LoadAllAssetsAsync < TObject > ( string location ) where TObject : UnityEngine . Object
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , typeof ( TObject ) ) ;
return LoadAllAssetsInternal ( assetInfo , false ) ;
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public AllAssetsOperationHandle LoadAllAssetsAsync ( string location , System . Type type )
{
DebugCheckInitialize ( ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAllAssetsInternal ( assetInfo , false ) ;
}
2023-06-27 17:33:04 +08:00
2023-07-20 11:27:56 +08:00
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AllAssetsOperationHandle LoadAllAssetsAsync ( string location )
{
DebugCheckInitialize ( ) ;
Type type = typeof ( UnityEngine . Object ) ;
AssetInfo assetInfo = ConvertLocationToAssetInfo ( location , type ) ;
return LoadAllAssetsInternal ( assetInfo , false ) ;
}
2023-06-25 12:03:19 +08:00
private AllAssetsOperationHandle LoadAllAssetsInternal ( AssetInfo assetInfo , bool waitForAsyncComplete )
{
#if UNITY_EDITOR
if ( assetInfo . IsInvalid = = false )
{
BundleInfo bundleInfo = _bundleServices . GetBundleInfo ( assetInfo ) ;
if ( bundleInfo . Bundle . IsRawFile )
throw new Exception ( $"Cannot load raw file using {nameof(LoadAllAssetsAsync)} method !" ) ;
}
#endif
var handle = _assetSystemImpl . LoadAllAssetsAsync ( assetInfo ) ;
if ( waitForAsyncComplete )
handle . WaitForAsyncComplete ( ) ;
return handle ;
}
#endregion
2022-09-28 14:39:58 +08:00
#region 资 源 下 载
/// <summary>
2023-03-11 00:06:40 +08:00
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
/// </summary>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateResourceDownloader ( int downloadingMaxNumber , int failedTryAgain , int timeout = 60 )
{
DebugCheckInitialize ( ) ;
return _playModeServices . CreateResourceDownloaderByAll ( downloadingMaxNumber , failedTryAgain , timeout ) ;
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
2022-10-17 14:43:13 +08:00
/// <param name="timeout">超时时间</param>
2023-03-11 00:06:40 +08:00
public ResourceDownloaderOperation CreateResourceDownloader ( string tag , int downloadingMaxNumber , int failedTryAgain , int timeout = 60 )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-03-11 00:06:40 +08:00
return _playModeServices . CreateResourceDownloaderByTags ( new string [ ] { tag } , downloadingMaxNumber , failedTryAgain , timeout ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2023-03-11 00:06:40 +08:00
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
2022-10-17 14:43:13 +08:00
/// <param name="timeout">超时时间</param>
2023-03-11 00:06:40 +08:00
public ResourceDownloaderOperation CreateResourceDownloader ( string [ ] tags , int downloadingMaxNumber , int failedTryAgain , int timeout = 60 )
{
DebugCheckInitialize ( ) ;
return _playModeServices . CreateResourceDownloaderByTags ( tags , downloadingMaxNumber , failedTryAgain , timeout ) ;
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader ( string location , int downloadingMaxNumber , int failedTryAgain , int timeout = 60 )
{
DebugCheckInitialize ( ) ;
var assetInfo = ConvertLocationToAssetInfo ( location , null ) ;
AssetInfo [ ] assetInfos = new AssetInfo [ ] { assetInfo } ;
return _playModeServices . CreateResourceDownloaderByPaths ( assetInfos , downloadingMaxNumber , failedTryAgain , timeout ) ;
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="locations">资源的定位地址列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
/// <param name="timeout">超时时间</param>
public ResourceDownloaderOperation CreateBundleDownloader ( string [ ] locations , int downloadingMaxNumber , int failedTryAgain , int timeout = 60 )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-03-11 00:06:40 +08:00
List < AssetInfo > assetInfos = new List < AssetInfo > ( locations . Length ) ;
foreach ( var location in locations )
{
var assetInfo = ConvertLocationToAssetInfo ( location , null ) ;
assetInfos . Add ( assetInfo ) ;
}
return _playModeServices . CreateResourceDownloaderByPaths ( assetInfos . ToArray ( ) , downloadingMaxNumber , failedTryAgain , timeout ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2023-03-11 00:06:40 +08:00
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
2022-09-28 14:39:58 +08:00
/// </summary>
2023-03-11 00:06:40 +08:00
/// <param name="assetInfo">资源信息</param>
2022-09-28 14:39:58 +08:00
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
2022-10-17 14:43:13 +08:00
/// <param name="timeout">超时时间</param>
2023-03-11 00:06:40 +08:00
public ResourceDownloaderOperation CreateBundleDownloader ( AssetInfo assetInfo , int downloadingMaxNumber , int failedTryAgain , int timeout = 60 )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-03-11 00:06:40 +08:00
AssetInfo [ ] assetInfos = new AssetInfo [ ] { assetInfo } ;
return _playModeServices . CreateResourceDownloaderByPaths ( assetInfos , downloadingMaxNumber , failedTryAgain , timeout ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2023-03-11 00:06:40 +08:00
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="assetInfos">资源信息列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
2022-10-17 14:43:13 +08:00
/// <param name="timeout">超时时间</param>
2023-03-11 00:06:40 +08:00
public ResourceDownloaderOperation CreateBundleDownloader ( AssetInfo [ ] assetInfos , int downloadingMaxNumber , int failedTryAgain , int timeout = 60 )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-03-11 00:06:40 +08:00
return _playModeServices . CreateResourceDownloaderByPaths ( assetInfos , downloadingMaxNumber , failedTryAgain , timeout ) ;
2022-09-28 14:39:58 +08:00
}
#endregion
#region 资 源 解 压
/// <summary>
2023-03-11 00:06:40 +08:00
/// 创建内置资源解压器
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
2023-03-11 00:06:40 +08:00
public ResourceUnpackerOperation CreateResourceUnpacker ( string tag , int unpackingMaxNumber , int failedTryAgain )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-03-11 00:06:40 +08:00
return _playModeServices . CreateResourceUnpackerByTags ( new string [ ] { tag } , unpackingMaxNumber , failedTryAgain , int . MaxValue ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2023-03-11 00:06:40 +08:00
/// 创建内置资源解压器
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
2023-03-11 00:06:40 +08:00
public ResourceUnpackerOperation CreateResourceUnpacker ( string [ ] tags , int unpackingMaxNumber , int failedTryAgain )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-03-11 00:06:40 +08:00
return _playModeServices . CreateResourceUnpackerByTags ( tags , unpackingMaxNumber , failedTryAgain , int . MaxValue ) ;
2022-09-28 14:39:58 +08:00
}
/// <summary>
2023-03-11 00:06:40 +08:00
/// 创建内置资源解压器
2022-09-28 14:39:58 +08:00
/// </summary>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
2023-03-11 00:06:40 +08:00
public ResourceUnpackerOperation CreateResourceUnpacker ( int unpackingMaxNumber , int failedTryAgain )
2022-09-28 14:39:58 +08:00
{
DebugCheckInitialize ( ) ;
2023-03-11 00:06:40 +08:00
return _playModeServices . CreateResourceUnpackerByAll ( unpackingMaxNumber , failedTryAgain , int . MaxValue ) ;
2022-09-28 14:39:58 +08:00
}
#endregion
#region 内 部 方 法
2022-10-18 11:56:05 +08:00
/// <summary>
/// 是否包含资源文件
/// </summary>
2023-02-07 18:39:08 +08:00
internal bool IsIncludeBundleFile ( string cacheGUID )
2022-10-18 11:56:05 +08:00
{
2022-10-18 12:07:33 +08:00
// NOTE : 编辑器模拟模式下始终返回TRUE
if ( _playMode = = EPlayMode . EditorSimulateMode )
return true ;
2023-02-07 18:39:08 +08:00
return _playModeServices . ActiveManifest . IsIncludeBundleFile ( cacheGUID ) ;
2022-12-25 00:25:41 +08:00
}
private AssetInfo ConvertLocationToAssetInfo ( string location , System . Type assetType )
{
return _playModeServices . ActiveManifest . ConvertLocationToAssetInfo ( location , assetType ) ;
2022-10-18 11:56:05 +08:00
}
2023-06-26 18:30:29 +08:00
private AssetInfo ConvertAssetGUIDToAssetInfo ( string assetGUID , System . Type assetType )
{
return _playModeServices . ActiveManifest . ConvertAssetGUIDToAssetInfo ( assetGUID , assetType ) ;
}
2022-09-28 14:39:58 +08:00
#endregion
#region 调 试 方 法
[Conditional("DEBUG")]
2023-07-19 18:18:03 +08:00
private void DebugCheckInitialize ( bool checkActiveManifest = true )
2022-09-28 14:39:58 +08:00
{
if ( _initializeStatus = = EOperationStatus . None )
2022-10-31 16:45:21 +08:00
throw new Exception ( "Package initialize not completed !" ) ;
2022-09-28 14:39:58 +08:00
else if ( _initializeStatus = = EOperationStatus . Failed )
2022-10-31 16:45:21 +08:00
throw new Exception ( $"Package initialize failed ! {_initializeError}" ) ;
2023-07-19 18:18:03 +08:00
if ( checkActiveManifest )
{
if ( _playModeServices . ActiveManifest = = null )
throw new Exception ( "Not found active manifest !" ) ;
}
2022-09-28 14:39:58 +08:00
}
[Conditional("DEBUG")]
private void DebugCheckUpdateManifest ( )
{
2022-09-29 18:40:43 +08:00
var loadedBundleInfos = _assetSystemImpl . GetLoadedBundleInfos ( ) ;
2022-09-28 14:39:58 +08:00
if ( loadedBundleInfos . Count > 0 )
{
2022-12-21 10:54:22 +08:00
YooLogger . Warning ( $"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !" ) ;
2022-09-28 14:39:58 +08:00
}
}
#endregion
2022-09-29 18:40:43 +08:00
#region 调 试 信 息
2022-10-22 15:37:53 +08:00
internal DebugPackageData GetDebugPackageData ( )
2022-09-29 18:40:43 +08:00
{
2022-10-22 15:37:53 +08:00
DebugPackageData data = new DebugPackageData ( ) ;
data . PackageName = PackageName ;
data . ProviderInfos = _assetSystemImpl . GetDebugReportInfos ( ) ;
return data ;
2022-09-29 18:40:43 +08:00
}
#endregion
2022-09-28 14:39:58 +08:00
}
}