mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-26 02:30:18 +00:00
202 lines
6.4 KiB
C#
202 lines
6.4 KiB
C#
using System;
|
||
using System.IO;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace YooAsset
|
||
{
|
||
/// <summary>
|
||
/// Web文件系统
|
||
/// </summary>
|
||
internal class DefaultWebRemoteFileSystem : IFileSystem
|
||
{
|
||
/// <summary>
|
||
/// 下载后台接口
|
||
/// </summary>
|
||
public IDownloadBackend DownloadBackend { private set; get; }
|
||
|
||
/// <summary>
|
||
/// 包裹名称
|
||
/// </summary>
|
||
public string PackageName { private set; get; }
|
||
|
||
/// <summary>
|
||
/// 文件根目录
|
||
/// </summary>
|
||
public string FileRoot
|
||
{
|
||
get
|
||
{
|
||
return string.Empty;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 文件数量
|
||
/// </summary>
|
||
public int FileCount
|
||
{
|
||
get
|
||
{
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
#region 自定义参数
|
||
/// <summary>
|
||
/// 自定义参数:UnityWebRequest 创建委托
|
||
/// </summary>
|
||
public UnityWebRequestCreator WebRequestCreator { private set; get; }
|
||
|
||
/// <summary>
|
||
/// 禁用Unity的网络缓存
|
||
/// </summary>
|
||
public bool DisableUnityWebCache { private set; get; } = false;
|
||
|
||
/// <summary>
|
||
/// 自定义参数:远程服务接口的实例类(支持跨域下载)
|
||
/// </summary>
|
||
public IRemoteServices RemoteServices { private set; get; }
|
||
|
||
/// <summary>
|
||
/// 自定义参数:解密服务接口的实例类
|
||
/// </summary>
|
||
public IWebBundleDecryptionServices BundleDecryptionServices { private set; get; }
|
||
|
||
/// <summary>
|
||
/// 自定义参数:资源清单服务类
|
||
/// </summary>
|
||
public IManifestRestoreServices ManifestRestoreServices { private set; get; }
|
||
#endregion
|
||
|
||
|
||
public DefaultWebRemoteFileSystem()
|
||
{
|
||
}
|
||
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
|
||
{
|
||
var operation = new DWRFSInitializeOperation(this);
|
||
return operation;
|
||
}
|
||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||
{
|
||
var operation = new DWRFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout);
|
||
return operation;
|
||
}
|
||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||
{
|
||
var operation = new DWRFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
|
||
return operation;
|
||
}
|
||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||
{
|
||
var operation = new FSClearCacheFilesCompleteOperation();
|
||
return operation;
|
||
}
|
||
public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
|
||
{
|
||
throw new System.NotImplementedException();
|
||
}
|
||
public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
|
||
{
|
||
PackageBundle bundle = options.Bundle;
|
||
if (bundle.BundleType == (int)EBundleType.AssetBundle)
|
||
{
|
||
var operation = new DWRFSLoadAssetBundleOperation(this, bundle);
|
||
return operation;
|
||
}
|
||
else
|
||
{
|
||
string error = $"{nameof(DefaultWebRemoteFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||
var operation = new FSLoadBundleCompleteOperation(error);
|
||
return operation;
|
||
}
|
||
}
|
||
|
||
public virtual void SetParameter(string name, object value)
|
||
{
|
||
if (name == FileSystemParametersDefine.DOWNLOAD_BACKEND)
|
||
{
|
||
DownloadBackend = (IDownloadBackend)value;
|
||
}
|
||
else if (name == FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR)
|
||
{
|
||
WebRequestCreator = (UnityWebRequestCreator)value;
|
||
}
|
||
else if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||
{
|
||
DisableUnityWebCache = Convert.ToBoolean(value);
|
||
}
|
||
else if (name == FileSystemParametersDefine.REMOTE_SERVICES)
|
||
{
|
||
RemoteServices = (IRemoteServices)value;
|
||
}
|
||
else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
|
||
{
|
||
BundleDecryptionServices = (IWebBundleDecryptionServices)value;
|
||
}
|
||
else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
|
||
{
|
||
ManifestRestoreServices = (IManifestRestoreServices)value;
|
||
}
|
||
else
|
||
{
|
||
YooLogger.Warning($"Invalid parameter : {name}");
|
||
}
|
||
}
|
||
public virtual void OnCreate(string packageName, string packageRoot)
|
||
{
|
||
PackageName = packageName;
|
||
|
||
// 创建默认的下载后台接口
|
||
if (DownloadBackend == null)
|
||
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
|
||
}
|
||
public virtual void OnDestroy()
|
||
{
|
||
if (DownloadBackend != null)
|
||
{
|
||
DownloadBackend.Dispose();
|
||
DownloadBackend = null;
|
||
}
|
||
}
|
||
|
||
public virtual bool Belong(PackageBundle bundle)
|
||
{
|
||
return true;
|
||
}
|
||
public virtual bool Exists(PackageBundle bundle)
|
||
{
|
||
return true;
|
||
}
|
||
public virtual bool NeedDownload(PackageBundle bundle)
|
||
{
|
||
return false;
|
||
}
|
||
public virtual bool NeedUnpack(PackageBundle bundle)
|
||
{
|
||
return false;
|
||
}
|
||
public virtual bool NeedImport(PackageBundle bundle)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
public virtual string GetBundleFilePath(PackageBundle bundle)
|
||
{
|
||
throw new System.NotImplementedException();
|
||
}
|
||
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
||
{
|
||
throw new System.NotImplementedException();
|
||
}
|
||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||
{
|
||
throw new System.NotImplementedException();
|
||
}
|
||
|
||
#region 内部方法
|
||
#endregion
|
||
}
|
||
}
|