change : remove legacy WebGame and WebRemote file systems

This commit is contained in:
何冠峰
2026-05-26 19:18:29 +08:00
parent d337a86e68
commit af7aecbf0b
80 changed files with 152 additions and 3026 deletions

View File

@@ -1,129 +0,0 @@
using UnityEngine;
namespace YooAsset
{
/// <summary>
/// 从网络加载未加密 AssetBundle 操作
/// </summary>
internal sealed class LoadWebNormalAssetBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
BundleRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly LoadWebAssetBundleOptions _options;
private readonly DownloadRetryController _downloadRetryController;
private IDownloadAssetBundleRequest _downloadAssetBundleRequest;
private ESteps _steps = ESteps.None;
/// <summary>
/// 创建 AssetBundle 加载操作实例
/// </summary>
/// <param name="options">从网络加载 AssetBundle 的操作选项</param>
public LoadWebNormalAssetBundleOperation(LoadWebAssetBundleOptions options)
{
_options = options;
// 注意:网络原因失败后,重新尝试直到成功
_downloadRetryController = new DownloadRetryController(int.MaxValue, options.DownloadRetryPolicy);
}
protected override void InternalStart()
{
_steps = ESteps.BundleRequest;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.BundleRequest)
{
string url = _options.DownloadUrlPolicy.SelectUrl(_options.CandidateUrls);
var args = new DownloadAssetBundleRequestArgs(
url: url,
timeout: 0,
watchdogTimeout: _options.WatchdogTimeout,
disableUnityWebCache: _options.DisableUnityWebCache,
fileHash: _options.Bundle.FileHash,
unityCrc: _options.Bundle.UnityCrc,
platformStrategy : null);
_downloadAssetBundleRequest = _options.DownloadBackend.CreateAssetBundleRequest(args);
_downloadAssetBundleRequest.SendRequest();
_steps = ESteps.CheckRequest;
}
if (_steps == ESteps.CheckRequest)
{
Progress = _downloadAssetBundleRequest.DownloadProgress;
if (_downloadAssetBundleRequest.IsDone == false)
return;
if (_downloadAssetBundleRequest.Status == EDownloadRequestStatus.Succeeded)
{
_options.DownloadUrlPolicy.OnRequestSucceeded(_downloadAssetBundleRequest.Url);
var assetBundle = _downloadAssetBundleRequest.Result;
if (assetBundle == null)
{
_steps = ESteps.Done;
SetError($"Downloaded asset bundle is null. URL: {_downloadAssetBundleRequest.Url}");
}
else
{
_steps = ESteps.Done;
SetResult();
BundleHandle = new AssetBundleHandle(_options.Bundle, assetBundle, null);
}
}
else
{
string url = _downloadAssetBundleRequest.Url;
long httpCode = _downloadAssetBundleRequest.HttpCode;
string httpError = _downloadAssetBundleRequest.HttpError;
_options.DownloadUrlPolicy.OnRequestFailed(url, httpCode, httpError);
if (IsWaitForCompletion == false && _downloadRetryController.CanRetryRequest(url, httpCode, httpError))
{
_downloadRetryController.StartRetryDelay();
_steps = ESteps.TryAgain;
}
else
{
_steps = ESteps.Done;
SetError(_downloadAssetBundleRequest.Error);
YooLogger.LogError(Error);
}
}
}
if (_steps == ESteps.TryAgain)
{
// 注意:失败后释放网络请求
if (_downloadAssetBundleRequest != null)
{
_downloadAssetBundleRequest.Dispose();
_downloadAssetBundleRequest = null;
}
if (_downloadRetryController.TickRetryDelay())
{
Progress = 0f;
_steps = ESteps.BundleRequest;
}
}
}
protected override void InternalDispose()
{
if (_downloadAssetBundleRequest != null)
{
_downloadAssetBundleRequest.Dispose();
_downloadAssetBundleRequest = null;
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f0fd9af541471154d9fc968abd450d31
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,76 +0,0 @@
using System.Collections.Generic;
namespace YooAsset
{
/// <summary>
/// 加载 AssetBundle 的操作选项
/// </summary>
internal readonly struct LoadWebAssetBundleOptions
{
/// <summary>
/// 文件缓存名称
/// </summary>
public string CacheName { get; }
/// <summary>
/// 资源包描述
/// </summary>
public PackageBundle Bundle { get; }
/// <summary>
/// 候选下载地址列表
/// </summary>
public IReadOnlyList<string> CandidateUrls { get; }
/// <summary>
/// AssetBundle 解密器
/// </summary>
public IBundleDecryptor AssetBundleDecryptor { get; }
/// <summary>
/// 下载后台接口
/// </summary>
public IDownloadBackend DownloadBackend { get; }
/// <summary>
/// 下载数据校验级别
/// </summary>
public EFileVerifyLevel DownloadVerifyLevel { get; }
/// <summary>
/// 看门狗超时时间
/// </summary>
public int WatchdogTimeout { get; }
/// <summary>
/// 禁用 Unity 内置网络缓存
/// </summary>
public bool DisableUnityWebCache { get; }
/// <summary>
/// 下载重试判定策略
/// </summary>
public IDownloadRetryPolicy DownloadRetryPolicy { get; }
/// <summary>
/// URL 选择策略
/// </summary>
public IDownloadUrlPolicy DownloadUrlPolicy { get; }
public LoadWebAssetBundleOptions(string cacheName, PackageBundle bundle, IReadOnlyList<string> candidateUrls,
IBundleDecryptor assetBundleDecryptor, IDownloadBackend downloadBackend, EFileVerifyLevel downloadVerifyLevel,
int watchdogTimeout, bool disableUnityWebCache, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy)
{
CacheName = cacheName;
Bundle = bundle;
CandidateUrls = candidateUrls;
AssetBundleDecryptor = assetBundleDecryptor;
DownloadBackend = downloadBackend;
DownloadVerifyLevel = downloadVerifyLevel;
WatchdogTimeout = watchdogTimeout;
DisableUnityWebCache = disableUnityWebCache;
DownloadRetryPolicy = downloadRetryPolicy;
DownloadUrlPolicy = downloadUrlPolicy;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4c79e03ac8bcbef4aa0e2eede5bf63fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f6cbd76495075b54993179318fdda8dc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ead67fdda05e99747b03f49accc1526a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 9c86f68bc316ce54ca9396e6e6c2dd8f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,121 +0,0 @@
using UnityEngine;
namespace YooAsset
{
/// <summary>
/// 从 WebGL 游戏平台加载非加密 AssetBundle 操作
/// </summary>
internal sealed class LoadWebGameAssetBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
BundleRequest,
CheckRequest,
TryAgain,
Done,
}
private readonly LoadWebGameAssetBundleOptions _options;
private readonly DownloadRetryController _downloadRetryController;
private IDownloadAssetBundleRequest _downloadAssetBundleRequest;
private ESteps _steps = ESteps.None;
internal LoadWebGameAssetBundleOperation(LoadWebGameAssetBundleOptions options)
{
_options = options;
// 注意:网络原因失败后,重新尝试直到成功
_downloadRetryController = new DownloadRetryController(int.MaxValue, options.DownloadRetryPolicy);
}
protected override void InternalStart()
{
_steps = ESteps.BundleRequest;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.BundleRequest)
{
string url = _options.DownloadUrlPolicy.SelectUrl(_options.CandidateUrls);
var args = new DownloadRequestArgs(
url: url,
timeout: 0,
watchdogTimeout: _options.WatchdogTimeout);
_downloadAssetBundleRequest = new WebGameAssetBundleRequest(args, _options.GamePlatform);
_downloadAssetBundleRequest.SendRequest();
_steps = ESteps.CheckRequest;
}
if (_steps == ESteps.CheckRequest)
{
//TODO 部分小游戏平台的 downloadProgress 始终返回 0导致进度条无法正确显示。
Progress = _downloadAssetBundleRequest.DownloadProgress;
if (_downloadAssetBundleRequest.IsDone == false)
return;
if (_downloadAssetBundleRequest.Status == EDownloadRequestStatus.Succeeded)
{
_options.DownloadUrlPolicy.OnRequestSucceeded(_downloadAssetBundleRequest.Url);
var assetBundle = _downloadAssetBundleRequest.Result;
if (assetBundle == null)
{
_steps = ESteps.Done;
SetError($"Downloaded asset bundle is null. URL: {_downloadAssetBundleRequest.Url}");
}
else
{
_steps = ESteps.Done;
SetResult();
BundleHandle = new WebGameAssetBundleHandle(_options.Bundle, assetBundle, _options.GamePlatform);
}
}
else
{
string url = _downloadAssetBundleRequest.Url;
long httpCode = _downloadAssetBundleRequest.HttpCode;
string httpError = _downloadAssetBundleRequest.HttpError;
_options.DownloadUrlPolicy.OnRequestFailed(url, httpCode, httpError);
if (IsWaitForCompletion == false && _downloadRetryController.CanRetryRequest(url, httpCode, httpError))
{
_downloadRetryController.StartRetryDelay();
_steps = ESteps.TryAgain;
}
else
{
_steps = ESteps.Done;
SetError(_downloadAssetBundleRequest.Error);
YooLogger.LogError(Error);
}
}
}
if (_steps == ESteps.TryAgain)
{
// 注意:失败后释放网络请求
if (_downloadAssetBundleRequest != null)
{
_downloadAssetBundleRequest.Dispose();
_downloadAssetBundleRequest = null;
}
if (_downloadRetryController.TickRetryDelay())
{
Progress = 0f;
_steps = ESteps.BundleRequest;
}
}
}
protected override void InternalDispose()
{
if (_downloadAssetBundleRequest != null)
{
_downloadAssetBundleRequest.Dispose();
_downloadAssetBundleRequest = null;
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5ef65b981b91200439b05f29435e7c92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,52 +0,0 @@
using System.Collections.Generic;
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台加载 AssetBundle 的操作选项
/// </summary>
internal readonly struct LoadWebGameAssetBundleOptions
{
/// <summary>
/// 资源包描述
/// </summary>
public PackageBundle Bundle { get; }
/// <summary>
/// 候选下载地址列表
/// </summary>
public IReadOnlyList<string> CandidateUrls { get; }
/// <summary>
/// 游戏平台接口
/// </summary>
public IWebGamePlatform GamePlatform { get; }
/// <summary>
/// 看门狗超时时间
/// </summary>
public int WatchdogTimeout { get; }
/// <summary>
/// 下载重试判定策略
/// </summary>
public IDownloadRetryPolicy DownloadRetryPolicy { get; }
/// <summary>
/// URL 选择策略
/// </summary>
public IDownloadUrlPolicy DownloadUrlPolicy { get; }
public LoadWebGameAssetBundleOptions(PackageBundle bundle, IReadOnlyList<string> candidateUrls,
IWebGamePlatform gamePlatform, int watchdogTimeout,
IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy)
{
Bundle = bundle;
CandidateUrls = candidateUrls;
GamePlatform = gamePlatform;
WatchdogTimeout = watchdogTimeout;
DownloadRetryPolicy = downloadRetryPolicy;
DownloadUrlPolicy = downloadUrlPolicy;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f71ffbb8bf041e5478862cc179cd7e3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,17 +0,0 @@
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台缓存系统初始化操作
/// </summary>
internal sealed class WGBCInitializeOperation : BCInitializeOperation
{
protected override void InternalStart()
{
SetResult();
}
protected override void InternalUpdate()
{
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5b2ea6881f51a434db344d28e4e5f410
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,100 +0,0 @@
namespace YooAsset
{
/// <summary>
/// 小游戏平台加载 AssetBundle 操作
/// </summary>
internal sealed class WGBCLoadAssetBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
Done,
}
private readonly WebGameBundleCache _fileCache;
private readonly BCLoadBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
internal WGBCLoadAssetBundleOperation(WebGameBundleCache fileCache, BCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_loadBundleOp == null)
{
var urls = _fileCache.Config.RemoteService.GetRemoteUrls(_options.Bundle.GetFileName());
if (_options.Bundle.IsEncrypted)
{
var encryptedOptions = new LoadWebEncryptedAssetBundleOptions(
cacheName: _fileCache.GetType().Name,
bundle: _options.Bundle,
candidateUrls: urls,
assetBundleDecryptor: _fileCache.Config.AssetBundleDecryptor,
downloadBackend: _fileCache.Config.DownloadBackend,
downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel,
watchdogTimeout: _fileCache.Config.WatchdogTimeout,
downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy,
downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy);
_loadBundleOp = new LoadWebEncryptedAssetBundleOperation(encryptedOptions);
}
else
{
var webGameOptions = new LoadWebGameAssetBundleOptions(
bundle: _options.Bundle,
candidateUrls: urls,
gamePlatform: _fileCache.Config.GamePlatform,
watchdogTimeout: _fileCache.Config.WatchdogTimeout,
downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy,
downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy);
_loadBundleOp = new LoadWebGameAssetBundleOperation(webGameOptions);
}
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
}
_loadBundleOp.UpdateOperation();
Progress = _loadBundleOp.Progress;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadBundleOp.BundleHandle == null)
throw new YooInternalException("Loaded bundle handle is null.");
_steps = ESteps.Done;
SetResult();
BundleHandle = _loadBundleOp.BundleHandle;
}
else
{
_steps = ESteps.Done;
SetError(_loadBundleOp.Error);
}
}
}
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
SetError("WebGL platform does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c5aefbf5ae866434483465f633edf635
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,85 +0,0 @@
namespace YooAsset
{
/// <summary>
/// 小游戏平台加载 RawBundle 操作
/// </summary>
internal sealed class WGBCLoadRawBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
Done,
}
private readonly WebGameBundleCache _fileCache;
private readonly BCLoadBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
internal WGBCLoadRawBundleOperation(WebGameBundleCache fileCache, BCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_loadBundleOp == null)
{
var urls = _fileCache.Config.RemoteService.GetRemoteUrls(_options.Bundle.GetFileName());
var options = new LoadWebRawBundleOptions(
cacheName: _fileCache.GetType().Name,
bundle: _options.Bundle,
candidateUrls: urls,
rawBundleDecryptor: _fileCache.Config.RawBundleDecryptor,
downloadBackend: _fileCache.Config.DownloadBackend,
downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel,
watchdogTimeout: _fileCache.Config.WatchdogTimeout,
downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy,
downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy);
_loadBundleOp = new LoadWebRawBundleOperation(options);
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
}
_loadBundleOp.UpdateOperation();
Progress = _loadBundleOp.Progress;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadBundleOp.BundleHandle == null)
throw new YooInternalException("Loaded bundle handle is null.");
_steps = ESteps.Done;
SetResult();
BundleHandle = _loadBundleOp.BundleHandle;
}
else
{
_steps = ESteps.Done;
SetError(_loadBundleOp.Error);
}
}
}
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
SetError("WebGL platform does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4024fa98150c5d4479e93ce88c6c2795
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,175 +0,0 @@
using System.Collections.Generic;
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台缓存系统
/// </summary>
internal class WebGameBundleCache : IBundleCache
{
internal readonly struct Configuration
{
/// <summary>
/// 游戏平台接口
/// </summary>
public IWebGamePlatform GamePlatform { get; }
/// <summary>
/// 看门狗超时时间
/// </summary>
public int WatchdogTimeout { get; }
/// <summary>
/// 禁用 Unity 内置网络缓存
/// </summary>
public bool DisableUnityWebCache { get; }
/// <summary>
/// 下载数据校验级别
/// </summary>
public EFileVerifyLevel DownloadVerifyLevel { get; }
/// <summary>
/// AssetBundle 解密器
/// </summary>
public IBundleDecryptor AssetBundleDecryptor { get; }
/// <summary>
/// RawBundle 解密器
/// </summary>
public IBundleDecryptor RawBundleDecryptor { get; }
/// <summary>
/// 远程服务接口
/// </summary>
public IRemoteService RemoteService { get; }
/// <summary>
/// 下载后台接口
/// </summary>
public IDownloadBackend DownloadBackend { get; }
/// <summary>
/// 下载重试判定策略
/// </summary>
public IDownloadRetryPolicy DownloadRetryPolicy { get; }
/// <summary>
/// URL 选择策略
/// </summary>
public IDownloadUrlPolicy DownloadUrlPolicy { get; }
public Configuration(IWebGamePlatform gamePlatform, int watchdogTimeout, bool disableUnityWebCache,
EFileVerifyLevel downloadVerifyLevel, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor, IRemoteService remoteService,
IDownloadBackend downloadBackend, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy)
{
GamePlatform = gamePlatform;
WatchdogTimeout = watchdogTimeout;
DisableUnityWebCache = disableUnityWebCache;
DownloadVerifyLevel = downloadVerifyLevel;
AssetBundleDecryptor = assetBundleDecryptor;
RawBundleDecryptor = rawBundleDecryptor;
RemoteService = remoteService;
DownloadBackend = downloadBackend;
DownloadRetryPolicy = downloadRetryPolicy;
DownloadUrlPolicy = downloadUrlPolicy;
}
}
/// <summary>
/// 缓存配置
/// </summary>
internal readonly Configuration Config;
#region
/// <inheritdoc/>
public string PackageName { get; }
/// <inheritdoc/>
public string RootPath { get; }
/// <inheritdoc/>
public bool IsReadOnly { get; }
/// <inheritdoc/>
public int FileCount { get; }
/// <inheritdoc/>
public long SpaceOccupied { get; }
#endregion
/// <summary>
/// 创建 WebGameBundleCache 实例
/// </summary>
/// <param name="packageName">包裹名称</param>
/// <param name="rootPath">缓存根目录</param>
/// <param name="config">缓存配置</param>
public WebGameBundleCache(string packageName, string rootPath, Configuration config)
{
PackageName = packageName;
RootPath = rootPath;
Config = config;
IsReadOnly = true;
}
/// <inheritdoc/>
public void Dispose()
{
}
/// <inheritdoc/>
public BCInitializeOperation InitializeAsync()
{
var operation = new WGBCInitializeOperation();
return operation;
}
/// <inheritdoc/>
public BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options)
{
var operation = new BCWriteCacheCompleteOperation($"{nameof(WebGameBundleCache)} is readonly.");
return operation;
}
/// <inheritdoc/>
public BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options)
{
var operation = new BCClearCacheCompleteOperation();
return operation;
}
/// <inheritdoc/>
public BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options)
{
var operation = new BCVerifyCacheCompleteOperation();
return operation;
}
/// <inheritdoc/>
public BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options)
{
if (options.Bundle.GetBundleType() == (int)EBundleType.AssetBundle)
{
var operation = new WGBCLoadAssetBundleOperation(this, options);
return operation;
}
else if (options.Bundle.GetBundleType() == (int)EBundleType.RawBundle)
{
var operation = new WGBCLoadRawBundleOperation(this, options);
return operation;
}
else
{
string error = $"{nameof(WebGameBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}.";
var operation = new BCLoadBundleErrorOperation(error);
return operation;
}
}
/// <inheritdoc/>
public bool IsCached(string bundleGuid)
{
return true;
}
/// <inheritdoc/>
public string GetCacheFilePath(string bundleGuid)
{
YooLogger.LogWarning($"{nameof(WebGameBundleCache)} does not support local cache file path.");
return null;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ddef4533d379a984c8d1669776147acf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: bc4cd72a390c1054a99c49a7c501c8f6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: a466429abacca2f40aacb9ab5a9ffebf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,27 +0,0 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件缓存初始化操作
/// </summary>
internal sealed class WRBCInitializeOperation : BCInitializeOperation
{
private readonly WebRemoteBundleCache _fileCache;
/// <summary>
/// 创建 Web 远端缓存初始化操作实例
/// </summary>
/// <param name="fileCache">Web 远端文件缓存系统</param>
public WRBCInitializeOperation(WebRemoteBundleCache fileCache)
{
_fileCache = fileCache;
}
protected override void InternalStart()
{
SetResult();
}
protected override void InternalUpdate()
{
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 476dbbea577819a43a807f22bb91f974
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,110 +0,0 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件缓存加载 AssetBundle 操作
/// </summary>
internal sealed class WRBCLoadAssetBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
Done,
}
private readonly WebRemoteBundleCache _fileCache;
private readonly BCLoadBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
/// <summary>
/// 创建 WRBCLoadAssetBundleOperation 实例
/// </summary>
/// <param name="fileCache">Web 远端文件缓存系统</param>
/// <param name="options">加载资源包操作选项</param>
public WRBCLoadAssetBundleOperation(WebRemoteBundleCache fileCache, BCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_loadBundleOp == null)
{
var urls = _fileCache.Config.RemoteService.GetRemoteUrls(_options.Bundle.GetFileName());
if (_options.Bundle.IsEncrypted)
{
var encryptedOptions = new LoadWebEncryptedAssetBundleOptions(
cacheName: _fileCache.GetType().Name,
bundle: _options.Bundle,
candidateUrls: urls,
assetBundleDecryptor: _fileCache.Config.AssetBundleDecryptor,
downloadBackend: _fileCache.Config.DownloadBackend,
downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel,
watchdogTimeout: _fileCache.Config.WatchdogTimeout,
downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy,
downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy);
_loadBundleOp = new LoadWebEncryptedAssetBundleOperation(encryptedOptions);
}
else
{
var options = new LoadWebAssetBundleOptions(
cacheName: _fileCache.GetType().Name,
bundle: _options.Bundle,
candidateUrls: urls,
assetBundleDecryptor: _fileCache.Config.AssetBundleDecryptor,
downloadBackend: _fileCache.Config.DownloadBackend,
downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel,
watchdogTimeout: _fileCache.Config.WatchdogTimeout,
disableUnityWebCache: _fileCache.Config.DisableUnityWebCache,
downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy,
downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy);
_loadBundleOp = new LoadWebNormalAssetBundleOperation(options);
}
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
}
_loadBundleOp.UpdateOperation();
Progress = _loadBundleOp.Progress;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadBundleOp.BundleHandle == null)
throw new YooInternalException("Loaded bundle handle is null.");
_steps = ESteps.Done;
SetResult();
BundleHandle = _loadBundleOp.BundleHandle;
}
else
{
_steps = ESteps.Done;
SetError(_loadBundleOp.Error);
}
}
}
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
SetError("WebGL platform does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8821049e94e79ff4b9c83c24e7b10d49
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,85 +0,0 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件缓存加载 RawBundle 操作
/// </summary>
internal sealed class WRBCLoadRawBundleOperation : BCLoadBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
Done,
}
private readonly WebRemoteBundleCache _fileCache;
private readonly BCLoadBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
public WRBCLoadRawBundleOperation(WebRemoteBundleCache fileCache, BCLoadBundleOptions options)
{
_fileCache = fileCache;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_loadBundleOp == null)
{
var urls = _fileCache.Config.RemoteService.GetRemoteUrls(_options.Bundle.GetFileName());
var options = new LoadWebRawBundleOptions(
cacheName: _fileCache.GetType().Name,
bundle: _options.Bundle,
candidateUrls: urls,
rawBundleDecryptor: _fileCache.Config.RawBundleDecryptor,
downloadBackend: _fileCache.Config.DownloadBackend,
downloadVerifyLevel: _fileCache.Config.DownloadVerifyLevel,
watchdogTimeout: _fileCache.Config.WatchdogTimeout,
downloadRetryPolicy: _fileCache.Config.DownloadRetryPolicy,
downloadUrlPolicy: _fileCache.Config.DownloadUrlPolicy);
_loadBundleOp = new LoadWebRawBundleOperation(options);
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
}
_loadBundleOp.UpdateOperation();
Progress = _loadBundleOp.Progress;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadBundleOp.BundleHandle == null)
throw new YooInternalException("Loaded bundle handle is null.");
_steps = ESteps.Done;
SetResult();
BundleHandle = _loadBundleOp.BundleHandle;
}
else
{
_steps = ESteps.Done;
SetError(_loadBundleOp.Error);
}
}
}
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
SetError("WebGL platform does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: bf6535c1839c8b04697179268cda275c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,170 +0,0 @@
using System;
using System.Collections.Generic;
namespace YooAsset
{
/// <summary>
/// Web远端文件缓存系统用于从远程服务器加载资源。
/// </summary>
internal class WebRemoteBundleCache : IBundleCache
{
internal readonly struct Configuration
{
/// <summary>
/// 看门狗超时时间
/// </summary>
public int WatchdogTimeout { get; }
/// <summary>
/// 禁用 Unity 内置网络缓存
/// </summary>
public bool DisableUnityWebCache { get; }
/// <summary>
/// 下载数据校验级别
/// </summary>
public EFileVerifyLevel DownloadVerifyLevel { get; }
/// <summary>
/// AssetBundle 解密器
/// </summary>
public IBundleDecryptor AssetBundleDecryptor { get; }
/// <summary>
/// RawBundle 解密器
/// </summary>
public IBundleDecryptor RawBundleDecryptor { get; }
/// <summary>
/// 远程服务接口
/// </summary>
public IRemoteService RemoteService { get; }
/// <summary>
/// 下载后台接口
/// </summary>
public IDownloadBackend DownloadBackend { get; }
/// <summary>
/// 下载重试判定策略
/// </summary>
public IDownloadRetryPolicy DownloadRetryPolicy { get; }
/// <summary>
/// URL 选择策略
/// </summary>
public IDownloadUrlPolicy DownloadUrlPolicy { get; }
public Configuration(int watchdogTimeout, bool disableUnityWebCache,
EFileVerifyLevel downloadVerifyLevel, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor, IRemoteService remoteService,
IDownloadBackend downloadBackend, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy)
{
WatchdogTimeout = watchdogTimeout;
DisableUnityWebCache = disableUnityWebCache;
DownloadVerifyLevel = downloadVerifyLevel;
AssetBundleDecryptor = assetBundleDecryptor;
RawBundleDecryptor = rawBundleDecryptor;
RemoteService = remoteService;
DownloadBackend = downloadBackend;
DownloadRetryPolicy = downloadRetryPolicy;
DownloadUrlPolicy = downloadUrlPolicy;
}
}
/// <summary>
/// 缓存配置
/// </summary>
internal readonly Configuration Config;
#region
/// <inheritdoc/>
public string PackageName { get; }
/// <inheritdoc/>
public string RootPath { get; }
/// <inheritdoc/>
public bool IsReadOnly { get; }
/// <inheritdoc/>
public int FileCount { get; }
/// <inheritdoc/>
public long SpaceOccupied { get; }
#endregion
/// <summary>
/// 创建 WebRemoteBundleCache 实例
/// </summary>
/// <param name="packageName">包裹名称</param>
/// <param name="rootPath">缓存根目录</param>
/// <param name="config">缓存配置</param>
public WebRemoteBundleCache(string packageName, string rootPath, Configuration config)
{
PackageName = packageName;
RootPath = rootPath;
Config = config;
IsReadOnly = true;
}
/// <inheritdoc />
public void Dispose()
{
}
/// <inheritdoc />
public BCInitializeOperation InitializeAsync()
{
var operation = new WRBCInitializeOperation(this);
return operation;
}
/// <inheritdoc />
public BCWriteCacheOperation WriteCacheAsync(BCWriteCacheOptions options)
{
var operation = new BCWriteCacheCompleteOperation($"{nameof(WebRemoteBundleCache)} is readonly.");
return operation;
}
/// <inheritdoc />
public BCClearCacheOperation ClearCacheAsync(BCClearCacheOptions options)
{
var operation = new BCClearCacheCompleteOperation();
return operation;
}
/// <inheritdoc />
public BCVerifyCacheOperation VerifyCacheAsync(BCVerifyCacheOptions options)
{
var operation = new BCVerifyCacheCompleteOperation();
return operation;
}
/// <inheritdoc />
public BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options)
{
if (options.Bundle.GetBundleType() == (int)EBundleType.AssetBundle)
{
var operation = new WRBCLoadAssetBundleOperation(this, options);
return operation;
}
else if (options.Bundle.GetBundleType() == (int)EBundleType.RawBundle)
{
var operation = new WRBCLoadRawBundleOperation(this, options);
return operation;
}
else
{
string error = $"{nameof(WebRemoteBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}.";
var operation = new BCLoadBundleErrorOperation(error);
return operation;
}
}
/// <inheritdoc />
public bool IsCached(string bundleGuid)
{
return true;
}
/// <inheritdoc />
public string GetCacheFilePath(string bundleGuid)
{
YooLogger.LogWarning($"{nameof(WebRemoteBundleCache)} does not support local cache file path.");
return null;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ebc556c0bb6cbe146a502e678761ace1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: a5e19370caf42414f91a17249c63b190
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,68 +0,0 @@
using UnityEngine;
using UnityEngine.SceneManagement;
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台 AssetBundle 资源包句柄
/// </summary>
internal sealed class WebGameAssetBundleHandle : IBundleHandle
{
private readonly PackageBundle _packageBundle;
private readonly AssetBundle _assetBundle;
private readonly IWebGamePlatform _platform;
/// <summary>
/// 创建 WebGameAssetBundleHandle 实例
/// </summary>
/// <param name="packageBundle">资源包描述</param>
/// <param name="assetBundle">已加载的 AssetBundle 对象</param>
/// <param name="platform">平台实现</param>
public WebGameAssetBundleHandle(PackageBundle packageBundle, AssetBundle assetBundle, IWebGamePlatform platform)
{
_packageBundle = packageBundle;
_assetBundle = assetBundle;
_platform = platform;
}
/// <inheritdoc/>
public void UnloadBundle()
{
if (_assetBundle != null)
{
if (_packageBundle.IsEncrypted)
_assetBundle.Unload(true);
else
_platform.UnloadAssetBundle(_assetBundle, true);
}
}
/// <inheritdoc/>
public BHLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
{
var operation = new ABHLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
/// <inheritdoc/>
public BHLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
{
var operation = new ABHLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
/// <inheritdoc/>
public BHLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
{
var operation = new ABHLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
return operation;
}
/// <inheritdoc/>
public BHLoadSceneOperation LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool allowSceneActivation)
{
var operation = new ABHLoadSceneOperation(assetInfo, loadSceneParams, allowSceneActivation);
return operation;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 37bcfc042801ba74e89e44d47732eb47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -88,13 +88,31 @@ namespace YooAsset
}
/// <summary>
/// v2.3 WebRemote 文件系统入口
/// WebRemote 文件系统入口,转发到 WebNetwork 文件系统
/// </summary>
[Obsolete("Use CreateDefaultWebRemoteFileSystemParameters(IRemoteService, bool) instead. IWebDecryptionServices is no longer supported.")]
[Obsolete("Use CreateDefaultWebNetworkFileSystemParameters instead.")]
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteService remoteService, bool disableUnityWebCache)
{
return CreateDefaultWebNetworkFileSystemParameters(remoteService, disableUnityWebCache);
}
/// <summary>
/// WebRemote 文件系统入口,转发到 WebNetwork 文件系统
/// </summary>
[Obsolete("Use CreateDefaultWebNetworkFileSystemParameters instead.")]
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteService remoteService)
{
return CreateDefaultWebNetworkFileSystemParameters(remoteService);
}
/// <summary>
/// v2.3 WebRemote 文件系统入口,转发到 WebNetwork 文件系统
/// </summary>
[Obsolete("Use CreateDefaultWebNetworkFileSystemParameters(IRemoteService, bool) instead. IWebDecryptionServices is no longer supported.")]
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, IWebDecryptionServices decryptionServices = null, bool disableUnityWebCache = false)
{
var adapter = remoteServices != null ? new RemoteServicesAdapter(remoteServices) : null;
return CreateDefaultWebRemoteFileSystemParameters(adapter, disableUnityWebCache);
return CreateDefaultWebNetworkFileSystemParameters(adapter, disableUnityWebCache);
}
}

View File

@@ -71,7 +71,7 @@ namespace YooAsset
options.AutoUnloadBundleWhenUnused = wpp.AutoUnloadBundleWhenUnused;
options.WebGLForceSyncLoadAsset = wpp.WebGLForceSyncLoadAsset;
options.WebServerFileSystemParameters = wpp.WebServerFileSystemParameters;
options.WebRemoteFileSystemParameters = wpp.WebRemoteFileSystemParameters;
options.WebNetworkFileSystemParameters = wpp.WebRemoteFileSystemParameters;
var operation = InitializePackageAsync(options);
var wrapper = new InitializationOperation(operation);
AsyncOperationSystem.StartOperation(PackageName, wrapper);

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 955bc3e522742f04297343174a663fd6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,44 +0,0 @@
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台 AssetBundle 下载器
/// </summary>
/// <remarks>
/// 创建平台专用请求并提取 AssetBundle 对象
/// </remarks>
internal sealed class WebGameAssetBundleRequest : UnityWebRequestBase, IDownloadAssetBundleRequest
{
private readonly IWebGamePlatform _platform;
/// <summary>
/// 下载结果AssetBundle 对象)
/// </summary>
public AssetBundle Result { get; private set; }
/// <summary>
/// 构造 AssetBundle 下载器
/// </summary>
/// <param name="requestArgs">公共请求参数</param>
/// <param name="platform">游戏平台接口</param>
public WebGameAssetBundleRequest(DownloadRequestArgs requestArgs, IWebGamePlatform platform)
: base(requestArgs, null)
{
_platform = platform;
}
protected override UnityWebRequest CreateWebRequest()
{
var request = _platform.CreateAssetBundleRequest(Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
protected override void OnRequestSucceeded(UnityWebRequest webRequest)
{
Result = _platform.ExtractAssetBundle(webRequest);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: be6bed6a8d321cd46a34235142571329
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,32 +0,0 @@
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台接口
/// </summary>
internal interface IWebGamePlatform
{
/// <summary>
/// 创建平台专用的 AssetBundle 下载请求
/// </summary>
/// <param name="url">资源包的远程地址</param>
/// <returns>已配置的 UnityWebRequest 实例</returns>
UnityWebRequest CreateAssetBundleRequest(string url);
/// <summary>
/// 从已完成的请求中提取 AssetBundle 对象
/// </summary>
/// <param name="request">已完成下载的 UnityWebRequest</param>
/// <returns>提取到的 AssetBundle若提取失败则返回 null。</returns>
AssetBundle ExtractAssetBundle(UnityWebRequest request);
/// <summary>
/// 使用平台专用 API 卸载 AssetBundle
/// </summary>
/// <param name="assetBundle">待卸载的 AssetBundle 实例</param>
/// <param name="unloadAll">是否同时卸载所有已加载的资源对象</param>
void UnloadAssetBundle(AssetBundle assetBundle, bool unloadAll);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 7e41f9ae5af23084296179220c99ee37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ecc61a05185e16f4082069f3d4976a16
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 6f59bbfac9d9e6f4987496e16bae8b22
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,96 +0,0 @@
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台文件系统初始化操作
/// </summary>
internal sealed class WGFSInitializeOperation : FSInitializeOperation
{
private enum ESteps
{
None,
CheckPlatform,
CheckParameter,
InitializeBundleCache,
Done,
}
private readonly WebGameFileSystem _fileSystem;
private BCInitializeOperation _initializeBundleCacheOp;
private ESteps _steps = ESteps.None;
internal WGFSInitializeOperation(WebGameFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
protected override void InternalStart()
{
_steps = ESteps.CheckPlatform;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckPlatform)
{
#if !UNITY_WEBGL
_steps = ESteps.Done;
SetError($"{nameof(WebGameFileSystem)} only supports the WebGL platform.");
#else
_steps = ESteps.CheckParameter;
#endif
}
if (_steps == ESteps.CheckParameter)
{
if (_fileSystem.RemoteService == null)
{
_steps = ESteps.Done;
SetError($"{nameof(IRemoteService)} is null.");
return;
}
// 检查URL双斜杠
// 注意:双斜杠会导致某小游戏平台加载文件失败,但网络请求又不返回失败!
var testUrls = _fileSystem.RemoteService.GetRemoteUrls("test.bundle");
foreach (var url in testUrls)
{
if (PathUtility.ContainsDoubleSlashes(url))
{
_steps = ESteps.Done;
SetError($"{nameof(IRemoteService)} returned URL contains double slashes: '{url}'.");
return;
}
}
_steps = ESteps.InitializeBundleCache;
}
if (_steps == ESteps.InitializeBundleCache)
{
if (_initializeBundleCacheOp == null)
{
_initializeBundleCacheOp = _fileSystem.BundleCache.InitializeAsync();
_initializeBundleCacheOp.StartOperation();
AddChildOperation(_initializeBundleCacheOp);
}
_initializeBundleCacheOp.UpdateOperation();
Progress = _initializeBundleCacheOp.Progress;
if (_initializeBundleCacheOp.IsDone == false)
return;
if (_initializeBundleCacheOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
SetResult();
}
else
{
_steps = ESteps.Done;
SetError(_initializeBundleCacheOp.Error);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4c67db74d2670a84abf48b4b3dad3227
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,79 +0,0 @@
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台加载资源包操作
/// </summary>
internal sealed class WGFSLoadPackageBundleOperation : FSLoadPackageBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
Done,
}
private readonly WebGameFileSystem _fileSystem;
private readonly FSLoadPackageBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
internal WGFSLoadPackageBundleOperation(WebGameFileSystem fileSystem, FSLoadPackageBundleOptions options)
{
_fileSystem = fileSystem;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_loadBundleOp == null)
{
_loadBundleOp = _fileSystem.BundleCache.LoadBundleAsync(_options.ConvertTo());
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
}
_loadBundleOp.UpdateOperation();
Progress = _loadBundleOp.Progress;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadBundleOp.BundleHandle == null)
{
_steps = ESteps.Done;
SetError("Fatal error: loaded bundle handle is null.");
}
else
{
_steps = ESteps.Done;
SetResult();
BundleHandle = _loadBundleOp.BundleHandle;
}
}
else
{
_steps = ESteps.Done;
SetError(_loadBundleOp.Error);
}
}
}
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
SetError("WebGL platform does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4330e6c76bd8f6146bdba6c5b6715469
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,106 +0,0 @@
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台加载包裹清单操作
/// </summary>
internal sealed class WGFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
{
private enum ESteps
{
None,
RequestPackageHash,
LoadPackageManifest,
Done,
}
private readonly WebGameFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly int _timeout;
private RequestWebPackageHashOperation _requestWebPackageHashOp;
private LoadWebPackageManifestOperation _loadWebPackageManifestOp;
private ESteps _steps = ESteps.None;
internal WGFSLoadPackageManifestOperation(WebGameFileSystem fileSystem, string packageVersion, int timeout)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
protected override void InternalStart()
{
_steps = ESteps.RequestPackageHash;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageHash)
{
if (_requestWebPackageHashOp == null)
{
var options = new RequestWebPackageHashOptions(
packageName: _fileSystem.PackageName,
packageVersion: _packageVersion,
timeout: _timeout,
remoteService: _fileSystem.RemoteService,
downloadBackend: _fileSystem.DownloadBackend,
downloadUrlPolicy: _fileSystem.DownloadUrlPolicy);
_requestWebPackageHashOp = new RequestWebPackageHashOperation(options);
_requestWebPackageHashOp.StartOperation();
AddChildOperation(_requestWebPackageHashOp);
}
_requestWebPackageHashOp.UpdateOperation();
if (_requestWebPackageHashOp.IsDone == false)
return;
if (_requestWebPackageHashOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.LoadPackageManifest;
}
else
{
_steps = ESteps.Done;
SetError(_requestWebPackageHashOp.Error);
}
}
if (_steps == ESteps.LoadPackageManifest)
{
if (_loadWebPackageManifestOp == null)
{
var options = new LoadWebPackageManifestOptions(
packageName: _fileSystem.PackageName,
packageVersion: _packageVersion,
packageHash: _requestWebPackageHashOp.PackageHash,
timeout: _timeout,
remoteService: _fileSystem.RemoteService,
manifestDecryptor: _fileSystem.ManifestDecryptor,
downloadBackend: _fileSystem.DownloadBackend,
downloadUrlPolicy: _fileSystem.DownloadUrlPolicy);
_loadWebPackageManifestOp = new LoadWebPackageManifestOperation(options);
_loadWebPackageManifestOp.StartOperation();
AddChildOperation(_loadWebPackageManifestOp);
}
_loadWebPackageManifestOp.UpdateOperation();
Progress = _loadWebPackageManifestOp.Progress;
if (_loadWebPackageManifestOp.IsDone == false)
return;
if (_loadWebPackageManifestOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
Manifest = _loadWebPackageManifestOp.Manifest;
SetResult();
}
else
{
_steps = ESteps.Done;
SetError(_loadWebPackageManifestOp.Error);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 94158cfc4223d4f4ca4883d097aad775
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,71 +0,0 @@
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台请求包裹版本操作
/// </summary>
internal sealed class WGFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
RequestPackageVersion,
Done,
}
private readonly WebGameFileSystem _fileSystem;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private RequestWebPackageVersionOperation _requestWebPackageVersionOp;
private ESteps _steps = ESteps.None;
internal WGFSRequestPackageVersionOperation(WebGameFileSystem fileSystem, bool appendTimeTicks, int timeout)
{
_fileSystem = fileSystem;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
protected override void InternalStart()
{
_steps = ESteps.RequestPackageVersion;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageVersion)
{
if (_requestWebPackageVersionOp == null)
{
var options = new RequestWebPackageVersionOptions(
packageName: _fileSystem.PackageName,
appendTimeTicks: _appendTimeTicks,
timeout: _timeout,
remoteService: _fileSystem.RemoteService,
downloadBackend: _fileSystem.DownloadBackend,
downloadUrlPolicy: _fileSystem.DownloadUrlPolicy);
_requestWebPackageVersionOp = new RequestWebPackageVersionOperation(options);
_requestWebPackageVersionOp.StartOperation();
AddChildOperation(_requestWebPackageVersionOp);
}
_requestWebPackageVersionOp.UpdateOperation();
Progress = _requestWebPackageVersionOp.Progress;
if (_requestWebPackageVersionOp.IsDone == false)
return;
if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
PackageVersion = _requestWebPackageVersionOp.PackageVersion;
SetResult();
}
else
{
_steps = ESteps.Done;
SetError(_requestWebPackageVersionOp.Error);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 82b50b3ee5b8b114697a65275691f883
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,253 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
/// <summary>
/// WebGL 游戏平台文件系统抽象基类,封装各小游戏平台的公共逻辑
/// </summary>
internal abstract class WebGameFileSystem : IFileSystem
{
/// <summary>
/// 平台实现实例
/// </summary>
internal IWebGamePlatform Platform { get; private set; }
/// <summary>
/// 缓存系统
/// </summary>
public IBundleCache BundleCache { get; private set; }
/// <summary>
/// 下载后台接口
/// </summary>
public IDownloadBackend DownloadBackend { get; private set; }
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName { get; private set; }
#region
/// <summary>
/// 自定义参数:禁用 Unity 内置网络缓存
/// </summary>
public bool DisableUnityWebCache { get; private set; } = true;
/// <summary>
/// 自定义参数:下载看门狗超时时间(秒)
/// </summary>
public int DownloadWatchdogTimeout { get; private set; } = 0;
/// <summary>
/// 自定义参数:下载数据校验级别
/// </summary>
public EFileVerifyLevel DownloadVerifyLevel { get; private set; } = EFileVerifyLevel.Middle;
/// <summary>
/// 自定义参数:远端资源服务
/// </summary>
public IRemoteService RemoteService { get; private set; }
/// <summary>
/// 自定义参数:资源包解密器
/// </summary>
public IBundleDecryptor AssetBundleDecryptor { get; private set; }
/// <summary>
/// 自定义参数RawBundle 解密器
/// </summary>
public IBundleDecryptor RawBundleDecryptor { get; private set; }
/// <summary>
/// 自定义参数:资源清单解密器
/// </summary>
public IManifestDecryptor ManifestDecryptor { get; private set; }
/// <summary>
/// 自定义参数:下载重试策略
/// </summary>
public IDownloadRetryPolicy DownloadRetryPolicy { get; private set; }
/// <summary>
/// 自定义参数URL 选择策略
/// </summary>
public IDownloadUrlPolicy DownloadUrlPolicy { get; private set; }
#endregion
/// <inheritdoc />
public virtual FSInitializeOperation InitializeAsync()
{
var operation = new WGFSInitializeOperation(this);
return operation;
}
/// <inheritdoc />
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(FSRequestPackageVersionOptions options)
{
var operation = new WGFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout);
return operation;
}
/// <inheritdoc />
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(FSLoadPackageManifestOptions options)
{
var operation = new WGFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
return operation;
}
/// <inheritdoc />
public virtual FSLoadPackageBundleOperation LoadPackageBundleAsync(FSLoadPackageBundleOptions options)
{
var operation = new WGFSLoadPackageBundleOperation(this, options);
return operation;
}
/// <inheritdoc />
public virtual FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
{
var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebGameFileSystem)} does not support ensure bundle file operation.");
return operation;
}
/// <inheritdoc />
public virtual FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
{
var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebGameFileSystem)} does not support download operation.");
return operation;
}
/// <inheritdoc />
public virtual FSClearCacheOperation ClearCacheAsync(FSClearCacheOptions options)
{
var operation = new FSClearCacheCompleteOperation();
return operation;
}
/// <inheritdoc />
public virtual void SetParameter(string paramName, object value)
{
if (paramName == nameof(EFileSystemParameter.DownloadBackend))
{
DownloadBackend = FileSystemHelper.CastParameter<IDownloadBackend>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DisableUnityWebCache))
{
DisableUnityWebCache = FileSystemHelper.CastParameter<bool>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DownloadWatchdogTimeout))
{
int convertValue = FileSystemHelper.CastParameter<int>(paramName, value);
DownloadWatchdogTimeout = Mathf.Max(convertValue, 0);
}
else if (paramName == nameof(EFileSystemParameter.FileVerifyLevel))
{
DownloadVerifyLevel = FileSystemHelper.CastParameter<EFileVerifyLevel>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.RemoteService))
{
RemoteService = FileSystemHelper.CastParameter<IRemoteService>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.AssetbundleDecryptor))
{
AssetBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.RawbundleDecryptor))
{
RawBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.ManifestDecryptor))
{
ManifestDecryptor = FileSystemHelper.CastParameter<IManifestDecryptor>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DownloadRetryPolicy))
{
DownloadRetryPolicy = FileSystemHelper.CastParameter<IDownloadRetryPolicy>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DownloadUrlPolicy))
{
DownloadUrlPolicy = FileSystemHelper.CastParameter<IDownloadUrlPolicy>(paramName, value);
}
else
{
throw new ArgumentException($"Unrecognized parameter name: '{paramName}'.", nameof(paramName));
}
}
/// <inheritdoc />
public virtual void OnCreate(string packageName, string packageRoot)
{
PackageName = packageName;
if (string.IsNullOrEmpty(packageRoot))
{
throw new ArgumentException("The package root for mini game cache must be configured.", nameof(packageRoot));
}
// 创建默认的下载后台接口
if (DownloadBackend == null)
DownloadBackend = new UnityWebRequestBackend();
// 创建默认的下载重试策略
if (DownloadRetryPolicy == null)
DownloadRetryPolicy = new DefaultDownloadRetryPolicy();
// 创建默认的 URL 选择策略
if (DownloadUrlPolicy == null)
DownloadUrlPolicy = new DefaultDownloadUrlPolicy();
// 创建Web游戏缓存系统
Platform = CreatePlatform(packageRoot);
var cacheConfig = new WebGameBundleCache.Configuration(
gamePlatform: Platform,
watchdogTimeout: DownloadWatchdogTimeout,
disableUnityWebCache: DisableUnityWebCache,
downloadVerifyLevel: DownloadVerifyLevel,
assetBundleDecryptor: AssetBundleDecryptor,
rawBundleDecryptor: RawBundleDecryptor,
remoteService: RemoteService,
downloadBackend: DownloadBackend,
downloadRetryPolicy: DownloadRetryPolicy,
downloadUrlPolicy: DownloadUrlPolicy);
BundleCache = new WebGameBundleCache(packageName, packageRoot, cacheConfig);
}
/// <inheritdoc />
public virtual void OnDestroy()
{
if (BundleCache != null)
{
BundleCache.Dispose();
BundleCache = null;
}
if (DownloadBackend != null)
{
DownloadBackend.Dispose();
DownloadBackend = null;
}
}
/// <inheritdoc />
public virtual bool CanAcceptBundle(PackageBundle bundle)
{
// 注意:保底加载!
return true;
}
/// <inheritdoc />
public virtual bool IsDownloadRequired(PackageBundle bundle)
{
return false;
}
/// <inheritdoc />
public virtual bool IsUnpackRequired(PackageBundle bundle)
{
return false;
}
/// <inheritdoc />
public virtual bool IsImportRequired(PackageBundle bundle)
{
return false;
}
/// <summary>
/// 创建平台实现实例
/// </summary>
/// <param name="packageRoot">包裹缓存根目录</param>
/// <returns>平台实现实例</returns>
protected abstract IWebGamePlatform CreatePlatform(string packageRoot);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 593436dc827a65c4a81aff2d7805db07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 2bf1355f3cbe3d543b53bd9553bba02c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 1086ea45b8b84fe43ba1ef69b4f813dc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,84 +0,0 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件系统的初始化操作
/// </summary>
internal sealed class WRFSInitializeOperation : FSInitializeOperation
{
private enum ESteps
{
None,
CheckPlatform,
CheckParameter,
InitializeBundleCache,
Done,
}
private readonly WebRemoteFileSystem _fileSystem;
private BCInitializeOperation _initializeBundleCacheOp;
private ESteps _steps = ESteps.None;
public WRFSInitializeOperation(WebRemoteFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
protected override void InternalStart()
{
_steps = ESteps.CheckPlatform;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckPlatform)
{
#if !UNITY_WEBGL
_steps = ESteps.Done;
SetError($"{nameof(WebRemoteFileSystem)} only supports the WebGL platform.");
#else
_steps = ESteps.CheckParameter;
#endif
}
if (_steps == ESteps.CheckParameter)
{
if (_fileSystem.RemoteService == null)
{
_steps = ESteps.Done;
SetError($"{nameof(IRemoteService)} is null.");
return;
}
_steps = ESteps.InitializeBundleCache;
}
if (_steps == ESteps.InitializeBundleCache)
{
if (_initializeBundleCacheOp == null)
{
_initializeBundleCacheOp = _fileSystem.BundleCache.InitializeAsync();
_initializeBundleCacheOp.StartOperation();
AddChildOperation(_initializeBundleCacheOp);
}
_initializeBundleCacheOp.UpdateOperation();
Progress = _initializeBundleCacheOp.Progress;
if (_initializeBundleCacheOp.IsDone == false)
return;
if (_initializeBundleCacheOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
SetResult();
}
else
{
_steps = ESteps.Done;
SetError(_initializeBundleCacheOp.Error);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f30b92e4f3b9e594ca0481128b56cc21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,80 +0,0 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件系统的加载资源包操作
/// </summary>
internal sealed class WRFSLoadPackageBundleOperation : FSLoadPackageBundleOperation
{
private enum ESteps
{
None,
LoadBundle,
Done,
}
private readonly WebRemoteFileSystem _fileSystem;
private readonly FSLoadPackageBundleOptions _options;
private BCLoadBundleOperation _loadBundleOp;
private ESteps _steps = ESteps.None;
internal WRFSLoadPackageBundleOperation(WebRemoteFileSystem fileSystem, FSLoadPackageBundleOptions options)
{
_fileSystem = fileSystem;
_options = options;
}
protected override void InternalStart()
{
_steps = ESteps.LoadBundle;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBundle)
{
if (_loadBundleOp == null)
{
_loadBundleOp = _fileSystem.BundleCache.LoadBundleAsync(_options.ConvertTo());
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
}
_loadBundleOp.UpdateOperation();
Progress = _loadBundleOp.Progress;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeeded)
{
if (_loadBundleOp.BundleHandle == null)
{
_steps = ESteps.Done;
SetError("Fatal error: loaded bundle handle is null.");
}
else
{
_steps = ESteps.Done;
SetResult();
BundleHandle = _loadBundleOp.BundleHandle;
}
}
else
{
_steps = ESteps.Done;
SetError(_loadBundleOp.Error);
}
}
}
protected override void InternalWaitForCompletion()
{
if (_steps != ESteps.Done)
{
_steps = ESteps.Done;
SetError("WebGL platform does not support synchronous loading.");
YooLogger.LogError(Error);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 270b776fd379b0f45bc602c845720733
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,108 +0,0 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件系统的加载包裹清单操作
/// </summary>
internal sealed class WRFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
{
private enum ESteps
{
None,
RequestPackageHash,
LoadPackageManifest,
Done,
}
private readonly WebRemoteFileSystem _fileSystem;
private readonly string _packageVersion;
private readonly int _timeout;
private RequestWebPackageHashOperation _requestWebPackageHashOp;
private LoadWebPackageManifestOperation _loadWebPackageManifestOp;
private ESteps _steps = ESteps.None;
public WRFSLoadPackageManifestOperation(WebRemoteFileSystem fileSystem, string packageVersion, int timeout)
{
_fileSystem = fileSystem;
_packageVersion = packageVersion;
_timeout = timeout;
}
protected override void InternalStart()
{
_steps = ESteps.RequestPackageHash;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageHash)
{
if (_requestWebPackageHashOp == null)
{
var options = new RequestWebPackageHashOptions(
packageName: _fileSystem.PackageName,
packageVersion: _packageVersion,
timeout: _timeout,
remoteService: _fileSystem.RemoteService,
downloadBackend: _fileSystem.DownloadBackend,
downloadUrlPolicy: _fileSystem.DownloadUrlPolicy);
_requestWebPackageHashOp = new RequestWebPackageHashOperation(options);
_requestWebPackageHashOp.StartOperation();
AddChildOperation(_requestWebPackageHashOp);
}
_requestWebPackageHashOp.UpdateOperation();
if (_requestWebPackageHashOp.IsDone == false)
return;
if (_requestWebPackageHashOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.LoadPackageManifest;
}
else
{
_steps = ESteps.Done;
SetError(_requestWebPackageHashOp.Error);
}
}
if (_steps == ESteps.LoadPackageManifest)
{
if (_loadWebPackageManifestOp == null)
{
var options = new LoadWebPackageManifestOptions(
packageName: _fileSystem.PackageName,
packageVersion: _packageVersion,
packageHash: _requestWebPackageHashOp.PackageHash,
timeout: _timeout,
remoteService: _fileSystem.RemoteService,
manifestDecryptor: _fileSystem.ManifestDecryptor,
downloadBackend: _fileSystem.DownloadBackend,
downloadUrlPolicy: _fileSystem.DownloadUrlPolicy);
_loadWebPackageManifestOp = new LoadWebPackageManifestOperation(options);
_loadWebPackageManifestOp.StartOperation();
AddChildOperation(_loadWebPackageManifestOp);
}
_loadWebPackageManifestOp.UpdateOperation();
Progress = _loadWebPackageManifestOp.Progress;
if (_loadWebPackageManifestOp.IsDone == false)
return;
if (_loadWebPackageManifestOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
Manifest = _loadWebPackageManifestOp.Manifest;
SetResult();
}
else
{
_steps = ESteps.Done;
SetError(_loadWebPackageManifestOp.Error);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 2611f6fbc97de1a4d9a38116045d4faf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,73 +0,0 @@
namespace YooAsset
{
/// <summary>
/// Web远端文件系统的查询包裹版本操作
/// </summary>
internal sealed class WRFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
{
private enum ESteps
{
None,
RequestPackageVersion,
Done,
}
private readonly WebRemoteFileSystem _fileSystem;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private RequestWebPackageVersionOperation _requestWebPackageVersionOp;
private ESteps _steps = ESteps.None;
internal WRFSRequestPackageVersionOperation(WebRemoteFileSystem fileSystem, bool appendTimeTicks, int timeout)
{
_fileSystem = fileSystem;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
protected override void InternalStart()
{
_steps = ESteps.RequestPackageVersion;
}
protected override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.RequestPackageVersion)
{
if (_requestWebPackageVersionOp == null)
{
var options = new RequestWebPackageVersionOptions(
packageName: _fileSystem.PackageName,
appendTimeTicks: _appendTimeTicks,
timeout: _timeout,
remoteService: _fileSystem.RemoteService,
downloadBackend: _fileSystem.DownloadBackend,
downloadUrlPolicy: _fileSystem.DownloadUrlPolicy);
_requestWebPackageVersionOp = new RequestWebPackageVersionOperation(options);
_requestWebPackageVersionOp.StartOperation();
AddChildOperation(_requestWebPackageVersionOp);
}
_requestWebPackageVersionOp.UpdateOperation();
Progress = _requestWebPackageVersionOp.Progress;
if (_requestWebPackageVersionOp.IsDone == false)
return;
if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeeded)
{
_steps = ESteps.Done;
PackageVersion = _requestWebPackageVersionOp.PackageVersion;
SetResult();
}
else
{
_steps = ESteps.Done;
SetError(_requestWebPackageVersionOp.Error);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d1c5335974b2432458ed902e20cc954e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,249 +0,0 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
/// <summary>
/// Web远端文件系统管理 WebRemote 平台的远程文件系统访问。
/// </summary>
internal class WebRemoteFileSystem : IFileSystem
{
/// <summary>
/// Web 文件缓存系统
/// </summary>
public IBundleCache BundleCache { get; private set; }
/// <summary>
/// 下载后台接口
/// </summary>
public IDownloadBackend DownloadBackend { get; private set; }
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName { get; private set; }
#region
/// <summary>
/// 自定义参数UnityWebRequest 创建委托
/// </summary>
public UnityWebRequestCreator WebRequestCreator { get; private set; }
/// <summary>
/// 自定义参数:禁用 Unity 内置网络缓存
/// </summary>
public bool DisableUnityWebCache { get; private set; } = false;
/// <summary>
/// 自定义参数:下载任务的看门狗机制超时时间
/// </summary>
public int DownloadWatchdogTimeout { get; private set; } = 0;
/// <summary>
/// 自定义参数:下载的资源包数据的校验级别
/// </summary>
public EFileVerifyLevel DownloadVerifyLevel { get; private set; } = EFileVerifyLevel.Middle;
/// <summary>
/// 支持跨域下载的远程服务接口实例
/// </summary>
public IRemoteService RemoteService { get; private set; }
/// <summary>
/// 自定义参数AssetBundle 解密器
/// </summary>
public IBundleDecryptor AssetBundleDecryptor { get; private set; }
/// <summary>
/// 自定义参数RawBundle 解密器
/// </summary>
public IBundleDecryptor RawBundleDecryptor { get; private set; }
/// <summary>
/// 自定义参数:资源清单解密器
/// </summary>
public IManifestDecryptor ManifestDecryptor { get; private set; }
/// <summary>
/// 自定义参数:下载重试判定策略
/// </summary>
public IDownloadRetryPolicy DownloadRetryPolicy { get; private set; }
/// <summary>
/// 自定义参数URL 选择策略
/// </summary>
public IDownloadUrlPolicy DownloadUrlPolicy { get; private set; }
#endregion
/// <summary>
/// 创建实例
/// </summary>
public WebRemoteFileSystem()
{
}
/// <inheritdoc />
public FSInitializeOperation InitializeAsync()
{
var operation = new WRFSInitializeOperation(this);
return operation;
}
/// <inheritdoc />
public FSRequestPackageVersionOperation RequestPackageVersionAsync(FSRequestPackageVersionOptions options)
{
var operation = new WRFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout);
return operation;
}
/// <inheritdoc />
public FSLoadPackageManifestOperation LoadPackageManifestAsync(FSLoadPackageManifestOptions options)
{
var operation = new WRFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
return operation;
}
/// <inheritdoc />
public FSLoadPackageBundleOperation LoadPackageBundleAsync(FSLoadPackageBundleOptions options)
{
var operation = new WRFSLoadPackageBundleOperation(this, options);
return operation;
}
/// <inheritdoc />
public FSEnsurePackageBundleOperation EnsurePackageBundleAsync(FSEnsurePackageBundleOptions options)
{
var operation = new FSEnsurePackageBundleFailureOperation($"{nameof(WebRemoteFileSystem)} does not support ensure bundle file operation.");
return operation;
}
/// <inheritdoc />
public FSDownloadBundleOperation DownloadBundleAsync(FSDownloadBundleOptions options)
{
var operation = new FSDownloadBundleCompleteOperation($"{nameof(WebRemoteFileSystem)} does not support download operation.");
return operation;
}
/// <inheritdoc />
public FSClearCacheOperation ClearCacheAsync(FSClearCacheOptions options)
{
var operation = new FSClearCacheCompleteOperation();
return operation;
}
/// <inheritdoc />
public void SetParameter(string paramName, object value)
{
if (paramName == nameof(EFileSystemParameter.DownloadBackend))
{
DownloadBackend = FileSystemHelper.CastParameter<IDownloadBackend>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.UnityWebRequestCreator))
{
WebRequestCreator = FileSystemHelper.CastParameter<UnityWebRequestCreator>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DisableUnityWebCache))
{
DisableUnityWebCache = FileSystemHelper.CastParameter<bool>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DownloadWatchdogTimeout))
{
int convertValue = FileSystemHelper.CastParameter<int>(paramName, value);
DownloadWatchdogTimeout = Mathf.Max(convertValue, 0);
}
else if (paramName == nameof(EFileSystemParameter.FileVerifyLevel))
{
DownloadVerifyLevel = FileSystemHelper.CastParameter<EFileVerifyLevel>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.RemoteService))
{
RemoteService = FileSystemHelper.CastParameter<IRemoteService>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.AssetbundleDecryptor))
{
AssetBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.RawbundleDecryptor))
{
RawBundleDecryptor = FileSystemHelper.CastParameter<IBundleDecryptor>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.ManifestDecryptor))
{
ManifestDecryptor = FileSystemHelper.CastParameter<IManifestDecryptor>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DownloadRetryPolicy))
{
DownloadRetryPolicy = FileSystemHelper.CastParameter<IDownloadRetryPolicy>(paramName, value);
}
else if (paramName == nameof(EFileSystemParameter.DownloadUrlPolicy))
{
DownloadUrlPolicy = FileSystemHelper.CastParameter<IDownloadUrlPolicy>(paramName, value);
}
else
{
throw new ArgumentException($"Unrecognized parameter name: '{paramName}'.", nameof(paramName));
}
}
/// <inheritdoc />
public void OnCreate(string packageName, string packageRoot)
{
PackageName = packageName;
// 创建默认的下载后台接口
if (DownloadBackend == null)
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
// 创建默认的下载重试策略
if (DownloadRetryPolicy == null)
DownloadRetryPolicy = new DefaultDownloadRetryPolicy();
// 创建默认的 URL 选择策略
if (DownloadUrlPolicy == null)
DownloadUrlPolicy = new DefaultDownloadUrlPolicy();
// 创建Web文件缓存系统
var cacheConfig = new WebRemoteBundleCache.Configuration(
watchdogTimeout: DownloadWatchdogTimeout,
disableUnityWebCache: DisableUnityWebCache,
downloadVerifyLevel: DownloadVerifyLevel,
assetBundleDecryptor: AssetBundleDecryptor,
rawBundleDecryptor: RawBundleDecryptor,
remoteService: RemoteService,
downloadBackend: DownloadBackend,
downloadRetryPolicy: DownloadRetryPolicy,
downloadUrlPolicy: DownloadUrlPolicy);
BundleCache = new WebRemoteBundleCache(packageName, packageRoot, cacheConfig);
}
/// <inheritdoc />
public void OnDestroy()
{
if (BundleCache != null)
{
BundleCache.Dispose();
BundleCache = null;
}
if (DownloadBackend != null)
{
DownloadBackend.Dispose();
DownloadBackend = null;
}
}
/// <inheritdoc />
public bool CanAcceptBundle(PackageBundle bundle)
{
// 注意:保底加载!
return true;
}
/// <inheritdoc />
public bool IsDownloadRequired(PackageBundle bundle)
{
return false;
}
/// <inheritdoc />
public bool IsUnpackRequired(PackageBundle bundle)
{
return false;
}
/// <inheritdoc />
public bool IsImportRequired(PackageBundle bundle)
{
return false;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f511714bfc7c1104aa6200ee0826e9e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,43 +1,32 @@
#if UNITY_WEBGL && UNITY_ALIMINIGAME
using YooAsset;
using AlipaySdk;
public static class AlipayFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(AlipayFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
string fileSystemClass = $"{nameof(AlipayFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
{
string fileSystemClass = $"{nameof(AlipayFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
}
/// <summary>
/// 支付宝小游戏文件系统
/// </summary>
internal class AlipayFileSystem : WebGameFileSystem
{
protected override IWebGamePlatform CreatePlatform(string packageRoot)
private static FileSystemParameters CreateBaseFileSystemParameters(IRemoteService remoteService)
{
return new AlipayPlatform();
var fileSystemParams = FileSystemParameters.CreateDefaultWebNetworkFileSystemParameters(remoteService, true);
fileSystemParams.AddParameter(EFileSystemParameter.WebPlatformStrategy, new AlipayPlatform());
return fileSystemParams;
}
}
#endif

View File

@@ -8,12 +8,14 @@ using AlipaySdk;
/// 支付宝小游戏平台实现
/// 参考https://opendocs.alipay.com/mini-game/
/// </summary>
internal class AlipayPlatform : IWebGamePlatform
internal class AlipayPlatform : IWebPlatformStrategy
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
public UnityWebRequest CreateAssetBundleRequest(WebAssetBundleRequestArgs args)
{
return APAssetBundle.GetAssetBundle(url);
UnityWebRequest request = APAssetBundle.GetAssetBundle(args.Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
/// <inheritdoc/>

View File

@@ -3,41 +3,30 @@ using YooAsset;
public static class KuaiShouFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(KuaiShouFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
string fileSystemClass = $"{nameof(KuaiShouFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
{
string fileSystemClass = $"{nameof(KuaiShouFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
}
/// <summary>
/// 快手小游戏文件系统
/// </summary>
internal class KuaiShouFileSystem : WebGameFileSystem
{
/// <inheritdoc/>
protected override IWebGamePlatform CreatePlatform(string packageRoot)
private static FileSystemParameters CreateBaseFileSystemParameters(IRemoteService remoteService)
{
return new KuaiShouPlatform();
var fileSystemParams = FileSystemParameters.CreateDefaultWebNetworkFileSystemParameters(remoteService, true);
fileSystemParams.AddParameter(EFileSystemParameter.WebPlatformStrategy, new KuaiShouPlatform());
return fileSystemParams;
}
}
#endif

View File

@@ -7,12 +7,14 @@ using KSWASM;
/// <summary>
/// 快手小游戏平台实现
/// </summary>
internal class KuaiShouPlatform : IWebGamePlatform
internal class KuaiShouPlatform : IWebPlatformStrategy
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
public UnityWebRequest CreateAssetBundleRequest(WebAssetBundleRequestArgs args)
{
return KSAssetBundle.GetAssetBundle(url);
UnityWebRequest request = KSAssetBundle.GetAssetBundle(args.Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
/// <inheritdoc/>

View File

@@ -26,17 +26,16 @@ var createParameters = new WebPlayModeOptions();
string defaultHostServer = GetHostServerURL();
string fallbackHostServer = GetHostServerURL();
string packageRoot = "/__GAME_FILE_CACHE";
IRemoteService remoteService = new RemoteService(defaultHostServer, fallbackHostServer);
createParameters.WebServerFileSystemParameters =
KuaiShouFileSystemCreater.CreateFileSystemParameters(packageRoot, remoteService);
KuaiShouFileSystemCreater.CreateFileSystemParameters(remoteService);
var initializationOperation = package.InitializePackageAsync(createParameters);
#endif
```
对当前文件系统来说,`packageRoot` 只需要是一个非空值。快手小游戏底层会对远程 AssetBundle 请求做平台适配,业务侧仍然按照远程异步加载流程使用 YooAsset。
快手小游戏底层会对远程 AssetBundle 请求做平台适配,业务侧仍然按照远程异步加载流程使用 YooAsset。
## 资源包命名

View File

@@ -3,41 +3,30 @@ using YooAsset;
public static class OppoFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(OppoFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
string fileSystemClass = $"{nameof(OppoFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
{
string fileSystemClass = $"{nameof(OppoFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
}
/// <summary>
/// OPPO 小游戏文件系统
/// </summary>
internal class OppoFileSystem : WebGameFileSystem
{
/// <inheritdoc/>
protected override IWebGamePlatform CreatePlatform(string packageRoot)
private static FileSystemParameters CreateBaseFileSystemParameters(IRemoteService remoteService)
{
return new OppoPlatform();
var fileSystemParams = FileSystemParameters.CreateDefaultWebNetworkFileSystemParameters(remoteService, true);
fileSystemParams.AddParameter(EFileSystemParameter.WebPlatformStrategy, new OppoPlatform());
return fileSystemParams;
}
}
#endif

View File

@@ -6,12 +6,14 @@ using YooAsset;
/// <summary>
/// OPPO 小游戏平台实现
/// </summary>
internal class OppoPlatform : IWebGamePlatform
internal class OppoPlatform : IWebPlatformStrategy
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
public UnityWebRequest CreateAssetBundleRequest(WebAssetBundleRequestArgs args)
{
return UnityEngine.Networking.UnityWebRequestAssetBundle.GetAssetBundle(url);
UnityWebRequest request = UnityEngine.Networking.UnityWebRequestAssetBundle.GetAssetBundle(args.Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
/// <inheritdoc/>

View File

@@ -24,17 +24,16 @@ var createParameters = new WebPlayModeOptions();
string defaultHostServer = GetHostServerURL();
string fallbackHostServer = GetHostServerURL();
string packageRoot = "/__GAME_FILE_CACHE";
IRemoteService remoteService = new RemoteService(defaultHostServer, fallbackHostServer);
createParameters.WebServerFileSystemParameters =
OppoFileSystemCreater.CreateFileSystemParameters(packageRoot, remoteService);
OppoFileSystemCreater.CreateFileSystemParameters(remoteService);
var initializationOperation = package.InitializePackageAsync(createParameters);
#endif
```
对当前文件系统来说,`packageRoot` 只需要是一个非空值。OPPO 真正的 AssetBundle 缓存行为由生成后小游戏工程里的 `manifest.json` 控制。
OPPO 真正的 AssetBundle 缓存行为由生成后小游戏工程里的 `manifest.json` 控制。
## OPPO 缓存配置

View File

@@ -4,40 +4,30 @@ using TapTapMiniGame;
public static class TaptapFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(TaptapFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
string fileSystemClass = $"{nameof(TaptapFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
{
string fileSystemClass = $"{nameof(TaptapFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
}
/// <summary>
/// TapTap小游戏文件系统
/// </summary>
internal class TaptapFileSystem : WebGameFileSystem
{
protected override IWebGamePlatform CreatePlatform(string packageRoot)
private static FileSystemParameters CreateBaseFileSystemParameters(IRemoteService remoteService)
{
return new TaptapPlatform();
var fileSystemParams = FileSystemParameters.CreateDefaultWebNetworkFileSystemParameters(remoteService, true);
fileSystemParams.AddParameter(EFileSystemParameter.WebPlatformStrategy, new TaptapPlatform());
return fileSystemParams;
}
}
#endif

View File

@@ -8,12 +8,14 @@ using TapTapMiniGame;
/// TapTap 小游戏平台实现
/// 参考https://developer.taptap.cn/minigameapidoc/dev/engine/unity-adaptation/guide/
/// </summary>
internal class TaptapPlatform : IWebGamePlatform
internal class TaptapPlatform : IWebPlatformStrategy
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
public UnityWebRequest CreateAssetBundleRequest(WebAssetBundleRequestArgs args)
{
return TapAssetBundle.GetAssetBundle(url);
UnityWebRequest request = TapAssetBundle.GetAssetBundle(args.Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
/// <inheritdoc/>

View File

@@ -3,41 +3,30 @@ using YooAsset;
public static class TiktokFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
{
string fileSystemClass = $"{nameof(TiktokFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
}
/// <summary>
/// 抖音小游戏文件系统
/// </summary>
internal class TiktokFileSystem : WebGameFileSystem
{
/// <inheritdoc/>
protected override IWebGamePlatform CreatePlatform(string packageRoot)
private static FileSystemParameters CreateBaseFileSystemParameters(IRemoteService remoteService)
{
return new TiktokPlatform();
var fileSystemParams = FileSystemParameters.CreateDefaultWebNetworkFileSystemParameters(remoteService, true);
fileSystemParams.AddParameter(EFileSystemParameter.WebPlatformStrategy, new TiktokPlatform());
return fileSystemParams;
}
}
#endif

View File

@@ -7,12 +7,14 @@ using TTSDK;
/// <summary>
/// 抖音小游戏平台实现
/// </summary>
internal class TiktokPlatform : IWebGamePlatform
internal class TiktokPlatform : IWebPlatformStrategy
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
public UnityWebRequest CreateAssetBundleRequest(WebAssetBundleRequestArgs args)
{
return TTAssetBundle.GetAssetBundle(url);
UnityWebRequest request = TTAssetBundle.GetAssetBundle(args.Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
/// <inheritdoc/>

View File

@@ -24,17 +24,16 @@ var createParameters = new WebPlayModeOptions();
string defaultHostServer = GetHostServerURL();
string fallbackHostServer = GetHostServerURL();
string packageRoot = "/__GAME_FILE_CACHE";
IRemoteService remoteService = new RemoteService(defaultHostServer, fallbackHostServer);
createParameters.WebServerFileSystemParameters =
VivoFileSystemCreater.CreateFileSystemParameters(packageRoot, remoteService);
VivoFileSystemCreater.CreateFileSystemParameters(remoteService);
var initializationOperation = package.InitializePackageAsync(createParameters);
#endif
```
对当前文件系统来说,`packageRoot` 只需要是一个非空值。vivo 小游戏底层会对远程 AssetBundle 请求做缓存,业务侧仍然按照远程异步加载流程使用 YooAsset。
vivo 小游戏底层会对远程 AssetBundle 请求做缓存,业务侧仍然按照远程异步加载流程使用 YooAsset。
## 资源包命名

View File

@@ -3,41 +3,30 @@ using YooAsset;
public static class VivoFileSystemCreater
{
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(VivoFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
string fileSystemClass = $"{nameof(VivoFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
{
string fileSystemClass = $"{nameof(VivoFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateBaseFileSystemParameters(remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
}
/// <summary>
/// vivo 小游戏文件系统
/// </summary>
internal class VivoFileSystem : WebGameFileSystem
{
/// <inheritdoc/>
protected override IWebGamePlatform CreatePlatform(string packageRoot)
private static FileSystemParameters CreateBaseFileSystemParameters(IRemoteService remoteService)
{
return new VivoPlatform();
var fileSystemParams = FileSystemParameters.CreateDefaultWebNetworkFileSystemParameters(remoteService, true);
fileSystemParams.AddParameter(EFileSystemParameter.WebPlatformStrategy, new VivoPlatform());
return fileSystemParams;
}
}
#endif

View File

@@ -6,12 +6,14 @@ using YooAsset;
/// <summary>
/// vivo 小游戏平台实现
/// </summary>
internal class VivoPlatform : IWebGamePlatform
internal class VivoPlatform : IWebPlatformStrategy
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
public UnityWebRequest CreateAssetBundleRequest(WebAssetBundleRequestArgs args)
{
return UnityEngine.Networking.UnityWebRequestAssetBundle.GetAssetBundle(url);
UnityWebRequest request = UnityEngine.Networking.UnityWebRequestAssetBundle.GetAssetBundle(args.Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
/// <inheritdoc/>

View File

@@ -4,19 +4,31 @@ using WeChatWASM;
public static class WechatFileSystemCreater
{
private static string DefaultWXCacheRoot => $"{WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE";
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService)
{
var fileSystemParams = CreateFileSystemParameters(DefaultWXCacheRoot, remoteService, null, null);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
var fileSystemParams = CreateFileSystemParameters(DefaultWXCacheRoot, remoteService, assetBundleDecryptor, null);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
{
var fileSystemParams = CreateFileSystemParameters(DefaultWXCacheRoot, remoteService, assetBundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService)
{
string fileSystemClass = $"{nameof(WechatFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
var fileSystemParams = CreateFileSystemParameters(packageRoot, remoteService, null, null);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor)
{
string fileSystemClass = $"{nameof(WechatFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
var fileSystemParams = CreateFileSystemParameters(packageRoot, remoteService, assetBundleDecryptor, null);
return fileSystemParams;
}
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteService remoteService, IBundleDecryptor assetBundleDecryptor, IBundleDecryptor rawBundleDecryptor)
@@ -24,8 +36,13 @@ public static class WechatFileSystemCreater
string fileSystemClass = $"{nameof(WechatFileSystem)},YooAsset.MiniGame";
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(EFileSystemParameter.RemoteService, remoteService);
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
fileSystemParams.AddParameter(EFileSystemParameter.DisableUnityWebCache, true);
fileSystemParams.AddParameter(EFileSystemParameter.WebPlatformStrategy, new WechatPlatform());
if (assetBundleDecryptor != null)
fileSystemParams.AddParameter(EFileSystemParameter.AssetbundleDecryptor, assetBundleDecryptor);
if (rawBundleDecryptor != null)
fileSystemParams.AddParameter(EFileSystemParameter.RawbundleDecryptor, rawBundleDecryptor);
return fileSystemParams;
}
}
@@ -33,10 +50,9 @@ public static class WechatFileSystemCreater
/// <summary>
/// 微信小游戏文件系统
/// </summary>
internal class WechatFileSystem : WebGameFileSystem
internal class WechatFileSystem : WebNetworkFileSystem
{
private string _wxCacheRoot;
private WechatPlatform _wechatPlatform;
/// <inheritdoc />
public override FSClearCacheOperation ClearCacheAsync(FSClearCacheOptions options)
@@ -60,11 +76,10 @@ internal class WechatFileSystem : WebGameFileSystem
}
/// <inheritdoc />
protected override IWebGamePlatform CreatePlatform(string packageRoot)
public override void OnCreate(string packageName, string packageRoot)
{
_wxCacheRoot = packageRoot;
_wechatPlatform = new WechatPlatform();
return _wechatPlatform;
base.OnCreate(packageName, packageRoot);
}
internal string GetWXCacheRoot()

View File

@@ -7,12 +7,14 @@ using WeChatWASM;
/// <summary>
/// 微信小游戏平台实现
/// </summary>
internal class WechatPlatform : IWebGamePlatform
internal class WechatPlatform : IWebPlatformStrategy
{
/// <inheritdoc/>
public UnityWebRequest CreateAssetBundleRequest(string url)
public UnityWebRequest CreateAssetBundleRequest(WebAssetBundleRequestArgs args)
{
return WXAssetBundle.GetAssetBundle(url);
UnityWebRequest request = WXAssetBundle.GetAssetBundle(args.Url);
request.disposeDownloadHandlerOnDispose = true;
return request;
}
/// <inheritdoc/>