mirror of https://github.com/tuyoogame/YooAsset
update web file system
parent
d43eb821b9
commit
9420f8561f
|
@ -57,7 +57,7 @@ namespace YooAsset
|
|||
// 注意:在连续时间段内无新增下载数据及判定为超时
|
||||
if (_isAbort == false)
|
||||
{
|
||||
if (_latestDownloadBytes != _webRequest.downloadedBytes)
|
||||
if ( _latestDownloadBytes != _webRequest.downloadedBytes)
|
||||
{
|
||||
_latestDownloadBytes = _webRequest.downloadedBytes;
|
||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||
|
|
|
@ -61,12 +61,20 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
#region 自定义参数
|
||||
public bool AllowCrossAccess { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 禁用Unity的网络缓存
|
||||
/// </summary>
|
||||
public bool DisableUnityWebCache { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 允许跨域访问和下载
|
||||
/// </summary>
|
||||
public bool AllowCrossAccess { private set; get; } = false;
|
||||
#endregion
|
||||
|
||||
|
||||
|
@ -124,14 +132,18 @@ namespace YooAsset
|
|||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == "ALLOW_CROSS_ACCESS")
|
||||
{
|
||||
AllowCrossAccess = (bool)value;
|
||||
}
|
||||
else if (name == "REMOTE_SERVICES")
|
||||
if (name == "REMOTE_SERVICES")
|
||||
{
|
||||
RemoteServices = (IRemoteServices)value;
|
||||
}
|
||||
else if (name == "DISABLE_UNITY_WEB_CACHE")
|
||||
{
|
||||
DisableUnityWebCache = (bool)value;
|
||||
}
|
||||
else if (name == "ALLOW_CROSS_ACCESS")
|
||||
{
|
||||
AllowCrossAccess = (bool)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
|
|
|
@ -110,20 +110,34 @@ namespace YooAsset
|
|||
|
||||
private void CreateWebRequest()
|
||||
{
|
||||
uint unityCRC = Bundle.UnityCRC;
|
||||
Hash128 fileHash = Hash128.Parse(Bundle.FileHash);
|
||||
|
||||
// 注意:优先从浏览器缓存里获取文件
|
||||
// The file hash defining the version of the asset bundle.
|
||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||
_downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, unityCRC);
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
_downloadhandler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
_webRequest.downloadHandler = _downloadhandler;
|
||||
_webRequest.downloadHandler = CreateDownloadHandler();
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
_webRequest.SendWebRequest();
|
||||
}
|
||||
private DownloadHandlerAssetBundle CreateDownloadHandler()
|
||||
{
|
||||
if (_fileSystem.DisableUnityWebCache)
|
||||
{
|
||||
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, 0);
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
downloadhandler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
return downloadhandler;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:优先从浏览器缓存里获取文件
|
||||
// The file hash defining the version of the asset bundle.
|
||||
uint unityCRC = Bundle.UnityCRC;
|
||||
Hash128 fileHash = Hash128.Parse(Bundle.FileHash);
|
||||
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, unityCRC);
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
downloadhandler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
return downloadhandler;
|
||||
}
|
||||
}
|
||||
private void DisposeWebRequest()
|
||||
{
|
||||
if (_webRequest != null)
|
||||
|
|
|
@ -160,10 +160,11 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 创建默认的Web文件系统参数
|
||||
/// </summary>
|
||||
public static FileSystemParameters CreateDefaultWebFileSystemParameters()
|
||||
public static FileSystemParameters CreateDefaultWebFileSystemParameters(bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter("DISABLE_UNITY_WEB_CACHE", disableUnityWebCache);
|
||||
fileSystemParams.AddParameter("ALLOW_CROSS_ACCESS", false);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
@ -172,12 +173,13 @@ namespace YooAsset
|
|||
/// 创建默认的Web文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
public static FileSystemParameters CreateDefaultWebFileSystemParameters(IRemoteServices remoteServices)
|
||||
public static FileSystemParameters CreateDefaultWebFileSystemParameters(IRemoteServices remoteServices, bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter("ALLOW_CROSS_ACCESS", true);
|
||||
fileSystemParams.AddParameter("REMOTE_SERVICES", remoteServices);
|
||||
fileSystemParams.AddParameter("DISABLE_UNITY_WEB_CACHE", disableUnityWebCache);
|
||||
fileSystemParams.AddParameter("ALLOW_CROSS_ACCESS", true);
|
||||
return fileSystemParams;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue