Compare commits

..

4 Commits

Author SHA1 Message Date
hevinci cb2cb4e556 update package system 2023-07-20 11:27:56 +08:00
hevinci ab32bd390d update space shooter 2023-07-20 11:08:52 +08:00
hevinci b34374adfa update runtime code 2023-07-20 11:08:38 +08:00
hevinci b53b6a4246 update runtime code 2023-07-20 11:08:28 +08:00
9 changed files with 171 additions and 25 deletions

View File

@ -15,7 +15,8 @@ namespace YooAsset
CheckDownload, CheckDownload,
Unpack, Unpack,
CheckUnpack, CheckUnpack,
LoadFile, LoadBundleFile,
LoadDeliveryFile,
CheckLoadFile, CheckLoadFile,
Done, Done,
} }
@ -59,22 +60,22 @@ namespace YooAsset
} }
else else
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadBundleFile;
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath; FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
} }
#else #else
_steps = ESteps.LoadFile; _steps = ESteps.LoadBundleFile;
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath; FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
#endif #endif
} }
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache) else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadBundleFile;
FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath; FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath;
} }
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery) else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadDeliveryFile;
FileLoadPath = MainBundleInfo.DeliveryFilePath; FileLoadPath = MainBundleInfo.DeliveryFilePath;
} }
else else
@ -108,7 +109,7 @@ namespace YooAsset
} }
else else
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadBundleFile;
return; //下载完毕等待一帧再去加载! return; //下载完毕等待一帧再去加载!
} }
} }
@ -139,12 +140,12 @@ namespace YooAsset
} }
else else
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadBundleFile;
} }
} }
// 5. 加载AssetBundle // 5. 加载AssetBundle
if (_steps == ESteps.LoadFile) if (_steps == ESteps.LoadBundleFile)
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
// 注意Unity2017.4编辑器模式下如果AssetBundle文件不存在会导致编辑器崩溃这里做了预判。 // 注意Unity2017.4编辑器模式下如果AssetBundle文件不存在会导致编辑器崩溃这里做了预判。
@ -219,7 +220,35 @@ namespace YooAsset
_steps = ESteps.CheckLoadFile; _steps = ESteps.CheckLoadFile;
} }
// 6. 检测AssetBundle加载结果 // 6. 加载AssetBundle
if (_steps == ESteps.LoadDeliveryFile)
{
// 设置下载进度
DownloadProgress = 1f;
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
// Load assetBundle file
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
if (loadMethod == EBundleLoadMethod.Normal)
{
ulong offset = MainBundleInfo.DeliveryFileOffset;
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(FileLoadPath, 0, offset);
else
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath, 0, offset);
}
else
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = $"Delivery file not support encryption : {MainBundleInfo.Bundle.BundleName}";
YooLogger.Error(LastError);
return;
}
_steps = ESteps.CheckLoadFile;
}
// 7. 检测AssetBundle加载结果
if (_steps == ESteps.CheckLoadFile) if (_steps == ESteps.CheckLoadFile)
{ {
if (_createRequest != null) if (_createRequest != null)

View File

@ -31,6 +31,11 @@ namespace YooAsset
/// </summary> /// </summary>
public string DeliveryFilePath { private set; get; } public string DeliveryFilePath { private set; get; }
/// <summary>
/// 开发者分发的文件偏移量
/// </summary>
public ulong DeliveryFileOffset { private set; get; }
/// <summary> /// <summary>
/// 注意:该字段只用于帮助编辑器下的模拟模式。 /// 注意:该字段只用于帮助编辑器下的模拟模式。
/// </summary> /// </summary>
@ -47,14 +52,16 @@ namespace YooAsset
RemoteMainURL = mainURL; RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL; RemoteFallbackURL = fallbackURL;
DeliveryFilePath = string.Empty; DeliveryFilePath = string.Empty;
DeliveryFileOffset = 0;
} }
public BundleInfo(PackageBundle bundle, ELoadMode loadMode, string deliveryFilePath) public BundleInfo(PackageBundle bundle, ELoadMode loadMode, string deliveryFilePath, ulong deliveryFileOffset)
{ {
Bundle = bundle; Bundle = bundle;
LoadMode = loadMode; LoadMode = loadMode;
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
DeliveryFilePath = deliveryFilePath; DeliveryFilePath = deliveryFilePath;
DeliveryFileOffset = deliveryFileOffset;
} }
public BundleInfo(PackageBundle bundle, ELoadMode loadMode) public BundleInfo(PackageBundle bundle, ELoadMode loadMode)
{ {
@ -63,6 +70,7 @@ namespace YooAsset
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
DeliveryFilePath = string.Empty; DeliveryFilePath = string.Empty;
DeliveryFileOffset = 0;
} }
/// <summary> /// <summary>

View File

@ -60,13 +60,13 @@ namespace YooAsset
{ {
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID); return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
} }
private bool IsDeliveryPackageBundle(PackageBundle packageBundle, out string deliveryFilePath) private bool IsDeliveryPackageBundle(PackageBundle packageBundle)
{ {
deliveryFilePath = _queryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName); return _queryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName);
if (string.IsNullOrEmpty(deliveryFilePath)) }
return false; private DeliveryFileInfo GetDeiveryFileInfo(PackageBundle packageBundle)
else {
return true; return _queryServices.GetDeliveryFileInfo(_packageName, packageBundle.FileName);
} }
#region IPlayModeServices接口 #region IPlayModeServices接口
@ -119,6 +119,10 @@ namespace YooAsset
List<PackageBundle> downloadList = new List<PackageBundle>(1000); List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
// 忽略分发文件
if (IsDeliveryPackageBundle(packageBundle))
continue;
// 忽略缓存文件 // 忽略缓存文件
if (IsCachedPackageBundle(packageBundle)) if (IsCachedPackageBundle(packageBundle))
continue; continue;
@ -144,6 +148,10 @@ namespace YooAsset
List<PackageBundle> downloadList = new List<PackageBundle>(1000); List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
// 忽略分发文件
if (IsDeliveryPackageBundle(packageBundle))
continue;
// 忽略缓存文件 // 忽略缓存文件
if (IsCachedPackageBundle(packageBundle)) if (IsCachedPackageBundle(packageBundle))
continue; continue;
@ -205,6 +213,10 @@ namespace YooAsset
List<PackageBundle> downloadList = new List<PackageBundle>(1000); List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in checkList) foreach (var packageBundle in checkList)
{ {
// 忽略分发文件
if (IsDeliveryPackageBundle(packageBundle))
continue;
// 忽略缓存文件 // 忽略缓存文件
if (IsCachedPackageBundle(packageBundle)) if (IsCachedPackageBundle(packageBundle))
continue; continue;
@ -279,9 +291,10 @@ namespace YooAsset
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
// 查询分发资源 // 查询分发资源
if (IsDeliveryPackageBundle(packageBundle, out string deliveryFilePath)) if (IsDeliveryPackageBundle(packageBundle))
{ {
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromDelivery, deliveryFilePath); DeliveryFileInfo deliveryFileInfo = GetDeiveryFileInfo(packageBundle);
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromDelivery, deliveryFileInfo.DeliveryFilePath, deliveryFileInfo.DeliveryFileOffset);
return bundleInfo; return bundleInfo;
} }

View File

@ -571,6 +571,18 @@ namespace YooAsset
return LoadAssetInternal(assetInfo, true); return LoadAssetInternal(assetInfo, true);
} }
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AssetOperationHandle LoadAssetSync(string location)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, true);
}
/// <summary> /// <summary>
/// 异步加载资源对象 /// 异步加载资源对象
@ -606,6 +618,18 @@ namespace YooAsset
return LoadAssetInternal(assetInfo, false); return LoadAssetInternal(assetInfo, false);
} }
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AssetOperationHandle LoadAssetAsync(string location)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, false);
}
private AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete) private AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{ {
@ -660,6 +684,18 @@ namespace YooAsset
return LoadSubAssetsInternal(assetInfo, true); return LoadSubAssetsInternal(assetInfo, true);
} }
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public SubAssetsOperationHandle LoadSubAssetsSync(string location)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, true);
}
/// <summary> /// <summary>
/// 异步加载子资源对象 /// 异步加载子资源对象
@ -695,6 +731,18 @@ namespace YooAsset
return LoadSubAssetsInternal(assetInfo, false); return LoadSubAssetsInternal(assetInfo, false);
} }
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public SubAssetsOperationHandle LoadSubAssetsAsync(string location)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, false);
}
private SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete) private SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{ {
@ -749,6 +797,18 @@ namespace YooAsset
return LoadAllAssetsInternal(assetInfo, true); return LoadAllAssetsInternal(assetInfo, true);
} }
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AllAssetsOperationHandle LoadAllAssetsSync(string location)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, true);
}
/// <summary> /// <summary>
/// 异步加载资源包内所有资源对象 /// 异步加载资源包内所有资源对象
@ -784,6 +844,18 @@ namespace YooAsset
return LoadAllAssetsInternal(assetInfo, false); return LoadAllAssetsInternal(assetInfo, false);
} }
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AllAssetsOperationHandle LoadAllAssetsAsync(string location)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, false);
}
private AllAssetsOperationHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete) private AllAssetsOperationHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{ {

View File

@ -1,6 +1,15 @@
 
namespace YooAsset namespace YooAsset
{ {
/// <summary>
/// 分发的资源信息
/// </summary>
public struct DeliveryFileInfo
{
public string DeliveryFilePath;
public ulong DeliveryFileOffset;
}
public interface IQueryServices public interface IQueryServices
{ {
/// <summary> /// <summary>
@ -9,8 +18,13 @@ namespace YooAsset
bool QueryStreamingAssets(string packageName, string fileName); bool QueryStreamingAssets(string packageName, string fileName);
/// <summary> /// <summary>
/// 查询开发者分发的文件加载路径 /// 查询是否为开发者分发的资源
/// </summary> /// </summary>
string QueryDeliveryFiles(string packageName, string fileName); bool QueryDeliveryFiles(string packageName, string fileName);
/// <summary>
/// 获取开发者分发的资源信息
/// </summary>
DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName);
} }
} }

View File

@ -8,9 +8,14 @@ using YooAsset;
/// </summary> /// </summary>
public class GameQueryServices : IQueryServices public class GameQueryServices : IQueryServices
{ {
public string QueryDeliveryFiles(string packageName, string fileName) public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
{ {
return null; throw new System.NotImplementedException();
}
public bool QueryDeliveryFiles(string packageName, string fileName)
{
return false;
} }
public bool QueryStreamingAssets(string packageName, string fileName) public bool QueryStreamingAssets(string packageName, string fileName)

View File

@ -11,9 +11,14 @@ using YooAsset;
/// </summary> /// </summary>
public class GameQueryServices2 : IQueryServices public class GameQueryServices2 : IQueryServices
{ {
public string QueryDeliveryFiles(string packageName, string fileName) public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
{ {
return null; throw new System.NotImplementedException();
}
public bool QueryDeliveryFiles(string packageName, string fileName)
{
return false;
} }
public bool QueryStreamingAssets(string packageName, string fileName) public bool QueryStreamingAssets(string packageName, string fileName)