mirror of https://github.com/tuyoogame/YooAsset
Compare commits
4 Commits
191fbff768
...
cb2cb4e556
Author | SHA1 | Date |
---|---|---|
|
cb2cb4e556 | |
|
ab32bd390d | |
|
b34374adfa | |
|
b53b6a4246 |
|
@ -15,7 +15,8 @@ namespace YooAsset
|
|||
CheckDownload,
|
||||
Unpack,
|
||||
CheckUnpack,
|
||||
LoadFile,
|
||||
LoadBundleFile,
|
||||
LoadDeliveryFile,
|
||||
CheckLoadFile,
|
||||
Done,
|
||||
}
|
||||
|
@ -59,22 +60,22 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
}
|
||||
#else
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
#endif
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadDeliveryFile;
|
||||
FileLoadPath = MainBundleInfo.DeliveryFilePath;
|
||||
}
|
||||
else
|
||||
|
@ -108,7 +109,7 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
return; //下载完毕等待一帧再去加载!
|
||||
}
|
||||
}
|
||||
|
@ -139,12 +140,12 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 加载AssetBundle
|
||||
if (_steps == ESteps.LoadFile)
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
|
||||
|
@ -219,7 +220,35 @@ namespace YooAsset
|
|||
_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 (_createRequest != null)
|
||||
|
|
|
@ -30,7 +30,12 @@ namespace YooAsset
|
|||
/// 开发者分发的文件地址
|
||||
/// </summary>
|
||||
public string DeliveryFilePath { private set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 开发者分发的文件偏移量
|
||||
/// </summary>
|
||||
public ulong DeliveryFileOffset { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 注意:该字段只用于帮助编辑器下的模拟模式。
|
||||
/// </summary>
|
||||
|
@ -47,14 +52,16 @@ namespace YooAsset
|
|||
RemoteMainURL = mainURL;
|
||||
RemoteFallbackURL = fallbackURL;
|
||||
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;
|
||||
LoadMode = loadMode;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
DeliveryFilePath = deliveryFilePath;
|
||||
DeliveryFileOffset = deliveryFileOffset;
|
||||
}
|
||||
public BundleInfo(PackageBundle bundle, ELoadMode loadMode)
|
||||
{
|
||||
|
@ -63,6 +70,7 @@ namespace YooAsset
|
|||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
DeliveryFilePath = string.Empty;
|
||||
DeliveryFileOffset = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -60,13 +60,13 @@ namespace YooAsset
|
|||
{
|
||||
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);
|
||||
if (string.IsNullOrEmpty(deliveryFilePath))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
return _queryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName);
|
||||
}
|
||||
private DeliveryFileInfo GetDeiveryFileInfo(PackageBundle packageBundle)
|
||||
{
|
||||
return _queryServices.GetDeliveryFileInfo(_packageName, packageBundle.FileName);
|
||||
}
|
||||
|
||||
#region IPlayModeServices接口
|
||||
|
@ -119,6 +119,10 @@ namespace YooAsset
|
|||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
@ -144,6 +148,10 @@ namespace YooAsset
|
|||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
@ -205,6 +213,10 @@ namespace YooAsset
|
|||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in checkList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
@ -279,9 +291,10 @@ namespace YooAsset
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -571,6 +571,18 @@ namespace YooAsset
|
|||
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>
|
||||
/// 异步加载资源对象
|
||||
|
@ -606,6 +618,18 @@ namespace YooAsset
|
|||
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)
|
||||
{
|
||||
|
@ -660,6 +684,18 @@ namespace YooAsset
|
|||
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>
|
||||
/// 异步加载子资源对象
|
||||
|
@ -695,6 +731,18 @@ namespace YooAsset
|
|||
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)
|
||||
{
|
||||
|
@ -749,6 +797,18 @@ namespace YooAsset
|
|||
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>
|
||||
/// 异步加载资源包内所有资源对象
|
||||
|
@ -784,6 +844,18 @@ namespace YooAsset
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 分发的资源信息
|
||||
/// </summary>
|
||||
public struct DeliveryFileInfo
|
||||
{
|
||||
public string DeliveryFilePath;
|
||||
public ulong DeliveryFileOffset;
|
||||
}
|
||||
|
||||
public interface IQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -9,8 +18,13 @@ namespace YooAsset
|
|||
bool QueryStreamingAssets(string packageName, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 查询开发者分发的文件加载路径
|
||||
/// 查询是否为开发者分发的资源
|
||||
/// </summary>
|
||||
string QueryDeliveryFiles(string packageName, string fileName);
|
||||
bool QueryDeliveryFiles(string packageName, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取开发者分发的资源信息
|
||||
/// </summary>
|
||||
DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName);
|
||||
}
|
||||
}
|
|
@ -8,9 +8,14 @@ using YooAsset;
|
|||
/// </summary>
|
||||
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)
|
||||
|
|
|
@ -11,9 +11,14 @@ using YooAsset;
|
|||
/// </summary>
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue