mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
TEngine 6
This commit is contained in:
@@ -21,6 +21,13 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string Error { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
/// </summary>
|
||||
internal PackageAsset Asset
|
||||
{
|
||||
get { return _packageAsset; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 唯一标识符
|
||||
@@ -43,7 +50,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 身份是否无效
|
||||
/// </summary>
|
||||
internal bool IsInvalid
|
||||
public bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -77,11 +84,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private AssetInfo()
|
||||
{
|
||||
// 注意:禁止从外部创建该类
|
||||
}
|
||||
internal AssetInfo(string packageName, PackageAsset packageAsset, System.Type assetType)
|
||||
{
|
||||
if (packageAsset == null)
|
||||
|
@@ -1,209 +1,62 @@
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class BundleInfo
|
||||
{
|
||||
public enum ELoadMode
|
||||
{
|
||||
None,
|
||||
LoadFromDelivery,
|
||||
LoadFromStreaming,
|
||||
LoadFromCache,
|
||||
LoadFromRemote,
|
||||
LoadFromEditor,
|
||||
}
|
||||
|
||||
private readonly ResourceAssist _assist;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly string _importFilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包对象
|
||||
/// </summary>
|
||||
public readonly PackageBundle Bundle;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包加载模式
|
||||
/// </summary>
|
||||
public readonly ELoadMode LoadMode;
|
||||
|
||||
/// <summary>
|
||||
/// 远端下载地址
|
||||
/// </summary>
|
||||
public string RemoteMainURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 远端下载备用地址
|
||||
/// </summary>
|
||||
public string RemoteFallbackURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 分发资源文件路径
|
||||
/// </summary>
|
||||
public string DeliveryFilePath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 注意:该字段只用于帮助编辑器下的模拟模式。
|
||||
/// </summary>
|
||||
public string[] IncludeAssetsInEditor;
|
||||
|
||||
private BundleInfo()
|
||||
public BundleInfo(IFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
}
|
||||
public BundleInfo(ResourceAssist assist, PackageBundle bundle, ELoadMode loadMode, string mainURL, string fallbackURL)
|
||||
{
|
||||
_assist = assist;
|
||||
_fileSystem = fileSystem;
|
||||
Bundle = bundle;
|
||||
LoadMode = loadMode;
|
||||
RemoteMainURL = mainURL;
|
||||
RemoteFallbackURL = fallbackURL;
|
||||
DeliveryFilePath = string.Empty;
|
||||
_importFilePath = null;
|
||||
}
|
||||
public BundleInfo(ResourceAssist assist, PackageBundle bundle, ELoadMode loadMode, string deliveryFilePath)
|
||||
public BundleInfo(IFileSystem fileSystem, PackageBundle bundle, string importFilePath)
|
||||
{
|
||||
_assist = assist;
|
||||
_fileSystem = fileSystem;
|
||||
Bundle = bundle;
|
||||
LoadMode = loadMode;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
DeliveryFilePath = deliveryFilePath;
|
||||
}
|
||||
public BundleInfo(ResourceAssist assist, PackageBundle bundle, ELoadMode loadMode)
|
||||
{
|
||||
_assist = assist;
|
||||
Bundle = bundle;
|
||||
LoadMode = loadMode;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
DeliveryFilePath = string.Empty;
|
||||
}
|
||||
|
||||
#region Cache
|
||||
public bool IsCached()
|
||||
{
|
||||
return _assist.Cache.IsCached(Bundle.CacheGUID);
|
||||
}
|
||||
public void CacheRecord()
|
||||
{
|
||||
string infoFilePath = CachedInfoFilePath;
|
||||
string dataFilePath = CachedDataFilePath;
|
||||
string dataFileCRC = Bundle.FileCRC;
|
||||
long dataFileSize = Bundle.FileSize;
|
||||
var wrapper = new CacheManager.RecordWrapper(infoFilePath, dataFilePath, dataFileCRC, dataFileSize);
|
||||
_assist.Cache.Record(Bundle.CacheGUID, wrapper);
|
||||
}
|
||||
public void CacheDiscard()
|
||||
{
|
||||
_assist.Cache.Discard(Bundle.CacheGUID);
|
||||
}
|
||||
public EVerifyResult VerifySelf()
|
||||
{
|
||||
return CacheHelper.VerifyingRecordFile(_assist.Cache, Bundle.CacheGUID);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Persistent
|
||||
public string CachedDataFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _assist.Persistent.GetCachedDataFilePath(Bundle);
|
||||
}
|
||||
}
|
||||
public string CachedInfoFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _assist.Persistent.GetCachedInfoFilePath(Bundle);
|
||||
}
|
||||
}
|
||||
public string TempDataFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _assist.Persistent.GetTempDataFilePath(Bundle);
|
||||
}
|
||||
}
|
||||
public string BuildinFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _assist.Persistent.GetBuildinFilePath(Bundle);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Download
|
||||
public DownloaderBase CreateDownloader(int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return _assist.Download.CreateDownload(this, failedTryAgain, timeout);
|
||||
}
|
||||
public DownloaderBase CreateUnpacker(int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
var unpackBundleInfo = ConvertToUnpackInfo();
|
||||
return _assist.Download.CreateDownload(unpackBundleInfo, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AssetBundle
|
||||
internal AssetBundle LoadAssetBundle(string fileLoadPath, out Stream managedStream)
|
||||
{
|
||||
return _assist.Loader.LoadAssetBundle(this, fileLoadPath, out managedStream);
|
||||
}
|
||||
internal AssetBundleCreateRequest LoadAssetBundleAsync(string fileLoadPath, out Stream managedStream)
|
||||
{
|
||||
return _assist.Loader.LoadAssetBundleAsync(this, fileLoadPath, out managedStream);
|
||||
}
|
||||
internal AssetBundle LoadDeliveryAssetBundle(string fileLoadPath)
|
||||
{
|
||||
return _assist.Loader.LoadDeliveryAssetBundle(this, fileLoadPath);
|
||||
}
|
||||
internal AssetBundleCreateRequest LoadDeliveryAssetBundleAsync(string fileLoadPath)
|
||||
{
|
||||
return _assist.Loader.LoadDeliveryAssetBundleAsync(this, fileLoadPath);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 转换为解压BundleInfo
|
||||
/// </summary>
|
||||
private BundleInfo ConvertToUnpackInfo()
|
||||
{
|
||||
string streamingPath = PersistentHelper.ConvertToWWWPath(BuildinFilePath);
|
||||
BundleInfo newBundleInfo = new BundleInfo(_assist, Bundle, ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
|
||||
return newBundleInfo;
|
||||
_importFilePath = importFilePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量创建解压BundleInfo
|
||||
/// 加载资源包
|
||||
/// </summary>
|
||||
public static List<BundleInfo> CreateUnpackInfos(ResourceAssist assist, List<PackageBundle> unpackList)
|
||||
public FSLoadBundleOperation LoadBundleFile()
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
|
||||
foreach (var packageBundle in unpackList)
|
||||
{
|
||||
var bundleInfo = CreateUnpackInfo(assist, packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private static BundleInfo CreateUnpackInfo(ResourceAssist assist, PackageBundle packageBundle)
|
||||
{
|
||||
string streamingPath = PersistentHelper.ConvertToWWWPath(assist.Persistent.GetBuildinFilePath(packageBundle));
|
||||
BundleInfo newBundleInfo = new BundleInfo(assist, packageBundle, ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
|
||||
return newBundleInfo;
|
||||
return _fileSystem.LoadBundleFile(Bundle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建导入BundleInfo
|
||||
/// 创建下载器
|
||||
/// </summary>
|
||||
public static BundleInfo CreateImportInfo(ResourceAssist assist, PackageBundle packageBundle, string filePath)
|
||||
public FSDownloadFileOperation CreateDownloader(int failedTryAgain, int timeout)
|
||||
{
|
||||
// 注意:我们把本地文件路径指定为远端下载地址
|
||||
string persistentPath = PersistentHelper.ConvertToWWWPath(filePath);
|
||||
BundleInfo bundleInfo = new BundleInfo(assist, packageBundle, BundleInfo.ELoadMode.None, persistentPath, persistentPath);
|
||||
return bundleInfo;
|
||||
DownloadParam downloadParam = new DownloadParam(failedTryAgain, timeout);
|
||||
downloadParam.ImportFilePath = _importFilePath;
|
||||
return _fileSystem.DownloadFileAsync(Bundle, downloadParam);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要从远端下载
|
||||
/// </summary>
|
||||
public bool IsNeedDownloadFromRemote()
|
||||
{
|
||||
return _fileSystem.NeedDownload(Bundle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器合并识别码
|
||||
/// </summary>
|
||||
public string GetDownloadCombineGUID()
|
||||
{
|
||||
return $"{_fileSystem.GetHashCode()}_{Bundle.BundleGUID}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public enum EBuildBundleType
|
||||
{
|
||||
/// <summary>
|
||||
/// 未知类型
|
||||
/// </summary>
|
||||
Unknown = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 虚拟资源包
|
||||
/// </summary>
|
||||
VirtualBundle = 1,
|
||||
|
||||
/// <summary>
|
||||
/// AssetBundle
|
||||
/// </summary>
|
||||
AssetBundle = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件
|
||||
/// </summary>
|
||||
RawBundle = 3,
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5067db2d5b2aa1240aef2f9a952a2e0c
|
||||
guid: 2ea43593e14f4fb469b0e9abe9a8434d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -13,6 +13,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
BundleInfo[] GetDependBundleInfos(AssetInfo assetPath);
|
||||
|
||||
/// <summary>
|
||||
/// 获取主资源包名称
|
||||
/// </summary>
|
||||
string GetMainBundleName(int bundleID);
|
||||
|
||||
/// <summary>
|
||||
/// 获取主资源包名称
|
||||
/// </summary>
|
||||
@@ -22,10 +27,5 @@ namespace YooAsset
|
||||
/// 获取依赖的资源包名称集合
|
||||
/// </summary>
|
||||
string[] GetDependBundleNames(AssetInfo assetInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 清单是否有效
|
||||
/// </summary>
|
||||
bool ManifestValid();
|
||||
}
|
||||
}
|
@@ -4,34 +4,39 @@ namespace YooAsset
|
||||
internal interface IPlayMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 激活的清单
|
||||
/// 当前激活的清单
|
||||
/// </summary>
|
||||
PackageManifest ActiveManifest { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 保存清单版本文件到沙盒
|
||||
/// 销毁文件系统
|
||||
/// </summary>
|
||||
void FlushManifestVersionFile();
|
||||
void DestroyFileSystem();
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求最新的资源版本
|
||||
/// </summary>
|
||||
UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks, int timeout);
|
||||
RequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// </summary>
|
||||
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout);
|
||||
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹内容
|
||||
/// </summary>
|
||||
PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam);
|
||||
|
||||
// 下载相关
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
||||
|
||||
// 解压相关
|
||||
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout);
|
||||
|
@@ -39,9 +39,11 @@ namespace YooAsset
|
||||
buffer.WriteBool(manifest.LocationToLower);
|
||||
buffer.WriteBool(manifest.IncludeAssetGUID);
|
||||
buffer.WriteInt32(manifest.OutputNameStyle);
|
||||
buffer.WriteInt32(manifest.BuildBundleType);
|
||||
buffer.WriteUTF8(manifest.BuildPipeline);
|
||||
buffer.WriteUTF8(manifest.PackageName);
|
||||
buffer.WriteUTF8(manifest.PackageVersion);
|
||||
buffer.WriteUTF8(manifest.PackageNote);
|
||||
|
||||
// 写入资源列表
|
||||
buffer.WriteInt32(manifest.AssetList.Count);
|
||||
@@ -53,6 +55,7 @@ namespace YooAsset
|
||||
buffer.WriteUTF8(packageAsset.AssetGUID);
|
||||
buffer.WriteUTF8Array(packageAsset.AssetTags);
|
||||
buffer.WriteInt32(packageAsset.BundleID);
|
||||
buffer.WriteInt32Array(packageAsset.DependBundleIDs);
|
||||
}
|
||||
|
||||
// 写入资源包列表
|
||||
@@ -67,7 +70,7 @@ namespace YooAsset
|
||||
buffer.WriteInt64(packageBundle.FileSize);
|
||||
buffer.WriteBool(packageBundle.Encrypted);
|
||||
buffer.WriteUTF8Array(packageBundle.Tags);
|
||||
buffer.WriteInt32Array(packageBundle.DependIDs);
|
||||
buffer.WriteInt32Array(packageBundle.DependBundleIDs);
|
||||
}
|
||||
|
||||
// 写入文件流
|
||||
@@ -110,9 +113,11 @@ namespace YooAsset
|
||||
manifest.LocationToLower = buffer.ReadBool();
|
||||
manifest.IncludeAssetGUID = buffer.ReadBool();
|
||||
manifest.OutputNameStyle = buffer.ReadInt32();
|
||||
manifest.BuildBundleType = buffer.ReadInt32();
|
||||
manifest.BuildPipeline = buffer.ReadUTF8();
|
||||
manifest.PackageName = buffer.ReadUTF8();
|
||||
manifest.PackageVersion = buffer.ReadUTF8();
|
||||
manifest.PackageNote = buffer.ReadUTF8();
|
||||
|
||||
// 检测配置
|
||||
if (manifest.EnableAddressable && manifest.LocationToLower)
|
||||
@@ -120,7 +125,7 @@ namespace YooAsset
|
||||
|
||||
// 读取资源列表
|
||||
int packageAssetCount = buffer.ReadInt32();
|
||||
manifest.AssetList = new List<PackageAsset>(packageAssetCount);
|
||||
CreateAssetCollection(manifest, packageAssetCount);
|
||||
for (int i = 0; i < packageAssetCount; i++)
|
||||
{
|
||||
var packageAsset = new PackageAsset();
|
||||
@@ -129,12 +134,13 @@ namespace YooAsset
|
||||
packageAsset.AssetGUID = buffer.ReadUTF8();
|
||||
packageAsset.AssetTags = buffer.ReadUTF8Array();
|
||||
packageAsset.BundleID = buffer.ReadInt32();
|
||||
manifest.AssetList.Add(packageAsset);
|
||||
packageAsset.DependBundleIDs = buffer.ReadInt32Array();
|
||||
FillAssetCollection(manifest, packageAsset);
|
||||
}
|
||||
|
||||
// 读取资源包列表
|
||||
int packageBundleCount = buffer.ReadInt32();
|
||||
manifest.BundleList = new List<PackageBundle>(packageBundleCount);
|
||||
CreateBundleCollection(manifest, packageBundleCount);
|
||||
for (int i = 0; i < packageBundleCount; i++)
|
||||
{
|
||||
var packageBundle = new PackageBundle();
|
||||
@@ -145,37 +151,141 @@ namespace YooAsset
|
||||
packageBundle.FileSize = buffer.ReadInt64();
|
||||
packageBundle.Encrypted = buffer.ReadBool();
|
||||
packageBundle.Tags = buffer.ReadUTF8Array();
|
||||
packageBundle.DependIDs = buffer.ReadInt32Array();
|
||||
manifest.BundleList.Add(packageBundle);
|
||||
packageBundle.DependBundleIDs = buffer.ReadInt32Array();
|
||||
FillBundleCollection(manifest, packageBundle);
|
||||
}
|
||||
}
|
||||
|
||||
// 填充BundleDic
|
||||
manifest.BundleDic1 = new Dictionary<string, PackageBundle>(manifest.BundleList.Count);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(manifest.BundleList.Count);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
packageBundle.ParseBundle(manifest);
|
||||
manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
}
|
||||
|
||||
// 填充AssetDic
|
||||
manifest.AssetDic = new Dictionary<string, PackageAsset>(manifest.AssetList.Count);
|
||||
foreach (var packageAsset in manifest.AssetList)
|
||||
{
|
||||
// 注意:我们不允许原始路径存在重名
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
if (manifest.AssetDic.ContainsKey(assetPath))
|
||||
throw new Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
}
|
||||
|
||||
// 初始化资源清单
|
||||
InitManifest(manifest);
|
||||
return manifest;
|
||||
}
|
||||
#endif
|
||||
|
||||
#region 解析资源清单辅助方法
|
||||
public static void InitManifest(PackageManifest manifest)
|
||||
{
|
||||
// 填充资源包内包含的主资源列表
|
||||
foreach (var packageAsset in manifest.AssetList)
|
||||
{
|
||||
int bundleID = packageAsset.BundleID;
|
||||
if (bundleID >= 0 && bundleID < manifest.BundleList.Count)
|
||||
{
|
||||
var packageBundle = manifest.BundleList[bundleID];
|
||||
packageBundle.IncludeMainAssets.Add(packageAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {packageAsset.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// 填充资源包引用关系
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
var sourceBundle = manifest.BundleList[index];
|
||||
foreach (int dependIndex in sourceBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = manifest.BundleList[dependIndex];
|
||||
dependBundle.AddReferenceBundleID(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateAssetCollection(PackageManifest manifest, int assetCount)
|
||||
{
|
||||
manifest.AssetList = new List<PackageAsset>(assetCount);
|
||||
manifest.AssetDic = new Dictionary<string, PackageAsset>(assetCount);
|
||||
|
||||
if (manifest.EnableAddressable)
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 3);
|
||||
else
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
|
||||
|
||||
if (manifest.IncludeAssetGUID)
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>(assetCount);
|
||||
else
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>();
|
||||
}
|
||||
public static void FillAssetCollection(PackageManifest manifest, PackageAsset packageAsset)
|
||||
{
|
||||
// 添加到列表集合
|
||||
manifest.AssetList.Add(packageAsset);
|
||||
|
||||
// 注意:我们不允许原始路径存在重名
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
if (manifest.AssetDic.ContainsKey(assetPath))
|
||||
throw new System.Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
|
||||
// 填充AssetPathMapping1
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
if (manifest.LocationToLower)
|
||||
location = location.ToLower();
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (ReferenceEquals(location, locationWithoutExtension) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加可寻址地址
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 填充AssetPathMapping2
|
||||
if (manifest.IncludeAssetGUID)
|
||||
{
|
||||
if (manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
|
||||
throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
|
||||
else
|
||||
manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateBundleCollection(PackageManifest manifest, int bundleCount)
|
||||
{
|
||||
manifest.BundleList = new List<PackageBundle>(bundleCount);
|
||||
manifest.BundleDic1 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic3 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
}
|
||||
public static void FillBundleCollection(PackageManifest manifest, PackageBundle packageBundle)
|
||||
{
|
||||
// 初始化资源包
|
||||
packageBundle.InitBundle(manifest);
|
||||
|
||||
// 添加到列表集合
|
||||
manifest.BundleList.Add(packageBundle);
|
||||
|
||||
manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
manifest.BundleDic3.Add(packageBundle.BundleGUID, packageBundle);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 注意:该类拷贝自编辑器
|
||||
/// </summary>
|
||||
@@ -221,8 +331,15 @@ namespace YooAsset
|
||||
}
|
||||
else if (nameStyle == (int)EFileNameStyle.BundleName_HashName)
|
||||
{
|
||||
string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
|
||||
return StringUtility.Format("{0}_{1}{2}", fileName, fileHash, fileExtension);
|
||||
if (string.IsNullOrEmpty(fileExtension))
|
||||
{
|
||||
return StringUtility.Format("{0}_{1}", bundleName, fileHash);
|
||||
}
|
||||
else
|
||||
{
|
||||
string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
|
||||
return StringUtility.Format("{0}_{1}{2}", fileName, fileHash, fileExtension);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -0,0 +1,108 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class ClearCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
ClearCacheFiles,
|
||||
CheckClearResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly string _clearMode;
|
||||
private readonly object _clearParam;
|
||||
private List<IFileSystem> _cloneList;
|
||||
private FSClearCacheFilesOperation _clearCacheFilesOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearCacheFilesOperation(PlayModeImpl impl, string clearMode, object clearParam)
|
||||
{
|
||||
_impl = impl;
|
||||
_clearMode = clearMode;
|
||||
_clearParam = clearParam;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
var fileSytems = _impl.FileSystems;
|
||||
if (fileSytems == null || fileSytems.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "The file system is empty !";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var fileSystem in fileSytems)
|
||||
{
|
||||
if (fileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "An empty object exists in the list!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_cloneList = fileSytems.ToList();
|
||||
_steps = ESteps.ClearCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearCacheFiles)
|
||||
{
|
||||
if (_cloneList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileSystem = _cloneList[0];
|
||||
_cloneList.RemoveAt(0);
|
||||
|
||||
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
|
||||
_clearCacheFilesOp.StartOperation();
|
||||
AddChildOperation(_clearCacheFilesOp);
|
||||
_steps = ESteps.CheckClearResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckClearResult)
|
||||
{
|
||||
_clearCacheFilesOp.UpdateOperation();
|
||||
Progress = _clearCacheFilesOp.Progress;
|
||||
if (_clearCacheFilesOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_clearCacheFilesOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.ClearCacheFiles;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _clearCacheFilesOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"ClearMode : {_clearMode}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fccaa9437207a174d858ce44f14f5a03
|
||||
guid: 37b4e645f7a679f4fa978c55329ee01a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -0,0 +1,106 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class DestroyOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckInitStatus,
|
||||
UnloadAllAssets,
|
||||
DestroyPackage,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ResourcePackage _resourcePackage;
|
||||
private UnloadAllAssetsOperation _unloadAllAssetsOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public DestroyOperation(ResourcePackage resourcePackage)
|
||||
{
|
||||
_resourcePackage = resourcePackage;
|
||||
}
|
||||
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckInitStatus;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckInitStatus)
|
||||
{
|
||||
if (_resourcePackage.InitializeStatus == EOperationStatus.None)
|
||||
{
|
||||
_steps = ESteps.DestroyPackage;
|
||||
}
|
||||
else if (_resourcePackage.InitializeStatus == EOperationStatus.Processing)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "The Package is initializing ! Please try to destroy the package again later.";
|
||||
}
|
||||
else if (_resourcePackage.InitializeStatus == EOperationStatus.Failed)
|
||||
{
|
||||
_steps = ESteps.DestroyPackage;
|
||||
}
|
||||
else if (_resourcePackage.InitializeStatus == EOperationStatus.Succeed)
|
||||
{
|
||||
if (_resourcePackage.PackageValid)
|
||||
_steps = ESteps.UnloadAllAssets;
|
||||
else
|
||||
_steps = ESteps.DestroyPackage;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(_resourcePackage.InitializeStatus.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnloadAllAssets)
|
||||
{
|
||||
if (_unloadAllAssetsOp == null)
|
||||
{
|
||||
_unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync();
|
||||
_unloadAllAssetsOp.StartOperation();
|
||||
AddChildOperation(_unloadAllAssetsOp);
|
||||
}
|
||||
|
||||
_unloadAllAssetsOp.UpdateOperation();
|
||||
if (_unloadAllAssetsOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_unloadAllAssetsOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.DestroyPackage;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _unloadAllAssetsOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DestroyPackage)
|
||||
{
|
||||
// 销毁包裹
|
||||
_resourcePackage.DestroyPackage();
|
||||
|
||||
// 最后清理该包裹的异步任务
|
||||
// 注意:对于有线程操作的异步任务,需要保证线程安全释放。
|
||||
OperationSystem.ClearPackageOperation(_resourcePackage.PackageName);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"PackageVersion : {_resourcePackage.GetPackageVersion()}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 246df4d20b431c648a0821231a805e6b
|
||||
guid: 61a8757fa3c6b5c42a45e97198a645a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -15,20 +15,36 @@ namespace YooAsset
|
||||
|
||||
private const int MAX_LOADER_COUNT = 64;
|
||||
|
||||
public delegate void OnDownloadOver(bool isSucceed);
|
||||
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
|
||||
public delegate void OnDownloadError(string fileName, string error);
|
||||
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
|
||||
#region 委托定义
|
||||
/// <summary>
|
||||
/// 下载器结束
|
||||
/// </summary>
|
||||
public delegate void DownloaderFinish(DownloaderFinishData data);
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度更新
|
||||
/// </summary>
|
||||
public delegate void DownloadUpdate(DownloadUpdateData data);
|
||||
|
||||
/// <summary>
|
||||
/// 下载发生错误
|
||||
/// </summary>
|
||||
public delegate void DownloadError(DownloadErrorData data);
|
||||
|
||||
/// <summary>
|
||||
/// 开始下载某个文件
|
||||
/// </summary>
|
||||
public delegate void DownloadFileBegin(DownloadFileData data);
|
||||
#endregion
|
||||
|
||||
private readonly DownloadManager _downloadMgr;
|
||||
private readonly string _packageName;
|
||||
private readonly int _downloadingMaxNumber;
|
||||
private readonly int _failedTryAgain;
|
||||
private readonly int _timeout;
|
||||
private readonly List<BundleInfo> _bundleInfoList;
|
||||
private readonly List<DownloaderBase> _downloaders = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||
private readonly List<DownloaderBase> _removeList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||
private readonly List<DownloaderBase> _failedList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||
private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
||||
private readonly List<FSDownloadFileOperation> _removeList = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
||||
private readonly List<FSDownloadFileOperation> _failedList = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
||||
|
||||
// 数据相关
|
||||
private bool _isPause = false;
|
||||
@@ -68,27 +84,26 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 当下载器结束(无论成功或失败)
|
||||
/// </summary>
|
||||
public OnDownloadOver OnDownloadOverCallback { set; get; }
|
||||
public DownloaderFinish DownloadFinishCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当下载进度发生变化
|
||||
/// </summary>
|
||||
public OnDownloadProgress OnDownloadProgressCallback { set; get; }
|
||||
public DownloadUpdate DownloadUpdateCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当某个文件下载失败
|
||||
/// 当下载器发生错误
|
||||
/// </summary>
|
||||
public OnDownloadError OnDownloadErrorCallback { set; get; }
|
||||
public DownloadError DownloadErrorCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当开始下载某个文件
|
||||
/// </summary>
|
||||
public OnStartDownloadFile OnStartDownloadFileCallback { set; get; }
|
||||
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
|
||||
|
||||
|
||||
internal DownloaderOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
_downloadMgr = downloadMgr;
|
||||
_packageName = packageName;
|
||||
_bundleInfoList = downloadList;
|
||||
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
|
||||
@@ -101,12 +116,12 @@ namespace YooAsset
|
||||
// 统计下载信息
|
||||
CalculatDownloaderInfo();
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
internal override void InternalStart()
|
||||
{
|
||||
YooLogger.Log($"Begine to download : {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
|
||||
YooLogger.Log($"Begine to download {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
|
||||
_steps = ESteps.Check;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
@@ -132,12 +147,13 @@ namespace YooAsset
|
||||
long downloadBytes = _cachedDownloadBytes;
|
||||
foreach (var downloader in _downloaders)
|
||||
{
|
||||
downloadBytes += (long)downloader.DownloadedBytes;
|
||||
if (downloader.IsDone() == false)
|
||||
downloader.UpdateOperation();
|
||||
downloadBytes += downloader.DownloadedBytes;
|
||||
if (downloader.IsDone == false)
|
||||
continue;
|
||||
|
||||
// 检测是否下载失败
|
||||
if (downloader.HasError())
|
||||
if (downloader.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
_removeList.Add(downloader);
|
||||
_failedList.Add(downloader);
|
||||
@@ -147,13 +163,13 @@ namespace YooAsset
|
||||
// 下载成功
|
||||
_removeList.Add(downloader);
|
||||
_cachedDownloadCount++;
|
||||
_cachedDownloadBytes += downloader.GetDownloadFileSize();
|
||||
_cachedDownloadBytes += downloader.DownloadedBytes;
|
||||
}
|
||||
|
||||
// 移除已经完成的下载器(无论成功或失败)
|
||||
foreach (var loader in _removeList)
|
||||
foreach (var downloader in _removeList)
|
||||
{
|
||||
_downloaders.Remove(loader);
|
||||
_downloaders.Remove(downloader);
|
||||
}
|
||||
|
||||
// 如果下载进度发生变化
|
||||
@@ -162,7 +178,18 @@ namespace YooAsset
|
||||
_lastDownloadBytes = downloadBytes;
|
||||
_lastDownloadCount = _cachedDownloadCount;
|
||||
Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
|
||||
OnDownloadProgressCallback?.Invoke(TotalDownloadCount, _lastDownloadCount, TotalDownloadBytes, _lastDownloadBytes);
|
||||
|
||||
if (DownloadUpdateCallback != null)
|
||||
{
|
||||
var data = new DownloadUpdateData();
|
||||
data.PackageName = _packageName;
|
||||
data.Progress = Progress;
|
||||
data.TotalDownloadCount = TotalDownloadCount;
|
||||
data.CurrentDownloadCount = _lastDownloadCount;
|
||||
data.TotalDownloadBytes = TotalDownloadBytes;
|
||||
data.CurrentDownloadBytes = _lastDownloadBytes;
|
||||
DownloadUpdateCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
|
||||
// 动态创建新的下载器到最大数量限制
|
||||
@@ -177,10 +204,20 @@ namespace YooAsset
|
||||
int index = _bundleInfoList.Count - 1;
|
||||
var bundleInfo = _bundleInfoList[index];
|
||||
var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout);
|
||||
downloader.SendRequest();
|
||||
downloader.StartOperation();
|
||||
this.AddChildOperation(downloader);
|
||||
|
||||
_downloaders.Add(downloader);
|
||||
_bundleInfoList.RemoveAt(index);
|
||||
OnStartDownloadFileCallback?.Invoke(bundleInfo.Bundle.BundleName, bundleInfo.Bundle.FileSize);
|
||||
|
||||
if (DownloadFileBeginCallback != null)
|
||||
{
|
||||
var data = new DownloadFileData();
|
||||
data.PackageName = _packageName;
|
||||
data.FileName = bundleInfo.Bundle.BundleName;
|
||||
data.FileSize = bundleInfo.Bundle.FileSize;
|
||||
DownloadFileBeginCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,19 +227,41 @@ namespace YooAsset
|
||||
if (_failedList.Count > 0)
|
||||
{
|
||||
var failedDownloader = _failedList[0];
|
||||
string bundleName = failedDownloader.GetDownloadBundleName();
|
||||
string bundleName = failedDownloader.Bundle.BundleName;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to download file : {bundleName}";
|
||||
OnDownloadErrorCallback?.Invoke(bundleName, failedDownloader.GetLastError());
|
||||
OnDownloadOverCallback?.Invoke(false);
|
||||
|
||||
if (DownloadErrorCallback != null)
|
||||
{
|
||||
var data = new DownloadErrorData();
|
||||
data.PackageName = _packageName;
|
||||
data.FileName = bundleName;
|
||||
data.ErrorInfo = failedDownloader.Error;
|
||||
DownloadErrorCallback.Invoke(data);
|
||||
}
|
||||
|
||||
if (DownloadFinishCallback != null)
|
||||
{
|
||||
var data = new DownloaderFinishData();
|
||||
data.PackageName = _packageName;
|
||||
data.Succeed = false;
|
||||
DownloadFinishCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 结算成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
OnDownloadOverCallback?.Invoke(true);
|
||||
|
||||
if (DownloadFinishCallback != null)
|
||||
{
|
||||
var data = new DownloaderFinishData();
|
||||
data.PackageName = _packageName;
|
||||
data.Succeed = true;
|
||||
DownloadFinishCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,16 +305,18 @@ namespace YooAsset
|
||||
HashSet<string> temper = new HashSet<string>();
|
||||
foreach (var bundleInfo in _bundleInfoList)
|
||||
{
|
||||
if (temper.Contains(bundleInfo.CachedDataFilePath) == false)
|
||||
string combineGUID = bundleInfo.GetDownloadCombineGUID();
|
||||
if (temper.Contains(combineGUID) == false)
|
||||
{
|
||||
temper.Add(bundleInfo.CachedDataFilePath);
|
||||
temper.Add(combineGUID);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并下载列表
|
||||
foreach (var bundleInfo in downloader._bundleInfoList)
|
||||
{
|
||||
if (temper.Contains(bundleInfo.CachedDataFilePath) == false)
|
||||
string combineGUID = bundleInfo.GetDownloadCombineGUID();
|
||||
if (temper.Contains(combineGUID) == false)
|
||||
{
|
||||
_bundleInfoList.Add(bundleInfo);
|
||||
}
|
||||
@@ -272,7 +333,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
OperationSystem.StartOperation(this);
|
||||
OperationSystem.StartOperation(_packageName, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,69 +363,63 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "User cancel.";
|
||||
ReleaseAllDownloader();
|
||||
}
|
||||
}
|
||||
private void ReleaseAllDownloader()
|
||||
{
|
||||
foreach (var downloader in _downloaders)
|
||||
{
|
||||
downloader.Release();
|
||||
}
|
||||
|
||||
// 注意:停止不再使用的下载器
|
||||
_downloadMgr.AbortUnusedDownloader();
|
||||
foreach (var downloader in _downloaders)
|
||||
{
|
||||
downloader.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ResourceDownloaderOperation : DownloaderOperation
|
||||
{
|
||||
internal ResourceDownloaderOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建空的下载器
|
||||
/// </summary>
|
||||
internal static ResourceDownloaderOperation CreateEmptyDownloader(DownloadManager downloadMgr, string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||
var operation = new ResourceDownloaderOperation(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
public sealed class ResourceUnpackerOperation : DownloaderOperation
|
||||
{
|
||||
internal ResourceUnpackerOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建空的解压器
|
||||
/// </summary>
|
||||
internal static ResourceUnpackerOperation CreateEmptyUnpacker(DownloadManager downloadMgr, string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||
var operation = new ResourceUnpackerOperation(downloadMgr, packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||
var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
public sealed class ResourceImporterOperation : DownloaderOperation
|
||||
{
|
||||
internal ResourceImporterOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建空的导入器
|
||||
/// </summary>
|
||||
internal static ResourceImporterOperation CreateEmptyImporter(DownloadManager downloadMgr, string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||
var operation = new ResourceImporterOperation(downloadMgr, packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||
var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
@@ -1,505 +1,129 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化操作
|
||||
/// </summary>
|
||||
public abstract class InitializationOperation : AsyncOperationBase
|
||||
{
|
||||
public string PackageVersion { protected set; get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟模式的初始化操作
|
||||
/// </summary>
|
||||
internal sealed class EditorSimulateModeInitializationOperation : InitializationOperation
|
||||
public class InitializationOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadEditorManifest,
|
||||
Prepare,
|
||||
ClearOldFileSystem,
|
||||
InitFileSystem,
|
||||
CheckInitResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly EditorSimulateModeImpl _impl;
|
||||
private readonly string _simulateManifestFilePath;
|
||||
private LoadEditorManifestOperation _loadEditorManifestOp;
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly List<FileSystemParameters> _parametersList;
|
||||
private List<FileSystemParameters> _cloneList;
|
||||
private FSInitializeFileSystemOperation _initFileSystemOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, string simulateManifestFilePath)
|
||||
internal InitializationOperation(PlayModeImpl impl, List<FileSystemParameters> parametersList)
|
||||
{
|
||||
_impl = impl;
|
||||
_simulateManifestFilePath = simulateManifestFilePath;
|
||||
_parametersList = parametersList;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.LoadEditorManifest;
|
||||
_steps = ESteps.Prepare;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.LoadEditorManifest)
|
||||
{
|
||||
if (_loadEditorManifestOp == null)
|
||||
{
|
||||
_loadEditorManifestOp = new LoadEditorManifestOperation(_impl.PackageName, _simulateManifestFilePath);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadEditorManifestOp);
|
||||
}
|
||||
|
||||
if (_loadEditorManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadEditorManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _loadEditorManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadEditorManifestOp.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadEditorManifestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离线运行模式的初始化操作
|
||||
/// </summary>
|
||||
internal sealed class OfflinePlayModeInitializationOperation : InitializationOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
QueryBuildinPackageVersion,
|
||||
LoadBuildinManifest,
|
||||
PackageCaching,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly OfflinePlayModeImpl _impl;
|
||||
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
|
||||
private LoadBuildinManifestOperation _loadBuildinManifestOp;
|
||||
private PackageCachingOperation _cachingOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.QueryBuildinPackageVersion;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.QueryBuildinPackageVersion)
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
if (_queryBuildinPackageVersionOp == null)
|
||||
{
|
||||
_queryBuildinPackageVersionOp = new QueryBuildinPackageVersionOperation(_impl.Persistent);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _queryBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
if (_queryBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadBuildinManifest;
|
||||
}
|
||||
else
|
||||
if (_parametersList == null || _parametersList.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _queryBuildinPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBuildinManifest)
|
||||
{
|
||||
if (_loadBuildinManifestOp == null)
|
||||
{
|
||||
_loadBuildinManifestOp = new LoadBuildinManifestOperation(_impl.Persistent, _queryBuildinPackageVersionOp.PackageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadBuildinManifestOp);
|
||||
}
|
||||
|
||||
Progress = _loadBuildinManifestOp.Progress;
|
||||
if (_loadBuildinManifestOp.IsDone == false)
|
||||
Error = "The file system parameters is empty !";
|
||||
return;
|
||||
}
|
||||
|
||||
if (_loadBuildinManifestOp.Status == EOperationStatus.Succeed)
|
||||
foreach (var fileSystemParam in _parametersList)
|
||||
{
|
||||
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadBuildinManifestOp.Error;
|
||||
if (fileSystemParam == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "An empty object exists in the list!";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_cloneList = _parametersList.ToList();
|
||||
_steps = ESteps.ClearOldFileSystem;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.PackageCaching)
|
||||
if (_steps == ESteps.ClearOldFileSystem)
|
||||
{
|
||||
if (_cachingOperation == null)
|
||||
// 注意:初始化失败后可能会残存一些旧的文件系统!
|
||||
foreach (var fileSystem in _impl.FileSystems)
|
||||
{
|
||||
_cachingOperation = new PackageCachingOperation(_impl.Persistent, _impl.Cache);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _cachingOperation);
|
||||
fileSystem.OnDestroy();
|
||||
}
|
||||
|
||||
Progress = _cachingOperation.Progress;
|
||||
if (_cachingOperation.IsDone)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 联机运行模式的初始化操作
|
||||
/// 注意:优先从沙盒里加载清单,如果沙盒里不存在就尝试把内置清单拷贝到沙盒并加载该清单。
|
||||
/// </summary>
|
||||
internal sealed class HostPlayModeInitializationOperation : InitializationOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckAppFootPrint,
|
||||
QueryCachePackageVersion,
|
||||
TryLoadCacheManifest,
|
||||
QueryBuildinPackageVersion,
|
||||
UnpackBuildinManifest,
|
||||
LoadBuildinManifest,
|
||||
PackageCaching,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
|
||||
private QueryCachePackageVersionOperation _queryCachePackageVersionOp;
|
||||
private UnpackBuildinManifestOperation _unpackBuildinManifestOp;
|
||||
private LoadBuildinManifestOperation _loadBuildinManifestOp;
|
||||
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||
private PackageCachingOperation _cachingOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.CheckAppFootPrint;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckAppFootPrint)
|
||||
{
|
||||
var appFootPrint = new AppFootPrint(_impl.Persistent);
|
||||
appFootPrint.Load(_impl.PackageName);
|
||||
|
||||
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
|
||||
if (appFootPrint.IsDirty())
|
||||
{
|
||||
_impl.Persistent.DeleteSandboxManifestFilesFolder();
|
||||
appFootPrint.Coverage(_impl.PackageName);
|
||||
YooLogger.Log("Delete manifest files when application foot print dirty !");
|
||||
}
|
||||
_steps = ESteps.QueryCachePackageVersion;
|
||||
_impl.FileSystems.Clear();
|
||||
_steps = ESteps.InitFileSystem;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.QueryCachePackageVersion)
|
||||
if (_steps == ESteps.InitFileSystem)
|
||||
{
|
||||
if (_queryCachePackageVersionOp == null)
|
||||
if (_cloneList.Count == 0)
|
||||
{
|
||||
_queryCachePackageVersionOp = new QueryCachePackageVersionOperation(_impl.Persistent);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _queryCachePackageVersionOp);
|
||||
}
|
||||
|
||||
if (_queryCachePackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryCachePackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.TryLoadCacheManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.QueryBuildinPackageVersion;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.TryLoadCacheManifest)
|
||||
{
|
||||
if (_loadCacheManifestOp == null)
|
||||
{
|
||||
_loadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _queryCachePackageVersionOp.PackageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
|
||||
}
|
||||
|
||||
if (_loadCacheManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _loadCacheManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.QueryBuildinPackageVersion;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.QueryBuildinPackageVersion)
|
||||
{
|
||||
if (_queryBuildinPackageVersionOp == null)
|
||||
{
|
||||
_queryBuildinPackageVersionOp = new QueryBuildinPackageVersionOperation(_impl.Persistent);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _queryBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
if (_queryBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.UnpackBuildinManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:为了兼容MOD模式,初始化动态新增的包裹的时候,如果内置清单不存在也不需要报错!
|
||||
_steps = ESteps.PackageCaching;
|
||||
string error = _queryBuildinPackageVersionOp.Error;
|
||||
YooLogger.Log($"Failed to load buildin package version file : {error}");
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackBuildinManifest)
|
||||
{
|
||||
if (_unpackBuildinManifestOp == null)
|
||||
{
|
||||
_unpackBuildinManifestOp = new UnpackBuildinManifestOperation(_impl.Persistent, _queryBuildinPackageVersionOp.PackageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _unpackBuildinManifestOp);
|
||||
}
|
||||
|
||||
if (_unpackBuildinManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_unpackBuildinManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadBuildinManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _unpackBuildinManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBuildinManifest)
|
||||
{
|
||||
if (_loadBuildinManifestOp == null)
|
||||
{
|
||||
_loadBuildinManifestOp = new LoadBuildinManifestOperation(_impl.Persistent, _queryBuildinPackageVersionOp.PackageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadBuildinManifestOp);
|
||||
}
|
||||
|
||||
Progress = _loadBuildinManifestOp.Progress;
|
||||
if (_loadBuildinManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadBuildinManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||
_impl.FlushManifestVersionFile(); //注意:解压内置清单并加载成功后保存该清单版本。
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadBuildinManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.PackageCaching)
|
||||
{
|
||||
if (_cachingOperation == null)
|
||||
{
|
||||
_cachingOperation = new PackageCachingOperation(_impl.Persistent, _impl.Cache);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _cachingOperation);
|
||||
}
|
||||
|
||||
Progress = _cachingOperation.Progress;
|
||||
if (_cachingOperation.IsDone)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WebGL运行模式的初始化操作
|
||||
/// </summary>
|
||||
internal sealed class WebPlayModeInitializationOperation : InitializationOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
QueryWebPackageVersion,
|
||||
LoadWebManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly WebPlayModeImpl _impl;
|
||||
private QueryBuildinPackageVersionOperation _queryWebPackageVersionOp;
|
||||
private LoadBuildinManifestOperation _loadWebManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal WebPlayModeInitializationOperation(WebPlayModeImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.QueryWebPackageVersion;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.QueryWebPackageVersion)
|
||||
{
|
||||
if (_queryWebPackageVersionOp == null)
|
||||
{
|
||||
_queryWebPackageVersionOp = new QueryBuildinPackageVersionOperation(_impl.Persistent);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _queryWebPackageVersionOp);
|
||||
}
|
||||
|
||||
if (_queryWebPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryWebPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadWebManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:WebGL平台可能因为网络的原因会导致请求失败。如果内置清单不存在或者超时也不需要报错!
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
string error = _queryWebPackageVersionOp.Error;
|
||||
YooLogger.Log($"Failed to load web package version file : {error}");
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadWebManifest)
|
||||
{
|
||||
if (_loadWebManifestOp == null)
|
||||
{
|
||||
_loadWebManifestOp = new LoadBuildinManifestOperation(_impl.Persistent, _queryWebPackageVersionOp.PackageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadWebManifestOp);
|
||||
}
|
||||
|
||||
Progress = _loadWebManifestOp.Progress;
|
||||
if (_loadWebManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadWebManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _loadWebManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadWebManifestOp.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileSystemParams = _cloneList[0];
|
||||
_cloneList.RemoveAt(0);
|
||||
|
||||
IFileSystem fileSystemInstance = fileSystemParams.CreateFileSystem(_impl.PackageName);
|
||||
if (fileSystemInstance == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to create file system instance !";
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.FileSystems.Add(fileSystemInstance);
|
||||
_initFileSystemOp = fileSystemInstance.InitializeFileSystemAsync();
|
||||
_initFileSystemOp.StartOperation();
|
||||
AddChildOperation(_initFileSystemOp);
|
||||
_steps = ESteps.CheckInitResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckInitResult)
|
||||
{
|
||||
_initFileSystemOp.UpdateOperation();
|
||||
Progress = _initFileSystemOp.Progress;
|
||||
if (_initFileSystemOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_initFileSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.InitFileSystem;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadWebManifestOp.Error;
|
||||
Error = _initFileSystemOp.Error;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用程序水印
|
||||
/// </summary>
|
||||
internal class AppFootPrint
|
||||
{
|
||||
private PersistentManager _persistent;
|
||||
private string _footPrint;
|
||||
|
||||
public AppFootPrint(PersistentManager persistent)
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
_persistent = persistent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取应用程序水印
|
||||
/// </summary>
|
||||
public void Load(string packageName)
|
||||
{
|
||||
string footPrintFilePath = _persistent.SandboxAppFootPrintFilePath;
|
||||
if (File.Exists(footPrintFilePath))
|
||||
{
|
||||
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Coverage(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测水印是否发生变化
|
||||
/// </summary>
|
||||
public bool IsDirty()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return _footPrint != Application.version;
|
||||
#else
|
||||
return _footPrint != Application.buildGUID;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 覆盖掉水印
|
||||
/// </summary>
|
||||
public void Coverage(string packageName)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_footPrint = Application.version;
|
||||
#else
|
||||
_footPrint = Application.buildGUID;
|
||||
#endif
|
||||
string footPrintFilePath = _persistent.SandboxAppFootPrintFilePath;
|
||||
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
|
||||
YooLogger.Log($"Save application foot print : {_footPrint}");
|
||||
return $"PlayMode : {_impl.PlayMode}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -14,6 +15,7 @@ namespace YooAsset
|
||||
DeserializeAssetList,
|
||||
PrepareBundleList,
|
||||
DeserializeBundleList,
|
||||
InitManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -32,11 +34,11 @@ namespace YooAsset
|
||||
{
|
||||
_buffer = new BufferReader(binaryData);
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.DeserializeFileHeader;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
@@ -80,9 +82,11 @@ namespace YooAsset
|
||||
Manifest.LocationToLower = _buffer.ReadBool();
|
||||
Manifest.IncludeAssetGUID = _buffer.ReadBool();
|
||||
Manifest.OutputNameStyle = _buffer.ReadInt32();
|
||||
Manifest.BuildBundleType = _buffer.ReadInt32();
|
||||
Manifest.BuildPipeline = _buffer.ReadUTF8();
|
||||
Manifest.PackageName = _buffer.ReadUTF8();
|
||||
Manifest.PackageVersion = _buffer.ReadUTF8();
|
||||
Manifest.PackageNote = _buffer.ReadUTF8();
|
||||
|
||||
// 检测配置
|
||||
if (Manifest.EnableAddressable && Manifest.LocationToLower)
|
||||
@@ -94,20 +98,8 @@ namespace YooAsset
|
||||
if (_steps == ESteps.PrepareAssetList)
|
||||
{
|
||||
_packageAssetCount = _buffer.ReadInt32();
|
||||
Manifest.AssetList = new List<PackageAsset>(_packageAssetCount);
|
||||
Manifest.AssetDic = new Dictionary<string, PackageAsset>(_packageAssetCount);
|
||||
|
||||
if (Manifest.EnableAddressable)
|
||||
Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount * 3);
|
||||
else
|
||||
Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount * 2);
|
||||
|
||||
if (Manifest.IncludeAssetGUID)
|
||||
Manifest.AssetPathMapping2 = new Dictionary<string, string>(_packageAssetCount);
|
||||
else
|
||||
Manifest.AssetPathMapping2 = new Dictionary<string, string>();
|
||||
|
||||
_progressTotalValue = _packageAssetCount;
|
||||
ManifestTools.CreateAssetCollection(Manifest, _packageAssetCount);
|
||||
_steps = ESteps.DeserializeAssetList;
|
||||
}
|
||||
if (_steps == ESteps.DeserializeAssetList)
|
||||
@@ -120,57 +112,8 @@ namespace YooAsset
|
||||
packageAsset.AssetGUID = _buffer.ReadUTF8();
|
||||
packageAsset.AssetTags = _buffer.ReadUTF8Array();
|
||||
packageAsset.BundleID = _buffer.ReadInt32();
|
||||
Manifest.AssetList.Add(packageAsset);
|
||||
|
||||
// 注意:我们不允许原始路径存在重名
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
if (Manifest.AssetDic.ContainsKey(assetPath))
|
||||
throw new System.Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
Manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
|
||||
// 填充AssetPathMapping1
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
if (Manifest.LocationToLower)
|
||||
location = location.ToLower();
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (ReferenceEquals(location, locationWithoutExtension) == false)
|
||||
{
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
if (Manifest.EnableAddressable)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 填充AssetPathMapping2
|
||||
if (Manifest.IncludeAssetGUID)
|
||||
{
|
||||
if (Manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
|
||||
throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
|
||||
else
|
||||
Manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
|
||||
}
|
||||
packageAsset.DependBundleIDs = _buffer.ReadInt32Array();
|
||||
ManifestTools.FillAssetCollection(Manifest, packageAsset);
|
||||
|
||||
_packageAssetCount--;
|
||||
Progress = 1f - _packageAssetCount / _progressTotalValue;
|
||||
@@ -187,11 +130,8 @@ namespace YooAsset
|
||||
if (_steps == ESteps.PrepareBundleList)
|
||||
{
|
||||
_packageBundleCount = _buffer.ReadInt32();
|
||||
Manifest.BundleList = new List<PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic1 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic2 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic3 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
_progressTotalValue = _packageBundleCount;
|
||||
ManifestTools.CreateBundleCollection(Manifest, _packageBundleCount);
|
||||
_steps = ESteps.DeserializeBundleList;
|
||||
}
|
||||
if (_steps == ESteps.DeserializeBundleList)
|
||||
@@ -206,15 +146,8 @@ namespace YooAsset
|
||||
packageBundle.FileSize = _buffer.ReadInt64();
|
||||
packageBundle.Encrypted = _buffer.ReadBool();
|
||||
packageBundle.Tags = _buffer.ReadUTF8Array();
|
||||
packageBundle.DependIDs = _buffer.ReadInt32Array();
|
||||
packageBundle.ParseBundle(Manifest);
|
||||
Manifest.BundleList.Add(packageBundle);
|
||||
Manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
|
||||
Manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
|
||||
// 注意:原始文件可能存在相同的CacheGUID
|
||||
if (Manifest.BundleDic3.ContainsKey(packageBundle.CacheGUID) == false)
|
||||
Manifest.BundleDic3.Add(packageBundle.CacheGUID, packageBundle);
|
||||
packageBundle.DependBundleIDs = _buffer.ReadInt32Array();
|
||||
ManifestTools.FillBundleCollection(Manifest, packageBundle);
|
||||
|
||||
_packageBundleCount--;
|
||||
Progress = 1f - _packageBundleCount / _progressTotalValue;
|
||||
@@ -224,10 +157,16 @@ namespace YooAsset
|
||||
|
||||
if (_packageBundleCount <= 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
_steps = ESteps.InitManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.InitManifest)
|
||||
{
|
||||
ManifestTools.InitManifest(Manifest);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
|
@@ -1,113 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DownloadManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
DownloadPackageHashFile,
|
||||
DownloadManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private UnityWebFileRequester _downloader1;
|
||||
private UnityWebFileRequester _downloader2;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
internal DownloadManifestOperation(PersistentManager persistent, IRemoteServices remoteServices, string packageVersion, int timeout)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_remoteServices = remoteServices;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_persistent.PackageName, nameof(DownloadManifestOperation));
|
||||
_steps = ESteps.DownloadPackageHashFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.DownloadPackageHashFile)
|
||||
{
|
||||
if (_downloader1 == null)
|
||||
{
|
||||
string savePath = _persistent.GetSandboxPackageHashFilePath(_packageVersion);
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_persistent.PackageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download package hash file : {webURL}");
|
||||
_downloader1 = new UnityWebFileRequester();
|
||||
_downloader1.SendRequest(webURL, savePath, _timeout);
|
||||
}
|
||||
|
||||
_downloader1.CheckTimeout();
|
||||
if (_downloader1.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader1.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader1.GetError();
|
||||
RequestHelper.RecordRequestFailed(_persistent.PackageName, nameof(DownloadManifestOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.DownloadManifestFile;
|
||||
}
|
||||
|
||||
_downloader1.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadManifestFile)
|
||||
{
|
||||
if (_downloader2 == null)
|
||||
{
|
||||
string savePath = _persistent.GetSandboxPackageManifestFilePath(_packageVersion);
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_persistent.PackageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download package manifest file : {webURL}");
|
||||
_downloader2 = new UnityWebFileRequester();
|
||||
_downloader2.SendRequest(webURL, savePath, _timeout);
|
||||
}
|
||||
|
||||
_downloader2.CheckTimeout();
|
||||
if (_downloader2.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader2.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader2.GetError();
|
||||
RequestHelper.RecordRequestFailed(_persistent.PackageName, nameof(DownloadManifestOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
_downloader2.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDownloadRequestURL(string fileName)
|
||||
{
|
||||
// 轮流返回请求地址
|
||||
if (_requestCount % 2 == 0)
|
||||
return _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
return _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,91 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadBuildinManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadBuildinManifest,
|
||||
CheckDeserializeManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly string _buildinPackageVersion;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 加载的清单实例
|
||||
/// </summary>
|
||||
public PackageManifest Manifest { private set; get; }
|
||||
|
||||
|
||||
public LoadBuildinManifestOperation(PersistentManager persistent, string buildinPackageVersion)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_buildinPackageVersion = buildinPackageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadBuildinManifest;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadBuildinManifest)
|
||||
{
|
||||
if (_downloader == null)
|
||||
{
|
||||
string filePath = _persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||
string url = PersistentHelper.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(url);
|
||||
}
|
||||
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] bytesData = _downloader.GetData();
|
||||
_deserializer = new DeserializeManifestOperation(bytesData);
|
||||
OperationSystem.StartOperation(_persistent.PackageName, _deserializer);
|
||||
_steps = ESteps.CheckDeserializeManifest;
|
||||
}
|
||||
|
||||
_downloader.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckDeserializeManifest)
|
||||
{
|
||||
Progress = _deserializer.Progress;
|
||||
if (_deserializer.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
Manifest = _deserializer.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _deserializer.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,141 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadCacheManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
QueryCachePackageHash,
|
||||
VerifyFileHash,
|
||||
LoadCacheManifest,
|
||||
CheckDeserializeManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly string _packageVersion;
|
||||
private QueryCachePackageHashOperation _queryCachePackageHashOp;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private string _manifestFilePath;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 加载的清单实例
|
||||
/// </summary>
|
||||
public PackageManifest Manifest { private set; get; }
|
||||
|
||||
|
||||
public LoadCacheManifestOperation(PersistentManager persistent, string packageVersion)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.QueryCachePackageHash;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.QueryCachePackageHash)
|
||||
{
|
||||
if (_queryCachePackageHashOp == null)
|
||||
{
|
||||
_queryCachePackageHashOp = new QueryCachePackageHashOperation(_persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_persistent.PackageName, _queryCachePackageHashOp);
|
||||
}
|
||||
|
||||
if (_queryCachePackageHashOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryCachePackageHashOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.VerifyFileHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _queryCachePackageHashOp.Error;
|
||||
ClearCacheFile();
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyFileHash)
|
||||
{
|
||||
_manifestFilePath = _persistent.GetSandboxPackageManifestFilePath(_packageVersion);
|
||||
if (File.Exists(_manifestFilePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Not found cache manifest file : {_manifestFilePath}";
|
||||
ClearCacheFile();
|
||||
return;
|
||||
}
|
||||
|
||||
string fileHash = HashUtility.FileMD5Safely(_manifestFilePath);
|
||||
if (fileHash != _queryCachePackageHashOp.PackageHash)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify cache manifest file hash !";
|
||||
ClearCacheFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadCacheManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheManifest)
|
||||
{
|
||||
byte[] bytesData = File.ReadAllBytes(_manifestFilePath);
|
||||
_deserializer = new DeserializeManifestOperation(bytesData);
|
||||
OperationSystem.StartOperation(_persistent.PackageName, _deserializer);
|
||||
_steps = ESteps.CheckDeserializeManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckDeserializeManifest)
|
||||
{
|
||||
Progress = _deserializer.Progress;
|
||||
if (_deserializer.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
Manifest = _deserializer.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _deserializer.Error;
|
||||
ClearCacheFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearCacheFile()
|
||||
{
|
||||
// 注意:如果加载沙盒内的清单报错,为了避免流程被卡住,主动把损坏的文件删除。
|
||||
if (File.Exists(_manifestFilePath))
|
||||
{
|
||||
YooLogger.Warning($"Failed to load cache manifest file : {Error}");
|
||||
YooLogger.Warning($"Invalid cache manifest file have been removed : {_manifestFilePath}");
|
||||
File.Delete(_manifestFilePath);
|
||||
}
|
||||
|
||||
string hashFilePath = _persistent.GetSandboxPackageHashFilePath(_packageVersion);
|
||||
if (File.Exists(hashFilePath))
|
||||
{
|
||||
File.Delete(hashFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadEditorManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadEditorManifest,
|
||||
CheckDeserializeManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private readonly string _manifestFilePath;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 加载的清单实例
|
||||
/// </summary>
|
||||
public PackageManifest Manifest { private set; get; }
|
||||
|
||||
|
||||
public LoadEditorManifestOperation(string packageName, string manifestFilePath)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_manifestFilePath = manifestFilePath;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadEditorManifest;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadEditorManifest)
|
||||
{
|
||||
if (File.Exists(_manifestFilePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Not found simulation manifest file : {_manifestFilePath}";
|
||||
return;
|
||||
}
|
||||
|
||||
YooLogger.Log($"Load editor manifest file : {_manifestFilePath}");
|
||||
byte[] bytesData = FileUtility.ReadAllBytes(_manifestFilePath);
|
||||
_deserializer = new DeserializeManifestOperation(bytesData);
|
||||
OperationSystem.StartOperation(_packageName, _deserializer);
|
||||
_steps = ESteps.CheckDeserializeManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckDeserializeManifest)
|
||||
{
|
||||
Progress = _deserializer.Progress;
|
||||
if (_deserializer.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
Manifest = _deserializer.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _deserializer.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,151 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadRemoteManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
DownloadPackageHashFile,
|
||||
DownloadManifestFile,
|
||||
VerifyFileHash,
|
||||
CheckDeserializeManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private QueryRemotePackageHashOperation _queryRemotePackageHashOp;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private byte[] _fileData;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 加载的清单实例
|
||||
/// </summary>
|
||||
public PackageManifest Manifest { private set; get; }
|
||||
|
||||
|
||||
internal LoadRemoteManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
|
||||
{
|
||||
_remoteServices = remoteServices;
|
||||
_packageName = packageName;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(LoadRemoteManifestOperation));
|
||||
_steps = ESteps.DownloadPackageHashFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.DownloadPackageHashFile)
|
||||
{
|
||||
if (_queryRemotePackageHashOp == null)
|
||||
{
|
||||
_queryRemotePackageHashOp = new QueryRemotePackageHashOperation(_remoteServices, _packageName, _packageVersion, _timeout);
|
||||
OperationSystem.StartOperation(_packageName, _queryRemotePackageHashOp);
|
||||
}
|
||||
|
||||
if (_queryRemotePackageHashOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryRemotePackageHashOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.DownloadManifestFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _queryRemotePackageHashOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadManifestFile)
|
||||
{
|
||||
if (_downloader == null)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download manifest file : {webURL}");
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(webURL, _timeout);
|
||||
}
|
||||
|
||||
_downloader.CheckTimeout();
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(LoadRemoteManifestOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileData = _downloader.GetData();
|
||||
_steps = ESteps.VerifyFileHash;
|
||||
}
|
||||
|
||||
_downloader.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyFileHash)
|
||||
{
|
||||
string fileHash = HashUtility.BytesMD5(_fileData);
|
||||
if (fileHash != _queryRemotePackageHashOp.PackageHash)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Failed to verify remote manifest file hash !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_deserializer = new DeserializeManifestOperation(_fileData);
|
||||
OperationSystem.StartOperation(_packageName, _deserializer);
|
||||
_steps = ESteps.CheckDeserializeManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckDeserializeManifest)
|
||||
{
|
||||
Progress = _deserializer.Progress;
|
||||
if (_deserializer.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
Manifest = _deserializer.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _deserializer.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDownloadRequestURL(string fileName)
|
||||
{
|
||||
// 轮流返回请求地址
|
||||
if (_requestCount % 2 == 0)
|
||||
return _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
return _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 486ce3e7ad16f2948a36d49ecabd76b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,75 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class QueryBuildinPackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadBuildinPackageVersionFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
|
||||
|
||||
public QueryBuildinPackageVersionOperation(PersistentManager persistent)
|
||||
{
|
||||
_persistent = persistent;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadBuildinPackageVersionFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadBuildinPackageVersionFile)
|
||||
{
|
||||
if (_downloader == null)
|
||||
{
|
||||
string filePath = _persistent.GetBuildinPackageVersionFilePath();
|
||||
string url = PersistentHelper.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(url);
|
||||
}
|
||||
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
PackageVersion = _downloader.GetText();
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package version file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
_downloader.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bdc251ea99d82e54199dfba540f2814d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,64 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class QueryCachePackageHashOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadCachePackageHashFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly string _packageVersion;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹哈希值
|
||||
/// </summary>
|
||||
public string PackageHash { private set; get; }
|
||||
|
||||
|
||||
public QueryCachePackageHashOperation(PersistentManager persistent, string packageVersion)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadCachePackageHashFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadCachePackageHashFile)
|
||||
{
|
||||
string filePath = _persistent.GetSandboxPackageHashFilePath(_packageVersion);
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Cache package hash file not found : {filePath}";
|
||||
return;
|
||||
}
|
||||
|
||||
PackageHash = FileUtility.ReadAllText(filePath);
|
||||
if (string.IsNullOrEmpty(PackageHash))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Cache package hash file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60db6a6586340664ab7e9f85cec0eef4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,62 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class QueryCachePackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadCachePackageVersionFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
|
||||
|
||||
public QueryCachePackageVersionOperation(PersistentManager persistent)
|
||||
{
|
||||
_persistent = persistent;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadCachePackageVersionFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadCachePackageVersionFile)
|
||||
{
|
||||
string filePath = _persistent.GetSandboxPackageVersionFilePath();
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Cache package version file not found : {filePath}";
|
||||
return;
|
||||
}
|
||||
|
||||
PackageVersion = FileUtility.ReadAllText(filePath);
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Cache package version file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29a2cbdd051ba1247a24693d56cdc2c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,100 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class QueryRemotePackageHashOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
DownloadPackageHash,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹哈希值
|
||||
/// </summary>
|
||||
public string PackageHash { private set; get; }
|
||||
|
||||
|
||||
public QueryRemotePackageHashOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
|
||||
{
|
||||
_remoteServices = remoteServices;
|
||||
_packageName = packageName;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageHashOperation));
|
||||
_steps = ESteps.DownloadPackageHash;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.DownloadPackageHash)
|
||||
{
|
||||
if (_downloader == null)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||
string webURL = GetPackageHashRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to request package hash : {webURL}");
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(webURL, _timeout);
|
||||
}
|
||||
|
||||
Progress = _downloader.Progress();
|
||||
_downloader.CheckTimeout();
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageHashOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
PackageHash = _downloader.GetText();
|
||||
if (string.IsNullOrEmpty(PackageHash))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Remote package hash is empty : {_downloader.URL}";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
_downloader.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPackageHashRequestURL(string fileName)
|
||||
{
|
||||
string url;
|
||||
|
||||
// 轮流返回请求地址
|
||||
if (_requestCount % 2 == 0)
|
||||
url = _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
url = _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef77260f58172dd42ad10cfb862b78ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,104 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class QueryRemotePackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
DownloadPackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageName;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
|
||||
|
||||
public QueryRemotePackageVersionOperation(IRemoteServices remoteServices, string packageName, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_remoteServices = remoteServices;
|
||||
_packageName = packageName;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageVersionOperation));
|
||||
_steps = ESteps.DownloadPackageVersion;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.DownloadPackageVersion)
|
||||
{
|
||||
if (_downloader == null)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||
string webURL = GetPackageVersionRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to request package version : {webURL}");
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(webURL, _timeout);
|
||||
}
|
||||
|
||||
Progress = _downloader.Progress();
|
||||
_downloader.CheckTimeout();
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageVersionOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
PackageVersion = _downloader.GetText();
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Remote package version is empty : {_downloader.URL}";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
_downloader.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPackageVersionRequestURL(string fileName)
|
||||
{
|
||||
string url;
|
||||
|
||||
// 轮流返回请求地址
|
||||
if (_requestCount % 2 == 0)
|
||||
url = _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
url = _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
|
||||
// 在URL末尾添加时间戳
|
||||
if (_appendTimeTicks)
|
||||
return $"{url}?{System.DateTime.UtcNow.Ticks}";
|
||||
else
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d702a1a39789a34da99cbb854708b82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,92 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class UnpackBuildinManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
UnpackManifestHashFile,
|
||||
UnpackManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly string _buildinPackageVersion;
|
||||
private UnityWebFileRequester _downloader1;
|
||||
private UnityWebFileRequester _downloader2;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public UnpackBuildinManifestOperation(PersistentManager persistent, string buildinPackageVersion)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_buildinPackageVersion = buildinPackageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.UnpackManifestHashFile;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.UnpackManifestHashFile)
|
||||
{
|
||||
if (_downloader1 == null)
|
||||
{
|
||||
string savePath = _persistent.GetSandboxPackageHashFilePath(_buildinPackageVersion);
|
||||
string filePath = _persistent.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
||||
string url = PersistentHelper.ConvertToWWWPath(filePath);
|
||||
_downloader1 = new UnityWebFileRequester();
|
||||
_downloader1.SendRequest(url, savePath);
|
||||
}
|
||||
|
||||
if (_downloader1.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader1.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader1.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.UnpackManifestFile;
|
||||
}
|
||||
|
||||
_downloader1.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackManifestFile)
|
||||
{
|
||||
if (_downloader2 == null)
|
||||
{
|
||||
string savePath = _persistent.GetSandboxPackageManifestFilePath(_buildinPackageVersion);
|
||||
string filePath = _persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||
string url = PersistentHelper.ConvertToWWWPath(filePath);
|
||||
_downloader2 = new UnityWebFileRequester();
|
||||
_downloader2.SendRequest(url, savePath);
|
||||
}
|
||||
|
||||
if (_downloader2.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader2.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader2.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
_downloader2.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a7685e67b0e948439ffba34513b78c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -4,164 +4,53 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public abstract class PreDownloadContentOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public abstract ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="tag">资源标签</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public abstract ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="tags">资源标签列表</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public abstract ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public abstract ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="locations">资源定位地址列表</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public abstract ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
|
||||
}
|
||||
|
||||
internal class EditorPlayModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
{
|
||||
private readonly EditorSimulateModeImpl _impl;
|
||||
|
||||
public EditorPlayModePreDownloadContentOperation(EditorSimulateModeImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
}
|
||||
internal class OfflinePlayModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
{
|
||||
private readonly OfflinePlayModeImpl _impl;
|
||||
|
||||
public OfflinePlayModePreDownloadContentOperation(OfflinePlayModeImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
}
|
||||
internal class HostPlayModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
public sealed class PreDownloadContentOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckParams,
|
||||
CheckActiveManifest,
|
||||
TryLoadCacheManifest,
|
||||
DownloadManifest,
|
||||
LoadCacheManifest,
|
||||
LoadPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
|
||||
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||
private DownloadManifestOperation _downloadManifestOp;
|
||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private PackageManifest _manifest;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal HostPlayModePreDownloadContentOperation(HostPlayModeImpl impl, string packageVersion, int timeout)
|
||||
internal PreDownloadContentOperation(PlayModeImpl impl, string packageVersion, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
_steps = ESteps.CheckParams;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package version is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
{
|
||||
// 检测当前激活的清单对象
|
||||
@@ -175,69 +64,26 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
}
|
||||
_steps = ESteps.TryLoadCacheManifest;
|
||||
_steps = ESteps.LoadPackageManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.TryLoadCacheManifest)
|
||||
if (_steps == ESteps.LoadPackageManifest)
|
||||
{
|
||||
if (_tryLoadCacheManifestOp == null)
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _tryLoadCacheManifestOp);
|
||||
var mainFileSystem = _impl.GetMainFileSystem();
|
||||
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
|
||||
_loadPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_loadPackageManifestOp);
|
||||
}
|
||||
|
||||
if (_tryLoadCacheManifestOp.IsDone == false)
|
||||
_loadPackageManifestOp.UpdateOperation();
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_manifest = _tryLoadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.DownloadManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadManifest)
|
||||
{
|
||||
if (_downloadManifestOp == null)
|
||||
{
|
||||
_downloadManifestOp = new DownloadManifestOperation(_impl.Persistent, _impl.RemoteServices, _packageVersion, _timeout);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _downloadManifestOp);
|
||||
}
|
||||
|
||||
if (_downloadManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_downloadManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCacheManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloadManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheManifest)
|
||||
{
|
||||
if (_loadCacheManifestOp == null)
|
||||
{
|
||||
_loadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
|
||||
}
|
||||
|
||||
if (_loadCacheManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_manifest = _loadCacheManifestOp.Manifest;
|
||||
_manifest = _loadPackageManifestOp.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
@@ -245,69 +91,107 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadCacheManifestOp.Error;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="tag">资源标签</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="tags">资源标签列表</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<AssetInfo> assetInfos = new List<AssetInfo>();
|
||||
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
|
||||
assetInfos.Add(assetInfo);
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray());
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="locations">资源定位地址列表</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
if (Status != EOperationStatus.Succeed)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
||||
@@ -317,46 +201,9 @@ namespace YooAsset
|
||||
assetInfos.Add(assetInfo);
|
||||
}
|
||||
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray());
|
||||
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
internal class WebPlayModePreDownloadContentOperation : PreDownloadContentOperation
|
||||
{
|
||||
private readonly WebPlayModeImpl _impl;
|
||||
|
||||
public WebPlayModePreDownloadContentOperation(WebPlayModeImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public abstract class RequestPackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前最新的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { protected set; get; }
|
||||
}
|
||||
internal sealed class RequestPackageVersionImplOperation : RequestPackageVersionOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private FSRequestPackageVersionOperation _requestPackageVersionOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal RequestPackageVersionImplOperation(PlayModeImpl impl, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_requestPackageVersionOp == null)
|
||||
{
|
||||
var mainFileSystem = _impl.GetMainFileSystem();
|
||||
_requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout);
|
||||
_requestPackageVersionOp.StartOperation();
|
||||
AddChildOperation(_requestPackageVersionOp);
|
||||
}
|
||||
|
||||
_requestPackageVersionOp.UpdateOperation();
|
||||
if (_requestPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
PackageVersion = _requestPackageVersionOp.PackageVersion;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,93 +1,34 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 向远端请求并更新清单
|
||||
/// </summary>
|
||||
public abstract class UpdatePackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存当前清单的版本,用于下次启动时自动加载的版本。
|
||||
/// </summary>
|
||||
public virtual void SavePackageVersion() { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟运行的更新清单操作
|
||||
/// </summary>
|
||||
internal sealed class EditorPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||
{
|
||||
public EditorPlayModeUpdatePackageManifestOperation()
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离线模式的更新清单操作
|
||||
/// </summary>
|
||||
internal sealed class OfflinePlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||
{
|
||||
public OfflinePlayModeUpdatePackageManifestOperation()
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 联机模式的更新清单操作
|
||||
/// 注意:优先加载沙盒里缓存的清单文件,如果缓存没找到就下载远端清单文件,并保存到本地。
|
||||
/// </summary>
|
||||
internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||
public sealed class UpdatePackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckParams,
|
||||
CheckActiveManifest,
|
||||
TryLoadCacheManifest,
|
||||
DownloadManifest,
|
||||
LoadCacheManifest,
|
||||
LoadPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly string _packageVersion;
|
||||
private readonly bool _autoSaveVersion;
|
||||
private readonly int _timeout;
|
||||
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
|
||||
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||
private DownloadManifestOperation _downloadManifestOp;
|
||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageVersion, bool autoSaveVersion, int timeout)
|
||||
internal UpdatePackageManifestOperation(PlayModeImpl impl, string packageVersion, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageVersion = packageVersion;
|
||||
_autoSaveVersion = autoSaveVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckParams;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
@@ -99,10 +40,11 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package version is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
@@ -115,179 +57,41 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.TryLoadCacheManifest;
|
||||
_steps = ESteps.LoadPackageManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.TryLoadCacheManifest)
|
||||
if (_steps == ESteps.LoadPackageManifest)
|
||||
{
|
||||
if (_tryLoadCacheManifestOp == null)
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _tryLoadCacheManifestOp);
|
||||
var mainFileSystem = _impl.GetMainFileSystem();
|
||||
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
|
||||
_loadPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_loadPackageManifestOp);
|
||||
}
|
||||
|
||||
if (_tryLoadCacheManifestOp.IsDone == false)
|
||||
_loadPackageManifestOp.UpdateOperation();
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_impl.ActiveManifest = _tryLoadCacheManifestOp.Manifest;
|
||||
if (_autoSaveVersion)
|
||||
SavePackageVersion();
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.DownloadManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadManifest)
|
||||
{
|
||||
if (_downloadManifestOp == null)
|
||||
{
|
||||
_downloadManifestOp = new DownloadManifestOperation(_impl.Persistent, _impl.RemoteServices, _packageVersion, _timeout);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _downloadManifestOp);
|
||||
}
|
||||
|
||||
if (_downloadManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_downloadManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCacheManifest;
|
||||
}
|
||||
else
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloadManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheManifest)
|
||||
{
|
||||
if (_loadCacheManifestOp == null)
|
||||
{
|
||||
_loadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
|
||||
}
|
||||
|
||||
if (_loadCacheManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
|
||||
if (_autoSaveVersion)
|
||||
SavePackageVersion();
|
||||
_steps = ESteps.Done;
|
||||
_impl.ActiveManifest = _loadPackageManifestOp.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadCacheManifestOp.Error;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void SavePackageVersion()
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
_impl.FlushManifestVersionFile();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WebGL模式的更新清单操作
|
||||
/// </summary>
|
||||
internal sealed class WebPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckParams,
|
||||
CheckActiveManifest,
|
||||
LoadRemoteManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly WebPlayModeImpl _impl;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private LoadRemoteManifestOperation _loadCacheManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal WebPlayModeUpdatePackageManifestOperation(WebPlayModeImpl impl, string packageVersion, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.CheckParams;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package version is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
{
|
||||
// 检测当前激活的清单对象
|
||||
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadRemoteManifest;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadRemoteManifest)
|
||||
{
|
||||
if (_loadCacheManifestOp == null)
|
||||
{
|
||||
_loadCacheManifestOp = new LoadRemoteManifestOperation(_impl.RemoteServices, _impl.PackageName, _packageVersion, _timeout);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
|
||||
}
|
||||
|
||||
if (_loadCacheManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadCacheManifestOp.Error;
|
||||
}
|
||||
}
|
||||
return $"PackageVersion : {_packageVersion}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,165 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求远端包裹的最新版本
|
||||
/// </summary>
|
||||
public abstract class UpdatePackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前最新的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { protected set; get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟模式的请求远端包裹的最新版本
|
||||
/// </summary>
|
||||
internal sealed class EditorPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
|
||||
{
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离线模式的请求远端包裹的最新版本
|
||||
/// </summary>
|
||||
internal sealed class OfflinePlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
|
||||
{
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 联机模式的请求远端包裹的最新版本
|
||||
/// </summary>
|
||||
internal sealed class HostPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
QueryRemotePackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private QueryRemotePackageVersionOperation _queryRemotePackageVersionOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.QueryRemotePackageVersion;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.QueryRemotePackageVersion)
|
||||
{
|
||||
if (_queryRemotePackageVersionOp == null)
|
||||
{
|
||||
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _impl.PackageName, _appendTimeTicks, _timeout);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _queryRemotePackageVersionOp);
|
||||
}
|
||||
|
||||
if (_queryRemotePackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryRemotePackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _queryRemotePackageVersionOp.PackageVersion;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _queryRemotePackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WebGL模式的请求远端包裹的最新版本
|
||||
/// </summary>
|
||||
internal sealed class WebPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
QueryRemotePackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly WebPlayModeImpl _impl;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private QueryRemotePackageVersionOperation _queryRemotePackageVersionOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal WebPlayModeUpdatePackageVersionOperation(WebPlayModeImpl impl, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.QueryRemotePackageVersion;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.QueryRemotePackageVersion)
|
||||
{
|
||||
if (_queryRemotePackageVersionOp == null)
|
||||
{
|
||||
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _impl.PackageName, _appendTimeTicks, _timeout);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _queryRemotePackageVersionOp);
|
||||
}
|
||||
|
||||
if (_queryRemotePackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_queryRemotePackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _queryRemotePackageVersionOp.PackageVersion;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _queryRemotePackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -31,6 +31,18 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public int BundleID;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的资源包ID集合
|
||||
/// 说明:框架层收集查询结果
|
||||
/// </summary>
|
||||
public int[] DependBundleIDs;
|
||||
|
||||
/// <summary>
|
||||
/// 临时数据对象(仅编辑器有效)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public object TempDataInEditor;
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含Tag
|
||||
/// </summary>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -43,32 +44,33 @@ namespace YooAsset
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的资源包ID集合
|
||||
/// 注意:引擎层构建查询结果
|
||||
/// </summary>
|
||||
public int[] DependIDs;
|
||||
|
||||
public int[] DependBundleIDs;
|
||||
|
||||
/// <summary>
|
||||
/// 所属的包裹名称
|
||||
/// 资源包GUID
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属的构建管线
|
||||
/// </summary>
|
||||
public string Buildpipeline { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存GUID
|
||||
/// </summary>
|
||||
public string CacheGUID
|
||||
public string BundleGUID
|
||||
{
|
||||
get { return FileHash; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称
|
||||
/// 资源包类型
|
||||
/// </summary>
|
||||
private string _fileName;
|
||||
public int BundleType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bundleType;
|
||||
}
|
||||
}
|
||||
private int _bundleType;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称
|
||||
/// </summary>
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
@@ -78,11 +80,11 @@ namespace YooAsset
|
||||
return _fileName;
|
||||
}
|
||||
}
|
||||
private string _fileName;
|
||||
|
||||
/// <summary>
|
||||
/// 文件后缀名
|
||||
/// </summary>
|
||||
private string _fileExtension;
|
||||
public string FileExtension
|
||||
{
|
||||
get
|
||||
@@ -92,6 +94,21 @@ namespace YooAsset
|
||||
return _fileExtension;
|
||||
}
|
||||
}
|
||||
private string _fileExtension;
|
||||
|
||||
/// <summary>
|
||||
/// 包含的主资源集合
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public readonly List<PackageAsset> IncludeMainAssets = new List<PackageAsset>(10);
|
||||
|
||||
/// <summary>
|
||||
/// 引用该资源包的资源包列表
|
||||
/// 说明:谁引用了该资源包
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public readonly List<int> ReferenceBundleIDs = new List<int>(10);
|
||||
private readonly HashSet<int> _referenceBundleIDs = new HashSet<int>();
|
||||
|
||||
|
||||
public PackageBundle()
|
||||
@@ -99,16 +116,29 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析资源包
|
||||
/// 初始化资源包
|
||||
/// </summary>
|
||||
public void ParseBundle(PackageManifest manifest)
|
||||
public void InitBundle(PackageManifest manifest)
|
||||
{
|
||||
PackageName = manifest.PackageName;
|
||||
Buildpipeline = manifest.BuildPipeline;
|
||||
_mainfest = manifest;
|
||||
_bundleType = manifest.BuildBundleType;
|
||||
_fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName);
|
||||
_fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加引用该资源包的资源包ID
|
||||
/// 说明:谁引用了该资源包
|
||||
/// </summary>
|
||||
public void AddReferenceBundleID(int bundleID)
|
||||
{
|
||||
if (_referenceBundleIDs.Contains(bundleID) == false)
|
||||
{
|
||||
_referenceBundleIDs.Add(bundleID);
|
||||
ReferenceBundleIDs.Add(bundleID);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含Tag
|
||||
/// </summary>
|
||||
@@ -148,5 +178,23 @@ namespace YooAsset
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
private PackageManifest _mainfest;
|
||||
private List<string> _debugReferenceBundles;
|
||||
public List<string> GetDebugReferenceBundles()
|
||||
{
|
||||
if (_debugReferenceBundles == null)
|
||||
{
|
||||
_debugReferenceBundles = new List<string>(ReferenceBundleIDs.Count);
|
||||
foreach (int bundleID in ReferenceBundleIDs)
|
||||
{
|
||||
var packageBundle = _mainfest.BundleList[bundleID];
|
||||
_debugReferenceBundles.Add(packageBundle.BundleName);
|
||||
}
|
||||
}
|
||||
return _debugReferenceBundles;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class PackageDetails
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件版本
|
||||
/// </summary>
|
||||
public string FileVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable;
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址大小写不敏感
|
||||
/// </summary>
|
||||
public bool LocationToLower;
|
||||
|
||||
/// <summary>
|
||||
/// 包含资源GUID数据
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称样式
|
||||
/// </summary>
|
||||
public int OutputNameStyle;
|
||||
|
||||
/// <summary>
|
||||
/// 构建资源包类型
|
||||
/// </summary>
|
||||
public int BuildBundleType;
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线名称
|
||||
/// </summary>
|
||||
public string BuildPipeline;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包裹的版本信息
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包裹的备注信息
|
||||
/// </summary>
|
||||
public string PackageNote;
|
||||
|
||||
/// <summary>
|
||||
/// 主资源文件总数
|
||||
/// </summary>
|
||||
public int AssetTotalCount;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件总数
|
||||
/// </summary>
|
||||
public int BundleTotalCount;
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3a2fe7d8d4747d43b3ac48097341e36
|
||||
guid: 931f6c93109389b4f8fd4d48857d082b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -37,6 +37,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public int OutputNameStyle;
|
||||
|
||||
/// <summary>
|
||||
/// 构建资源包类型
|
||||
/// </summary>
|
||||
public int BuildBundleType;
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线名称
|
||||
/// </summary>
|
||||
@@ -52,6 +57,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包裹的备注信息
|
||||
/// </summary>
|
||||
public string PackageNote;
|
||||
|
||||
/// <summary>
|
||||
/// 资源列表(主动收集的资源列表)
|
||||
/// </summary>
|
||||
@@ -62,25 +72,6 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public List<PackageBundle> BundleList = new List<PackageBundle>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供BundleName获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic1;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供FileName获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic2;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供CacheGUID获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic3;
|
||||
|
||||
/// <summary>
|
||||
/// 资源映射集合(提供AssetPath获取PackageAsset)
|
||||
/// </summary>
|
||||
@@ -99,6 +90,45 @@ namespace YooAsset
|
||||
[NonSerialized]
|
||||
public Dictionary<string, string> AssetPathMapping2;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供BundleName获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic1;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供FileName获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic2;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供BundleGUID获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic3;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹的详细信息
|
||||
/// </summary>
|
||||
public PackageDetails GetPackageDetails()
|
||||
{
|
||||
PackageDetails details = new PackageDetails();
|
||||
details.FileVersion = FileVersion;
|
||||
details.EnableAddressable = EnableAddressable;
|
||||
details.LocationToLower = LocationToLower;
|
||||
details.IncludeAssetGUID = IncludeAssetGUID;
|
||||
details.OutputNameStyle = OutputNameStyle;
|
||||
details.BuildBundleType = BuildBundleType;
|
||||
details.BuildPipeline = BuildPipeline;
|
||||
details.PackageName = PackageName;
|
||||
details.PackageVersion = PackageVersion;
|
||||
details.PackageNote = PackageNote;
|
||||
details.AssetTotalCount = AssetList.Count;
|
||||
details.BundleTotalCount = BundleList.Count;
|
||||
return details;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试映射为资源路径
|
||||
@@ -119,48 +149,41 @@ namespace YooAsset
|
||||
|
||||
/// <summary>
|
||||
/// 获取主资源包
|
||||
/// 注意:传入的资源路径一定合法有效!
|
||||
/// 注意:传入的资源包ID一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle GetMainPackageBundle(string assetPath)
|
||||
public PackageBundle GetMainPackageBundle(int bundleID)
|
||||
{
|
||||
if (AssetDic.TryGetValue(assetPath, out PackageAsset packageAsset))
|
||||
if (bundleID >= 0 && bundleID < BundleList.Count)
|
||||
{
|
||||
int bundleID = packageAsset.BundleID;
|
||||
if (bundleID >= 0 && bundleID < BundleList.Count)
|
||||
{
|
||||
var packageBundle = BundleList[bundleID];
|
||||
return packageBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {assetPath}");
|
||||
}
|
||||
var packageBundle = BundleList[bundleID];
|
||||
return packageBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Should never get here !");
|
||||
throw new Exception($"Invalid bundle id : {bundleID}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源依赖列表
|
||||
/// 注意:传入的资源路径一定合法有效!
|
||||
/// 获取主资源包
|
||||
/// 注意:传入的资源对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(string assetPath)
|
||||
public PackageBundle GetMainPackageBundle(PackageAsset packageAsset)
|
||||
{
|
||||
var packageBundle = GetMainPackageBundle(assetPath);
|
||||
List<PackageBundle> result = new List<PackageBundle>(packageBundle.DependIDs.Length);
|
||||
foreach (var dependID in packageBundle.DependIDs)
|
||||
return GetMainPackageBundle(packageAsset.BundleID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源依赖列表
|
||||
/// 注意:传入的资源对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(PackageAsset packageAsset)
|
||||
{
|
||||
List<PackageBundle> result = new List<PackageBundle>(packageAsset.DependBundleIDs.Length);
|
||||
foreach (var dependID in packageAsset.DependBundleIDs)
|
||||
{
|
||||
if (dependID >= 0 && dependID < BundleList.Count)
|
||||
{
|
||||
var dependBundle = BundleList[dependID];
|
||||
result.Add(dependBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid bundle id : {dependID} Asset path : {assetPath}");
|
||||
}
|
||||
var dependBundle = GetMainPackageBundle(dependID);
|
||||
result.Add(dependBundle);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
@@ -192,23 +215,37 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源包
|
||||
/// </summary>
|
||||
public bool TryGetPackageBundleByCacheGUID(string cacheGUID, out PackageBundle result)
|
||||
public bool TryGetPackageBundleByBundleGUID(string bundleGUID, out PackageBundle result)
|
||||
{
|
||||
return BundleDic3.TryGetValue(cacheGUID, out result);
|
||||
return BundleDic3.TryGetValue(bundleGUID, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
/// </summary>
|
||||
public bool IsIncludeBundleFile(string cacheGUID)
|
||||
public bool IsIncludeBundleFile(string bundleGUID)
|
||||
{
|
||||
return BundleDic3.ContainsKey(cacheGUID);
|
||||
return BundleDic3.ContainsKey(bundleGUID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的资源信息
|
||||
/// </summary>
|
||||
public AssetInfo[] GetAllAssetInfos()
|
||||
{
|
||||
List<AssetInfo> result = new List<AssetInfo>(AssetList.Count);
|
||||
foreach (var packageAsset in AssetList)
|
||||
{
|
||||
AssetInfo assetInfo = new AssetInfo(PackageName, packageAsset, null);
|
||||
result.Add(assetInfo);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表
|
||||
/// </summary>
|
||||
public AssetInfo[] GetAssetsInfoByTags(string[] tags)
|
||||
public AssetInfo[] GetAssetInfosByTags(string[] tags)
|
||||
{
|
||||
List<AssetInfo> result = new List<AssetInfo>(100);
|
||||
foreach (var packageAsset in AssetList)
|
||||
@@ -318,25 +355,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包内的主资源列表
|
||||
/// </summary>
|
||||
public string[] GetBundleIncludeAssets(string assetPath)
|
||||
{
|
||||
List<string> assetList = new List<string>();
|
||||
if (TryGetPackageAsset(assetPath, out PackageAsset result))
|
||||
{
|
||||
foreach (var packageAsset in AssetList)
|
||||
{
|
||||
if (packageAsset.BundleID == result.BundleID)
|
||||
{
|
||||
assetList.Add(packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return assetList.ToArray();
|
||||
}
|
||||
|
||||
#region 调试方法
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugCheckLocation(string location)
|
||||
@@ -344,7 +362,7 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
// 检查路径末尾是否有空格
|
||||
int index = location.LastIndexOf(" ");
|
||||
int index = location.LastIndexOf(' ');
|
||||
if (index != -1)
|
||||
{
|
||||
if (location.Length == index + 1)
|
||||
|
@@ -1,58 +1,16 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public static class EditorSimulateModeHelper
|
||||
public class EditorSimulateModeHelper
|
||||
{
|
||||
private static System.Type _classType;
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟构建清单
|
||||
/// </summary>
|
||||
public static string SimulateBuild(string buildPipelineName, string packageName)
|
||||
public static PackageInvokeBuildResult SimulateBuild(string packageName)
|
||||
{
|
||||
if (_classType == null)
|
||||
_classType = Assembly.Load("YooAsset.Editor").GetType("YooAsset.Editor.AssetBundleSimulateBuilder");
|
||||
|
||||
string manifestFilePath = (string)InvokePublicStaticMethod(_classType, "SimulateBuild", buildPipelineName, packageName);
|
||||
return manifestFilePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟构建清单
|
||||
/// </summary>
|
||||
public static string SimulateBuild(EDefaultBuildPipeline buildPipeline, string packageName)
|
||||
{
|
||||
return SimulateBuild(buildPipeline.ToString(), packageName);
|
||||
}
|
||||
|
||||
private static object InvokePublicStaticMethod(System.Type type, string method, params object[] parameters)
|
||||
{
|
||||
var methodInfo = type.GetMethod(method, BindingFlags.Public | BindingFlags.Static);
|
||||
if (methodInfo == null)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"{type.FullName} not found method : {method}");
|
||||
return null;
|
||||
}
|
||||
return methodInfo.Invoke(null, parameters);
|
||||
var buildParam = new PackageInvokeBuildParam(packageName);
|
||||
buildParam.BuildPipelineName = "EditorSimulateBuildPipeline";
|
||||
buildParam.InvokeAssmeblyName = "YooAsset.Editor";
|
||||
buildParam.InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
|
||||
buildParam.InvokeMethodName = "SimulateBuild";
|
||||
return PakcageInvokeBuilder.InvokeBuilder(buildParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
namespace YooAsset
|
||||
{
|
||||
public static class EditorSimulateModeHelper
|
||||
{
|
||||
public static string SimulateBuild(string buildPipelineName, string packageName)
|
||||
{
|
||||
throw new System.Exception("Only support in unity editor !");
|
||||
}
|
||||
|
||||
public static string SimulateBuild(EDefaultBuildPipeline buildPipeline, string packageName)
|
||||
{
|
||||
throw new System.Exception("Only support in unity editor !");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b09fe4b7aa2d2143bc538976541b039
|
||||
guid: b0a23f529c8bf4943a371ee6b360e698
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
@@ -1,161 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class EditorSimulateModeImpl : IPlayMode, IBundleQuery
|
||||
{
|
||||
private PackageManifest _activeManifest;
|
||||
private ResourceAssist _assist;
|
||||
|
||||
public readonly string PackageName;
|
||||
public DownloadManager Download
|
||||
{
|
||||
get { return _assist.Download; }
|
||||
}
|
||||
|
||||
public EditorSimulateModeImpl(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist, string simulateManifestFilePath)
|
||||
{
|
||||
_assist = assist;
|
||||
|
||||
var operation = new EditorSimulateModeInitializationOperation(this, simulateManifestFilePath);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
#region IPlayMode接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
set
|
||||
{
|
||||
_activeManifest = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _activeManifest;
|
||||
}
|
||||
}
|
||||
public void FlushManifestVersionFile()
|
||||
{
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new EditorPlayModeUpdatePackageVersionOperation();
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
|
||||
{
|
||||
var operation = new EditorPlayModeUpdatePackageManifestOperation();
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new EditorPlayModePreDownloadContentOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceImporterOperation.CreateEmptyImporter(Download, PackageName, importerMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleQuery接口
|
||||
private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo)
|
||||
{
|
||||
if (packageBundle == null)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromEditor);
|
||||
bundleInfo.IncludeAssetsInEditor = _activeManifest.GetBundleIncludeAssets(assetInfo.AssetPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return CreateBundleInfo(packageBundle, assetInfo);
|
||||
}
|
||||
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return packageBundle.BundleName;
|
||||
}
|
||||
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
result.Add(packageBundle.BundleName);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
bool IBundleQuery.ManifestValid()
|
||||
{
|
||||
return _activeManifest != null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fb1b9a2a91f1af4a86acfcfac424e0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,417 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class HostPlayModeImpl : IPlayMode, IBundleQuery
|
||||
{
|
||||
private PackageManifest _activeManifest;
|
||||
private ResourceAssist _assist;
|
||||
private IBuildinQueryServices _buildinQueryServices;
|
||||
private IDeliveryQueryServices _deliveryQueryServices;
|
||||
private IRemoteServices _remoteServices;
|
||||
|
||||
public readonly string PackageName;
|
||||
public DownloadManager Download
|
||||
{
|
||||
get { return _assist.Download; }
|
||||
}
|
||||
public PersistentManager Persistent
|
||||
{
|
||||
get { return _assist.Persistent; }
|
||||
}
|
||||
public CacheManager Cache
|
||||
{
|
||||
get { return _assist.Cache; }
|
||||
}
|
||||
public IRemoteServices RemoteServices
|
||||
{
|
||||
get { return _remoteServices; }
|
||||
}
|
||||
|
||||
|
||||
public HostPlayModeImpl(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IDeliveryQueryServices deliveryQueryServices, IRemoteServices remoteServices)
|
||||
{
|
||||
_assist = assist;
|
||||
_buildinQueryServices = buildinQueryServices;
|
||||
_deliveryQueryServices = deliveryQueryServices;
|
||||
_remoteServices = remoteServices;
|
||||
|
||||
var operation = new HostPlayModeInitializationOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 下载相关
|
||||
private List<BundleInfo> ConvertToDownloadList(List<PackageBundle> downloadList)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
|
||||
foreach (var packageBundle in downloadList)
|
||||
{
|
||||
var bundleInfo = ConvertToDownloadInfo(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
|
||||
{
|
||||
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
|
||||
string remoteFallbackURL = _remoteServices.GetRemoteFallbackURL(packageBundle.FileName);
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
private bool IsDeliveryPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
if (_deliveryQueryServices == null)
|
||||
return false;
|
||||
return _deliveryQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
}
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _assist.Cache.IsCached(packageBundle.CacheGUID);
|
||||
}
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
}
|
||||
|
||||
#region IPlayMode接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
set
|
||||
{
|
||||
_activeManifest = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _activeManifest;
|
||||
}
|
||||
}
|
||||
public void FlushManifestVersionFile()
|
||||
{
|
||||
if (_activeManifest != null)
|
||||
{
|
||||
_assist.Persistent.SaveSandboxPackageVersionFile(_activeManifest.PackageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModeUpdatePackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModeUpdatePackageManifestOperation(this, packageVersion, autoSaveVersion, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModePreDownloadContentOperation(this, packageVersion, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByAll(_activeManifest);
|
||||
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByTags(_activeManifest, tags);
|
||||
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 如果未带任何标记,则统一下载
|
||||
if (packageBundle.HasAnyTags() == false)
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 查询DLC资源
|
||||
if (packageBundle.HasTag(tags))
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByPaths(_activeManifest, assetInfos);
|
||||
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos)
|
||||
{
|
||||
// 获取资源对象的资源包和所有依赖资源包
|
||||
List<PackageBundle> checkList = new List<PackageBundle>();
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
if (checkList.Contains(mainBundle) == false)
|
||||
checkList.Add(mainBundle);
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
foreach (var dependBundle in dependBundles)
|
||||
{
|
||||
if (checkList.Contains(dependBundle) == false)
|
||||
checkList.Add(dependBundle);
|
||||
}
|
||||
}
|
||||
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in checkList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> unpcakList = GetUnpackListByAll(_activeManifest);
|
||||
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
}
|
||||
|
||||
return BundleInfo.CreateUnpackInfos(_assist, downloadList);
|
||||
}
|
||||
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> unpcakList = GetUnpackListByTags(_activeManifest, tags);
|
||||
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 查询DLC资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
{
|
||||
if (packageBundle.HasTag(tags))
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BundleInfo.CreateUnpackInfos(_assist, downloadList);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
|
||||
var operation = new ResourceImporterOperation(Download, PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(filePath);
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
var bundleInfo = BundleInfo.CreateImportInfo(_assist, packageBundle, filePath);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleQuery接口
|
||||
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
||||
{
|
||||
if (packageBundle == null)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 查询分发资源
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
{
|
||||
string deliveryFilePath = _deliveryQueryServices.GetFilePath(PackageName, packageBundle.FileName);
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromDelivery, deliveryFilePath);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 查询沙盒资源
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromCache);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 查询APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 从服务端下载
|
||||
return ConvertToDownloadInfo(packageBundle);
|
||||
}
|
||||
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return CreateBundleInfo(packageBundle);
|
||||
}
|
||||
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
BundleInfo bundleInfo = CreateBundleInfo(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return packageBundle.BundleName;
|
||||
}
|
||||
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
result.Add(packageBundle.BundleName);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
bool IBundleQuery.ManifestValid()
|
||||
{
|
||||
return _activeManifest != null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84c10fd3507a1c24a9043aebb72db5f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,246 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class OfflinePlayModeImpl : IPlayMode, IBundleQuery
|
||||
{
|
||||
private PackageManifest _activeManifest;
|
||||
private ResourceAssist _assist;
|
||||
|
||||
public readonly string PackageName;
|
||||
public DownloadManager Download
|
||||
{
|
||||
get { return _assist.Download; }
|
||||
}
|
||||
public PersistentManager Persistent
|
||||
{
|
||||
get { return _assist.Persistent; }
|
||||
}
|
||||
public CacheManager Cache
|
||||
{
|
||||
get { return _assist.Cache; }
|
||||
}
|
||||
|
||||
|
||||
public OfflinePlayModeImpl(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist)
|
||||
{
|
||||
_assist = assist;
|
||||
|
||||
var operation = new OfflinePlayModeInitializationOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _assist.Cache.IsCached(packageBundle.CacheGUID);
|
||||
}
|
||||
|
||||
#region IPlayMode接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
set
|
||||
{
|
||||
_activeManifest = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _activeManifest;
|
||||
}
|
||||
}
|
||||
public void FlushManifestVersionFile()
|
||||
{
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
|
||||
{
|
||||
var operation = new OfflinePlayModeUpdatePackageManifestOperation();
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new OfflinePlayModePreDownloadContentOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> unpcakList = GetUnpackListByAll(_activeManifest);
|
||||
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
|
||||
return BundleInfo.CreateUnpackInfos(_assist, downloadList);
|
||||
}
|
||||
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> unpcakList = GetUnpackListByTags(_activeManifest, tags);
|
||||
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 查询DLC资源
|
||||
if (packageBundle.HasTag(tags))
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
}
|
||||
|
||||
return BundleInfo.CreateUnpackInfos(_assist, downloadList);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
|
||||
var operation = new ResourceImporterOperation(Download, PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(filePath);
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
var bundleInfo = BundleInfo.CreateImportInfo(_assist, packageBundle, filePath);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleQuery接口
|
||||
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
||||
{
|
||||
if (packageBundle == null)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 查询沙盒资源
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromCache);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 查询APP资源
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
||||
return bundleInfo;
|
||||
}
|
||||
}
|
||||
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return CreateBundleInfo(packageBundle);
|
||||
}
|
||||
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
BundleInfo bundleInfo = CreateBundleInfo(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return packageBundle.BundleName;
|
||||
}
|
||||
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
result.Add(packageBundle.BundleName);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
bool IBundleQuery.ManifestValid()
|
||||
{
|
||||
return _activeManifest != null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc10550f17aaeb14795135a51444de1c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,436 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class PlayModeImpl : IPlayMode, IBundleQuery
|
||||
{
|
||||
public readonly string PackageName;
|
||||
public readonly EPlayMode PlayMode;
|
||||
public readonly List<IFileSystem> FileSystems = new List<IFileSystem>(10);
|
||||
|
||||
public PlayModeImpl(string packageName, EPlayMode playMode)
|
||||
{
|
||||
PackageName = packageName;
|
||||
PlayMode = playMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameter)
|
||||
{
|
||||
var fileSystemParamList = new List<FileSystemParameters>();
|
||||
if (fileSystemParameter != null)
|
||||
fileSystemParamList.Add(fileSystemParameter);
|
||||
return InitializeAsync(fileSystemParamList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameterA, FileSystemParameters fileSystemParameterB)
|
||||
{
|
||||
var fileSystemParamList = new List<FileSystemParameters>();
|
||||
if (fileSystemParameterA != null)
|
||||
fileSystemParamList.Add(fileSystemParameterA);
|
||||
if (fileSystemParameterB != null)
|
||||
fileSystemParamList.Add(fileSystemParameterB);
|
||||
return InitializeAsync(fileSystemParamList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(List<FileSystemParameters> fileSystemParameterList)
|
||||
{
|
||||
var operation = new InitializationOperation(this, fileSystemParameterList);
|
||||
return operation;
|
||||
}
|
||||
|
||||
#region IPlayMode接口
|
||||
/// <summary>
|
||||
/// 当前激活的清单
|
||||
/// </summary>
|
||||
public PackageManifest ActiveManifest { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 销毁文件系统
|
||||
/// </summary>
|
||||
void IPlayMode.DestroyFileSystem()
|
||||
{
|
||||
foreach (var fileSystem in FileSystems)
|
||||
{
|
||||
fileSystem.OnDestroy();
|
||||
}
|
||||
FileSystems.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求最新的资源版本
|
||||
/// </summary>
|
||||
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new RequestPackageVersionImplOperation(this, appendTimeTicks, timeout);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// </summary>
|
||||
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new UpdatePackageManifestOperation(this, packageVersion, timeout);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹内容
|
||||
/// </summary>
|
||||
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new PreDownloadContentOperation(this, packageVersion, timeout);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
|
||||
{
|
||||
var operation = new ClearCacheFilesOperation(this, clearMode, clearParam);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 下载相关
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
|
||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
|
||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
|
||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 解压相关
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
|
||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
|
||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 导入相关
|
||||
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
|
||||
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleQuery接口
|
||||
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
||||
{
|
||||
if (packageBundle == null)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||
if (fileSystem != null)
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(fileSystem, packageBundle);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
|
||||
}
|
||||
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo == null || assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
return CreateBundleInfo(packageBundle);
|
||||
}
|
||||
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo == null || assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
BundleInfo bundleInfo = CreateBundleInfo(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
string IBundleQuery.GetMainBundleName(int bundleID)
|
||||
{
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
|
||||
return packageBundle.BundleName;
|
||||
}
|
||||
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo == null || assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
return packageBundle.BundleName;
|
||||
}
|
||||
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo == null || assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
result.Add(packageBundle.BundleName);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取主文件系统
|
||||
/// 说明:文件系统列表里,最后一个属于主文件系统
|
||||
/// </summary>
|
||||
public IFileSystem GetMainFileSystem()
|
||||
{
|
||||
int count = FileSystems.Count;
|
||||
if (count == 0)
|
||||
return null;
|
||||
return FileSystems[count - 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包所属文件系统
|
||||
/// </summary>
|
||||
public IFileSystem GetBelongFileSystem(PackageBundle packageBundle)
|
||||
{
|
||||
for (int i = 0; i < FileSystems.Count; i++)
|
||||
{
|
||||
IFileSystem fileSystem = FileSystems[i];
|
||||
if (fileSystem.Belong(packageBundle))
|
||||
{
|
||||
return fileSystem;
|
||||
}
|
||||
}
|
||||
|
||||
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||
if (fileSystem == null)
|
||||
continue;
|
||||
|
||||
if (fileSystem.NeedDownload(packageBundle))
|
||||
{
|
||||
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||
if (fileSystem == null)
|
||||
continue;
|
||||
|
||||
if (fileSystem.NeedDownload(packageBundle))
|
||||
{
|
||||
// 如果未带任何标记,则统一下载
|
||||
if (packageBundle.HasAnyTags() == false)
|
||||
{
|
||||
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 查询DLC资源
|
||||
if (packageBundle.HasTag(tags))
|
||||
{
|
||||
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
|
||||
// 获取资源对象的资源包和所有依赖资源包
|
||||
List<PackageBundle> checkList = new List<PackageBundle>();
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
if (checkList.Contains(mainBundle) == false)
|
||||
checkList.Add(mainBundle);
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle[] mainDependBundles = manifest.GetAllDependencies(assetInfo.Asset);
|
||||
foreach (var dependBundle in mainDependBundles)
|
||||
{
|
||||
if (checkList.Contains(dependBundle) == false)
|
||||
checkList.Add(dependBundle);
|
||||
}
|
||||
|
||||
// 下载主资源包内所有资源对象依赖的资源包
|
||||
if (recursiveDownload)
|
||||
{
|
||||
foreach (var otherMainAsset in mainBundle.IncludeMainAssets)
|
||||
{
|
||||
var otherMainBundle = manifest.GetMainPackageBundle(otherMainAsset.BundleID);
|
||||
if (checkList.Contains(otherMainBundle) == false)
|
||||
checkList.Add(otherMainBundle);
|
||||
|
||||
PackageBundle[] otherDependBundles = manifest.GetAllDependencies(otherMainAsset);
|
||||
foreach (var dependBundle in otherDependBundles)
|
||||
{
|
||||
if (checkList.Contains(dependBundle) == false)
|
||||
checkList.Add(dependBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(1000);
|
||||
foreach (var packageBundle in checkList)
|
||||
{
|
||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||
if (fileSystem == null)
|
||||
continue;
|
||||
|
||||
if (fileSystem.NeedDownload(packageBundle))
|
||||
{
|
||||
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||
if (fileSystem == null)
|
||||
continue;
|
||||
|
||||
if (fileSystem.NeedUnpack(packageBundle))
|
||||
{
|
||||
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||
if (fileSystem == null)
|
||||
continue;
|
||||
|
||||
if (fileSystem.NeedUnpack(packageBundle))
|
||||
{
|
||||
if (packageBundle.HasTag(tags))
|
||||
{
|
||||
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(filePath);
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
||||
{
|
||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||
if (fileSystem == null)
|
||||
continue;
|
||||
|
||||
if (fileSystem.NeedImport(packageBundle))
|
||||
{
|
||||
var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fa439f7b3213444290b3df1af1d8140
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,312 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class WebPlayModeImpl : IPlayMode, IBundleQuery
|
||||
{
|
||||
private PackageManifest _activeManifest;
|
||||
private ResourceAssist _assist;
|
||||
private IBuildinQueryServices _buildinQueryServices;
|
||||
private IRemoteServices _remoteServices;
|
||||
private IWechatQueryServices _wechatQueryServices;
|
||||
|
||||
public readonly string PackageName;
|
||||
public DownloadManager Download
|
||||
{
|
||||
get { return _assist.Download; }
|
||||
}
|
||||
public PersistentManager Persistent
|
||||
{
|
||||
get { return _assist.Persistent; }
|
||||
}
|
||||
public IRemoteServices RemoteServices
|
||||
{
|
||||
get { return _remoteServices; }
|
||||
}
|
||||
|
||||
|
||||
public WebPlayModeImpl(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices, IWechatQueryServices wechatQueryServices)
|
||||
{
|
||||
_assist = assist;
|
||||
_buildinQueryServices = buildinQueryServices;
|
||||
_remoteServices = remoteServices;
|
||||
_wechatQueryServices = wechatQueryServices;
|
||||
|
||||
var operation = new WebPlayModeInitializationOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 下载相关
|
||||
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
|
||||
{
|
||||
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
|
||||
string remoteFallbackURL = _remoteServices.GetRemoteFallbackURL(packageBundle.FileName);
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
||||
return bundleInfo;
|
||||
}
|
||||
private List<BundleInfo> ConvertToDownloadList(List<PackageBundle> downloadList)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
|
||||
foreach (var packageBundle in downloadList)
|
||||
{
|
||||
var bundleInfo = ConvertToDownloadInfo(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
if (_wechatQueryServices != null)
|
||||
return _wechatQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
}
|
||||
|
||||
#region IPlayMode接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
set
|
||||
{
|
||||
_activeManifest = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _activeManifest;
|
||||
}
|
||||
}
|
||||
public void FlushManifestVersionFile()
|
||||
{
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new WebPlayModeUpdatePackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
|
||||
{
|
||||
var operation = new WebPlayModeUpdatePackageManifestOperation(this, packageVersion, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new WebPlayModePreDownloadContentOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByAll(_activeManifest);
|
||||
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByTags(_activeManifest, tags);
|
||||
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 如果未带任何标记,则统一下载
|
||||
if (packageBundle.HasAnyTags() == false)
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 查询DLC资源
|
||||
if (packageBundle.HasTag(tags))
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = GetDownloadListByPaths(_activeManifest, assetInfos);
|
||||
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos)
|
||||
{
|
||||
// 获取资源对象的资源包和所有依赖资源包
|
||||
List<PackageBundle> checkList = new List<PackageBundle>();
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
if (checkList.Contains(mainBundle) == false)
|
||||
checkList.Add(mainBundle);
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
foreach (var dependBundle in dependBundles)
|
||||
{
|
||||
if (checkList.Contains(dependBundle) == false)
|
||||
checkList.Add(dependBundle);
|
||||
}
|
||||
}
|
||||
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in checkList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceImporterOperation.CreateEmptyImporter(Download, PackageName, importerMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleQuery接口
|
||||
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
||||
{
|
||||
if (packageBundle == null)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 查询APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
{
|
||||
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 从服务端下载
|
||||
return ConvertToDownloadInfo(packageBundle);
|
||||
}
|
||||
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return CreateBundleInfo(packageBundle);
|
||||
}
|
||||
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
BundleInfo bundleInfo = CreateBundleInfo(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
string IBundleQuery.GetMainBundleName(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
return packageBundle.BundleName;
|
||||
}
|
||||
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
result.Add(packageBundle.BundleName);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
bool IBundleQuery.ManifestValid()
|
||||
{
|
||||
return _activeManifest != null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa7d8823ee040534db067e6e2c254267
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,11 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class ResourceAssist
|
||||
{
|
||||
public CacheManager Cache { set; get; }
|
||||
public PersistentManager Persistent { set; get; }
|
||||
public DownloadManager Download { set; get; }
|
||||
public ResourceLoader Loader { set; get; }
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 395d187f862588340b6fe7c437f477ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -14,11 +14,7 @@ namespace YooAsset
|
||||
private EPlayMode _playMode;
|
||||
|
||||
// 管理器
|
||||
private CacheManager _cacheMgr;
|
||||
private PersistentManager _persistentMgr;
|
||||
private DownloadManager _downloadMgr;
|
||||
private ResourceManager _resourceMgr;
|
||||
private ResourceLoader _resourceLoader;
|
||||
private ResourceManager _resourceManager;
|
||||
private IBundleQuery _bundleQuery;
|
||||
private IPlayMode _playModeImpl;
|
||||
|
||||
@@ -35,27 +31,25 @@ namespace YooAsset
|
||||
get { return _initializeStatus; }
|
||||
}
|
||||
|
||||
|
||||
private ResourcePackage()
|
||||
/// <summary>
|
||||
/// 包裹是否有效
|
||||
/// </summary>
|
||||
public bool PackageValid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_playModeImpl == null)
|
||||
return false;
|
||||
return _playModeImpl.ActiveManifest != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal ResourcePackage(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新资源包裹
|
||||
/// </summary>
|
||||
internal void UpdatePackage()
|
||||
{
|
||||
if (_resourceMgr != null)
|
||||
_resourceMgr.Update();
|
||||
|
||||
if (_downloadMgr != null)
|
||||
_downloadMgr.Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁资源包裹
|
||||
/// </summary>
|
||||
@@ -67,32 +61,19 @@ namespace YooAsset
|
||||
_initializeError = string.Empty;
|
||||
_initializeStatus = EOperationStatus.None;
|
||||
|
||||
// 销毁资源管理器
|
||||
if (_resourceManager != null)
|
||||
{
|
||||
_resourceManager.Destroy();
|
||||
_resourceManager = null;
|
||||
}
|
||||
|
||||
// 销毁文件系统
|
||||
if (_playModeImpl != null)
|
||||
_playModeImpl.DestroyFileSystem();
|
||||
|
||||
_bundleQuery = null;
|
||||
_playModeImpl = null;
|
||||
_persistentMgr = null;
|
||||
_resourceLoader = null;
|
||||
|
||||
if (_resourceMgr != null)
|
||||
{
|
||||
_resourceMgr.ForceUnloadAllAssets();
|
||||
_resourceMgr = null;
|
||||
}
|
||||
|
||||
if (_downloadMgr != null)
|
||||
{
|
||||
_downloadMgr.DestroyAll();
|
||||
_downloadMgr = null;
|
||||
}
|
||||
|
||||
if (_cacheMgr != null)
|
||||
{
|
||||
_cacheMgr.ClearAll();
|
||||
_cacheMgr = null;
|
||||
}
|
||||
|
||||
// 最后清理该包裹的异步任务
|
||||
// 注意:对于有线程操作的异步任务,需要保证线程安全释放。
|
||||
OperationSystem.ClearPackageOperation(PackageName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,91 +82,52 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(InitializeParameters parameters)
|
||||
{
|
||||
// 注意:WebGL平台因为网络原因可能会初始化失败!
|
||||
// 注意:联机平台因为网络原因可能会初始化失败!
|
||||
ResetInitializeAfterFailed();
|
||||
|
||||
// 检测初始化参数合法性
|
||||
CheckInitializeParameters(parameters);
|
||||
|
||||
// 创建缓存管理器
|
||||
_cacheMgr = new CacheManager(PackageName, parameters.CacheBootVerifyLevel);
|
||||
|
||||
// 创建持久化管理器
|
||||
_persistentMgr = new PersistentManager(PackageName);
|
||||
_persistentMgr.Initialize(parameters.BuildinRootDirectory, parameters.SandboxRootDirectory, parameters.CacheFileAppendExtension);
|
||||
|
||||
// 创建下载管理器
|
||||
_downloadMgr = new DownloadManager(PackageName);
|
||||
_downloadMgr.Initialize(parameters.BreakpointResumeFileSize);
|
||||
|
||||
// 创建资源包加载器
|
||||
if (_playMode == EPlayMode.HostPlayMode)
|
||||
// 销毁资源管理器
|
||||
if (_resourceManager != null)
|
||||
{
|
||||
var initializeParameters = parameters as HostPlayModeParameters;
|
||||
_resourceLoader = new ResourceLoader();
|
||||
_resourceLoader.Init(parameters.DecryptionServices, initializeParameters.DeliveryLoadServices);
|
||||
}
|
||||
else
|
||||
{
|
||||
_resourceLoader = new ResourceLoader();
|
||||
_resourceLoader.Init(parameters.DecryptionServices, null);
|
||||
_resourceManager.Destroy();
|
||||
_resourceManager = null;
|
||||
}
|
||||
|
||||
// 创建资源协助类
|
||||
ResourceAssist assist = new ResourceAssist();
|
||||
assist.Cache = _cacheMgr;
|
||||
assist.Persistent = _persistentMgr;
|
||||
assist.Download = _downloadMgr;
|
||||
assist.Loader = _resourceLoader;
|
||||
// 创建资源管理器
|
||||
_resourceManager = new ResourceManager(PackageName);
|
||||
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
|
||||
_bundleQuery = playModeImpl;
|
||||
_playModeImpl = playModeImpl;
|
||||
_resourceManager.Initialize(_bundleQuery);
|
||||
|
||||
// 创建资源管理器
|
||||
// 初始化资源系统
|
||||
InitializationOperation initializeOperation;
|
||||
_resourceMgr = new ResourceManager(PackageName);
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
var editorSimulateModeImpl = new EditorSimulateModeImpl(PackageName);
|
||||
_bundleQuery = editorSimulateModeImpl;
|
||||
_playModeImpl = editorSimulateModeImpl;
|
||||
_resourceMgr.Initialize(true, parameters.AutoDestroyAssetProvider, _bundleQuery);
|
||||
|
||||
var initializeParameters = parameters as EditorSimulateModeParameters;
|
||||
initializeOperation = editorSimulateModeImpl.InitializeAsync(assist, initializeParameters.SimulateManifestFilePath);
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.EditorFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var offlinePlayModeImpl = new OfflinePlayModeImpl(PackageName);
|
||||
_bundleQuery = offlinePlayModeImpl;
|
||||
_playModeImpl = offlinePlayModeImpl;
|
||||
_resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, _bundleQuery);
|
||||
|
||||
var initializeParameters = parameters as OfflinePlayModeParameters;
|
||||
initializeOperation = offlinePlayModeImpl.InitializeAsync(assist);
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
var hostPlayModeImpl = new HostPlayModeImpl(PackageName);
|
||||
_bundleQuery = hostPlayModeImpl;
|
||||
_playModeImpl = hostPlayModeImpl;
|
||||
_resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, _bundleQuery);
|
||||
|
||||
var initializeParameters = parameters as HostPlayModeParameters;
|
||||
initializeOperation = hostPlayModeImpl.InitializeAsync(assist,
|
||||
initializeParameters.BuildinQueryServices,
|
||||
initializeParameters.DeliveryQueryServices,
|
||||
initializeParameters.RemoteServices);
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
var webPlayModeImpl = new WebPlayModeImpl(PackageName);
|
||||
_bundleQuery = webPlayModeImpl;
|
||||
_playModeImpl = webPlayModeImpl;
|
||||
_resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, _bundleQuery);
|
||||
|
||||
var initializeParameters = parameters as WebPlayModeParameters;
|
||||
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
|
||||
initializeParameters.BuildinQueryServices,
|
||||
initializeParameters.RemoteServices,
|
||||
initializeParameters.WechatQueryServices);
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.CustomPlayMode)
|
||||
{
|
||||
var initializeParameters = parameters as CustomPlayModeParameters;
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.FileSystemParameterList);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -194,6 +136,7 @@ namespace YooAsset
|
||||
|
||||
// 监听初始化结果
|
||||
_isInitialize = true;
|
||||
OperationSystem.StartOperation(PackageName, initializeOperation);
|
||||
initializeOperation.Completed += InitializeOperation_Completed;
|
||||
return initializeOperation;
|
||||
}
|
||||
@@ -219,27 +162,6 @@ namespace YooAsset
|
||||
throw new Exception($"Editor simulate mode only support unity editor.");
|
||||
#endif
|
||||
|
||||
if (parameters is EditorSimulateModeParameters)
|
||||
{
|
||||
var editorSimulateModeParameters = parameters as EditorSimulateModeParameters;
|
||||
if (string.IsNullOrEmpty(editorSimulateModeParameters.SimulateManifestFilePath))
|
||||
throw new Exception($"{nameof(editorSimulateModeParameters.SimulateManifestFilePath)} is null or empty.");
|
||||
}
|
||||
|
||||
if (parameters is HostPlayModeParameters)
|
||||
{
|
||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||
if (hostPlayModeParameters.RemoteServices == null)
|
||||
throw new Exception($"{nameof(IRemoteServices)} is null.");
|
||||
if (hostPlayModeParameters.BuildinQueryServices == null)
|
||||
throw new Exception($"{nameof(IBuildinQueryServices)} is null.");
|
||||
if (hostPlayModeParameters.DeliveryQueryServices != null)
|
||||
{
|
||||
if (hostPlayModeParameters.DeliveryLoadServices == null)
|
||||
throw new Exception($"{nameof(IDeliveryLoadServices)} is null.");
|
||||
}
|
||||
}
|
||||
|
||||
// 鉴定运行模式
|
||||
if (parameters is EditorSimulateModeParameters)
|
||||
_playMode = EPlayMode.EditorSimulateMode;
|
||||
@@ -249,6 +171,8 @@ namespace YooAsset
|
||||
_playMode = EPlayMode.HostPlayMode;
|
||||
else if (parameters is WebPlayModeParameters)
|
||||
_playMode = EPlayMode.WebPlayMode;
|
||||
else if (parameters is CustomPlayModeParameters)
|
||||
_playMode = EPlayMode.CustomPlayMode;
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -258,7 +182,7 @@ namespace YooAsset
|
||||
#if UNITY_WEBGL
|
||||
if (_playMode != EPlayMode.WebPlayMode)
|
||||
{
|
||||
throw new Exception($"{_playMode} can not support WebGL plateform ! Please use {nameof(EPlayMode.WebPlayMode)}");
|
||||
throw new Exception($"{_playMode} can not support WebGL plateform !");
|
||||
}
|
||||
#else
|
||||
if (_playMode == EPlayMode.WebPlayMode)
|
||||
@@ -272,51 +196,96 @@ namespace YooAsset
|
||||
{
|
||||
_initializeStatus = op.Status;
|
||||
_initializeError = op.Error;
|
||||
if (_initializeStatus != EOperationStatus.Succeed)
|
||||
YooLogger.Error(_initializeError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求最新的资源版本
|
||||
/// 异步销毁
|
||||
/// </summary>
|
||||
public DestroyOperation DestroyAsync()
|
||||
{
|
||||
var operation = new DestroyOperation(this);
|
||||
OperationSystem.StartOperation(null, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求最新的资源版本
|
||||
/// </summary>
|
||||
/// <param name="appendTimeTicks">在URL末尾添加时间戳</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
|
||||
public RequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
return _playModeImpl.UpdatePackageVersionAsync(appendTimeTicks, timeout);
|
||||
var operation = _playModeImpl.RequestPackageVersionAsync(appendTimeTicks, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// 更新并加载指定版本的资源清单
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">更新的包裹版本</param>
|
||||
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
|
||||
/// <param name="packageVersion">包裹版本</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
|
||||
// 注意:强烈建议在更新之前保持加载器为空!
|
||||
if (_resourceMgr.HasAnyLoader())
|
||||
if (_resourceManager.HasAnyLoader())
|
||||
{
|
||||
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !");
|
||||
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !");
|
||||
}
|
||||
|
||||
return _playModeImpl.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
|
||||
var operation = _playModeImpl.UpdatePackageManifestAsync(packageVersion, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹资源
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">下载的包裹版本</param>
|
||||
/// <param name="packageVersion">包裹版本</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
return _playModeImpl.PreDownloadContentAsync(packageVersion, timeout);
|
||||
var operation = _playModeImpl.PreDownloadContentAsync(packageVersion, timeout);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地包裹的版本信息
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
/// <param name="clearMode">清理方式</param>
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
/// <param name="clearMode">清理方式</param>
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
|
||||
#region 包裹信息
|
||||
/// <summary>
|
||||
/// 获取当前加载包裹的版本信息
|
||||
/// </summary>
|
||||
public string GetPackageVersion()
|
||||
{
|
||||
@@ -324,106 +293,79 @@ namespace YooAsset
|
||||
return _playModeImpl.ActiveManifest.PackageVersion;
|
||||
}
|
||||
|
||||
#region 资源卸载
|
||||
/// <summary>
|
||||
/// 资源回收(卸载引用计数为零的资源)
|
||||
/// 获取当前加载包裹的备注信息
|
||||
/// </summary>
|
||||
public void UnloadUnusedAssets()
|
||||
public string GetPackageNote()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
_resourceMgr.UnloadUnusedAssets();
|
||||
return _playModeImpl.ActiveManifest.PackageNote;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源回收(尝试卸载指定的资源)
|
||||
/// 获取当前加载包裹的详细信息
|
||||
/// </summary>
|
||||
public void TryUnloadUnusedAsset(string location)
|
||||
public PackageDetails GetPackageDetails()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
_resourceMgr.TryUnloadUnusedAsset(assetInfo);
|
||||
return _playModeImpl.ActiveManifest.GetPackageDetails();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源回收
|
||||
/// <summary>
|
||||
/// 资源回收(尝试卸载指定的资源)
|
||||
/// 强制回收所有资源
|
||||
/// </summary>
|
||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
||||
public UnloadAllAssetsOperation UnloadAllAssetsAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
_resourceMgr.TryUnloadUnusedAsset(assetInfo);
|
||||
var options = new UnloadAllAssetsOptions();
|
||||
return UnloadAllAssetsAsync(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制回收所有资源
|
||||
/// </summary>
|
||||
public void ForceUnloadAllAssets()
|
||||
/// <param name="options">卸载选项</param>
|
||||
public UnloadAllAssetsOperation UnloadAllAssetsAsync(UnloadAllAssetsOptions options)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
_resourceMgr.ForceUnloadAllAssets();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 沙盒相关
|
||||
/// <summary>
|
||||
/// 获取包裹的内置文件根路径
|
||||
/// </summary>
|
||||
public string GetPackageBuildinRootDirectory()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _persistentMgr.BuildinRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹的沙盒文件根路径
|
||||
/// </summary>
|
||||
public string GetPackageSandboxRootDirectory()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _persistentMgr.SandboxRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空包裹的沙盒目录
|
||||
/// </summary>
|
||||
public void ClearPackageSandbox()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
_persistentMgr.DeleteSandboxPackageFolder();
|
||||
_cacheMgr.ClearAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹未使用的缓存文件
|
||||
/// </summary>
|
||||
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new ClearUnusedCacheFilesOperation(this, _cacheMgr);
|
||||
var operation = new UnloadAllAssetsOperation(_resourceManager, options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹本地所有的缓存文件
|
||||
/// 回收不再使用的资源
|
||||
/// 说明:卸载引用计数为零的资源
|
||||
/// </summary>
|
||||
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync()
|
||||
/// <param name="loopCount">循环迭代次数</param>
|
||||
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(int loopCount = 10)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new ClearAllCacheFilesOperation(_cacheMgr);
|
||||
var operation = new UnloadUnusedAssetsOperation(_resourceManager, loopCount);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定版本的缓存信息
|
||||
/// 资源回收
|
||||
/// 说明:尝试卸载指定的资源
|
||||
/// </summary>
|
||||
public GetAllCacheFileInfosOperation GetAllCacheFileInfosAsync(string packageVersion)
|
||||
public void TryUnloadUnusedAsset(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
||||
}
|
||||
|
||||
var operation = new GetAllCacheFileInfosOperation(_persistentMgr, _cacheMgr, packageVersion);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
/// <summary>
|
||||
/// 资源回收
|
||||
/// 说明:尝试卸载指定的资源
|
||||
/// </summary>
|
||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -449,6 +391,15 @@ namespace YooAsset
|
||||
return IsNeedDownloadFromRemoteInternal(assetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的资源信息
|
||||
/// </summary>
|
||||
public AssetInfo[] GetAllAssetInfos()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _playModeImpl.ActiveManifest.GetAllAssetInfos();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息列表
|
||||
/// </summary>
|
||||
@@ -457,7 +408,7 @@ namespace YooAsset
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
string[] tags = new string[] { tag };
|
||||
return _playModeImpl.ActiveManifest.GetAssetsInfoByTags(tags);
|
||||
return _playModeImpl.ActiveManifest.GetAssetInfosByTags(tags);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -467,7 +418,7 @@ namespace YooAsset
|
||||
public AssetInfo[] GetAssetInfos(string[] tags)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _playModeImpl.ActiveManifest.GetAssetsInfoByTags(tags);
|
||||
return _playModeImpl.ActiveManifest.GetAssetInfosByTags(tags);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -532,13 +483,13 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo);
|
||||
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
if (bundleInfo.IsNeedDownloadFromRemote())
|
||||
return true;
|
||||
|
||||
BundleInfo[] depends = _bundleQuery.GetDependBundleInfos(assetInfo);
|
||||
foreach (var depend in depends)
|
||||
{
|
||||
if (depend.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
if (depend.IsNeedDownloadFromRemote())
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -594,8 +545,7 @@ namespace YooAsset
|
||||
|
||||
private RawFileHandle LoadRawFileInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckRawFileLoadMethod(nameof(LoadRawFileAsync));
|
||||
var handle = _resourceMgr.LoadRawFileAsync(assetInfo, priority);
|
||||
var handle = _resourceManager.LoadRawFileAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
return handle;
|
||||
@@ -608,11 +558,12 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, false, 0);
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -620,10 +571,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, false, 0);
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, physicsMode, false, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -631,13 +583,14 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 0)
|
||||
public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority);
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -645,19 +598,20 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
/// <param name="physicsMode">场景物理模式</param>
|
||||
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
|
||||
/// <param name="priority">加载的优先级</param>
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 0)
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority);
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, physicsMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, bool suspendLoad, uint priority)
|
||||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadMethod(nameof(LoadAssetAsync));
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
var handle = _resourceMgr.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||
var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode);
|
||||
var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
return handle;
|
||||
@@ -765,9 +719,8 @@ namespace YooAsset
|
||||
|
||||
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadMethod(nameof(LoadAssetAsync));
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
var handle = _resourceMgr.LoadAssetAsync(assetInfo, priority);
|
||||
var handle = _resourceManager.LoadAssetAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
return handle;
|
||||
@@ -875,9 +828,8 @@ namespace YooAsset
|
||||
|
||||
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadMethod(nameof(LoadSubAssetsAsync));
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
var handle = _resourceMgr.LoadSubAssetsAsync(assetInfo, priority);
|
||||
var handle = _resourceManager.LoadSubAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
return handle;
|
||||
@@ -985,9 +937,8 @@ namespace YooAsset
|
||||
|
||||
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadMethod(nameof(LoadAllAssetsAsync));
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
var handle = _resourceMgr.LoadAllAssetsAsync(assetInfo, priority);
|
||||
var handle = _resourceManager.LoadAllAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
return handle;
|
||||
@@ -1037,25 +988,31 @@ namespace YooAsset
|
||||
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="locations">资源的定位地址列表</param>
|
||||
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
||||
@@ -1064,34 +1021,48 @@ namespace YooAsset
|
||||
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
assetInfos.Add(assetInfo);
|
||||
}
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">资源信息</param>
|
||||
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="assetInfos">资源信息列表</param>
|
||||
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
|
||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||
{
|
||||
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -1148,17 +1119,6 @@ namespace YooAsset
|
||||
#endregion
|
||||
|
||||
#region 内部方法
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
/// </summary>
|
||||
internal bool IsIncludeBundleFile(string cacheGUID)
|
||||
{
|
||||
// NOTE : 编辑器模拟模式下始终返回TRUE
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
return true;
|
||||
return _playModeImpl.ActiveManifest.IsIncludeBundleFile(cacheGUID);
|
||||
}
|
||||
|
||||
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
|
||||
{
|
||||
return _playModeImpl.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
|
||||
@@ -1181,25 +1141,7 @@ namespace YooAsset
|
||||
if (checkActiveManifest)
|
||||
{
|
||||
if (_playModeImpl.ActiveManifest == null)
|
||||
throw new Exception("Not found active package manifest !");
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugCheckRawFileLoadMethod(string method)
|
||||
{
|
||||
if (_playModeImpl.ActiveManifest.BuildPipeline != EDefaultBuildPipeline.RawFileBuildPipeline.ToString())
|
||||
{
|
||||
throw new Exception($"Cannot load asset bundle file using {method} method !");
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugCheckAssetLoadMethod(string method)
|
||||
{
|
||||
if (_playModeImpl.ActiveManifest.BuildPipeline == EDefaultBuildPipeline.RawFileBuildPipeline.ToString())
|
||||
{
|
||||
throw new Exception($"Cannot load raw file using {method} method !");
|
||||
throw new Exception("Can not found active package manifest !");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1226,7 +1168,9 @@ namespace YooAsset
|
||||
{
|
||||
DebugPackageData data = new DebugPackageData();
|
||||
data.PackageName = PackageName;
|
||||
data.ProviderInfos = _resourceMgr.GetDebugReportInfos();
|
||||
data.ProviderInfos = _resourceManager.GetDebugProviderInfos();
|
||||
data.BundleInfos = _resourceManager.GetDebugBundleInfos();
|
||||
data.OperationInfos = OperationSystem.GetDebugOperationInfos(PackageName);
|
||||
return data;
|
||||
}
|
||||
#endregion
|
||||
|
Reference in New Issue
Block a user