mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-26 10:40:14 +00:00
update extension sample
This commit is contained in:
@@ -0,0 +1,274 @@
|
|||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
#region InitializeParameters
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化参数
|
||||||
|
/// </summary>
|
||||||
|
public abstract class InitializeParameters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 同时加载Bundle文件的最大并发数
|
||||||
|
/// </summary>
|
||||||
|
public int BundleLoadingMaxConcurrency = int.MaxValue;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当资源引用计数为零的时候自动释放资源包
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoUnloadBundleWhenUnused = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WebGL平台强制同步加载资源对象
|
||||||
|
/// </summary>
|
||||||
|
public bool WebGLForceSyncLoadAsset = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器下模拟运行模式的初始化参数
|
||||||
|
/// </summary>
|
||||||
|
public class EditorSimulateModeParameters : InitializeParameters
|
||||||
|
{
|
||||||
|
public FileSystemParameters EditorFileSystemParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 离线运行模式的初始化参数
|
||||||
|
/// </summary>
|
||||||
|
public class OfflinePlayModeParameters : InitializeParameters
|
||||||
|
{
|
||||||
|
public FileSystemParameters BuildinFileSystemParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 联机运行模式的初始化参数
|
||||||
|
/// </summary>
|
||||||
|
public class HostPlayModeParameters : InitializeParameters
|
||||||
|
{
|
||||||
|
public FileSystemParameters BuildinFileSystemParameters;
|
||||||
|
public FileSystemParameters CacheFileSystemParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WebGL运行模式的初始化参数
|
||||||
|
/// </summary>
|
||||||
|
public class WebPlayModeParameters : InitializeParameters
|
||||||
|
{
|
||||||
|
public FileSystemParameters WebServerFileSystemParameters;
|
||||||
|
public FileSystemParameters WebRemoteFileSystemParameters;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region InitializationOperation
|
||||||
|
public class InitializationOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private bool _isDone = false;
|
||||||
|
private readonly InitializePackageOperation _operation;
|
||||||
|
|
||||||
|
internal InitializationOperation(InitializePackageOperation op)
|
||||||
|
{
|
||||||
|
_operation = op;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_isDone)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_operation.UpdateOperation();
|
||||||
|
if (_operation.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isDone = true;
|
||||||
|
Status = _operation.Status;
|
||||||
|
Error = _operation.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DestroyOperation
|
||||||
|
public class DestroyOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private bool _isDone = false;
|
||||||
|
private readonly DestroyPackageOperation _operation;
|
||||||
|
|
||||||
|
internal DestroyOperation(DestroyPackageOperation op)
|
||||||
|
{
|
||||||
|
_operation = op;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_isDone)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_operation.UpdateOperation();
|
||||||
|
if (_operation.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isDone = true;
|
||||||
|
Status = _operation.Status;
|
||||||
|
Error = _operation.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UpdatePackageManifestOperation
|
||||||
|
public class UpdatePackageManifestOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private bool _isDone = false;
|
||||||
|
private readonly LoadPackageManifestOperation _operation;
|
||||||
|
|
||||||
|
internal UpdatePackageManifestOperation(LoadPackageManifestOperation op)
|
||||||
|
{
|
||||||
|
_operation = op;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_isDone)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_operation.UpdateOperation();
|
||||||
|
if (_operation.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isDone = true;
|
||||||
|
Status = _operation.Status;
|
||||||
|
Error = _operation.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public static class CompatibleOldVersion
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容Yoo2版本
|
||||||
|
/// </summary>
|
||||||
|
public static InitializationOperation InitializeAsync(this ResourcePackage package, InitializeParameters parameters)
|
||||||
|
{
|
||||||
|
if (parameters is EditorSimulateModeParameters)
|
||||||
|
{
|
||||||
|
var initializeParameters = parameters as EditorSimulateModeParameters;
|
||||||
|
var options = new EditorSimulateModeOptions();
|
||||||
|
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
|
||||||
|
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
|
||||||
|
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
|
||||||
|
options.EditorFileSystemParameters = initializeParameters.EditorFileSystemParameters;
|
||||||
|
var operation = package.InitializePackageAsync(options);
|
||||||
|
var wrapper = new InitializationOperation(operation);
|
||||||
|
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
else if (parameters is OfflinePlayModeParameters)
|
||||||
|
{
|
||||||
|
var initializeParameters = parameters as OfflinePlayModeParameters;
|
||||||
|
var options = new OfflinePlayModeOptions();
|
||||||
|
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
|
||||||
|
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
|
||||||
|
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
|
||||||
|
options.BuildinFileSystemParameters = initializeParameters.BuildinFileSystemParameters;
|
||||||
|
var operation = package.InitializePackageAsync(options);
|
||||||
|
var wrapper = new InitializationOperation(operation);
|
||||||
|
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
else if (parameters is HostPlayModeParameters)
|
||||||
|
{
|
||||||
|
var initializeParameters = parameters as HostPlayModeParameters;
|
||||||
|
var options = new HostPlayModeOptions();
|
||||||
|
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
|
||||||
|
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
|
||||||
|
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
|
||||||
|
options.BuildinFileSystemParameters = initializeParameters.BuildinFileSystemParameters;
|
||||||
|
options.CacheFileSystemParameters = initializeParameters.CacheFileSystemParameters;
|
||||||
|
var operation = package.InitializePackageAsync(options);
|
||||||
|
var wrapper = new InitializationOperation(operation);
|
||||||
|
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
else if (parameters is WebPlayModeParameters)
|
||||||
|
{
|
||||||
|
var initializeParameters = parameters as WebPlayModeParameters;
|
||||||
|
var options = new WebPlayModeOptions();
|
||||||
|
options.BundleLoadingMaxConcurrency = initializeParameters.BundleLoadingMaxConcurrency;
|
||||||
|
options.AutoUnloadBundleWhenUnused = initializeParameters.AutoUnloadBundleWhenUnused;
|
||||||
|
options.WebGLForceSyncLoadAsset = initializeParameters.WebGLForceSyncLoadAsset;
|
||||||
|
options.WebServerFileSystemParameters = initializeParameters.WebServerFileSystemParameters;
|
||||||
|
options.WebRemoteFileSystemParameters = initializeParameters.WebRemoteFileSystemParameters;
|
||||||
|
var operation = package.InitializePackageAsync(options);
|
||||||
|
var wrapper = new InitializationOperation(operation);
|
||||||
|
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容Yoo2版本
|
||||||
|
/// </summary>
|
||||||
|
public static DestroyOperation DestroyAsync(this ResourcePackage package)
|
||||||
|
{
|
||||||
|
var operation = package.DestroyPackageAsync();
|
||||||
|
var wrapper = new DestroyOperation(operation);
|
||||||
|
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容Yoo2版本
|
||||||
|
/// </summary>
|
||||||
|
public static RequestPackageVersionOperation RequestPackageVersionAsync(this ResourcePackage package, bool appendTimeTicks = true, int timeout = 60)
|
||||||
|
{
|
||||||
|
var options = new RequestPackageVersionOptions(appendTimeTicks, timeout);
|
||||||
|
var operation = package.RequestPackageVersionAsync(options);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容Yoo2版本
|
||||||
|
/// </summary>
|
||||||
|
public static UpdatePackageManifestOperation UpdatePackageManifestAsync(this ResourcePackage package, string packageVersion, int timeout = 60)
|
||||||
|
{
|
||||||
|
var options = new LoadPackageManifestOptions(packageVersion, timeout);
|
||||||
|
var operation = package.LoadPackageManifestAsync(options);
|
||||||
|
var wrapper = new UpdatePackageManifestOperation(operation);
|
||||||
|
OperationSystem.StartOperation(package.PackageName, wrapper);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容Yoo2版本
|
||||||
|
/// </summary>
|
||||||
|
public static PreDownloadContentOperation PreDownloadContentAsync(this ResourcePackage package, string packageVersion, int timeout = 60)
|
||||||
|
{
|
||||||
|
var options = new PreDownloadContentOptions(packageVersion, timeout);
|
||||||
|
var operation = package.PreDownloadContentAsync(options);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容Yoo2版本
|
||||||
|
/// </summary>
|
||||||
|
public static ClearCacheFilesOperation ClearCacheFilesAsync(this ResourcePackage package, EFileClearMode fileClearMode, object clearParam = null)
|
||||||
|
{
|
||||||
|
var options = new ClearCacheFilesOptions(fileClearMode, clearParam);
|
||||||
|
return package.ClearCacheFilesAsync(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容Yoo2版本
|
||||||
|
/// </summary>
|
||||||
|
public static ClearCacheFilesOperation ClearCacheFilesAsync(this ResourcePackage package, string fileClearMode, object clearParam = null)
|
||||||
|
{
|
||||||
|
var options = new ClearCacheFilesOptions(fileClearMode, clearParam);
|
||||||
|
return package.ClearCacheFilesAsync(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b974d3d744622f3499d026f99074cd72
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user