mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-17 05:10:12 +00:00
优化了资源定位不正确导致的错误报告方式。 YooAssets.ProcessOperation()重命名为YooAssets.StartOperation() YooAssets.GetBundleInfo()已经移除方法。 YooAssets.IsNeedDownloadFromRemote()新增加方法。
108 lines
3.2 KiB
C#
108 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace YooAsset
|
|
{
|
|
internal class OfflinePlayModeImpl : IBundleServices
|
|
{
|
|
private PatchManifest _appPatchManifest;
|
|
private bool _locationToLower;
|
|
|
|
/// <summary>
|
|
/// 异步初始化
|
|
/// </summary>
|
|
public InitializationOperation InitializeAsync(bool locationToLower)
|
|
{
|
|
_locationToLower = locationToLower;
|
|
var operation = new OfflinePlayModeInitializationOperation(this);
|
|
OperationSystem.StartOperaiton(operation);
|
|
return operation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取资源版本号
|
|
/// </summary>
|
|
public int GetResourceVersion()
|
|
{
|
|
if (_appPatchManifest == null)
|
|
return 0;
|
|
return _appPatchManifest.ResourceVersion;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建解压器
|
|
/// </summary>
|
|
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
|
|
{
|
|
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByTags(_appPatchManifest, tags);
|
|
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
|
return operation;
|
|
}
|
|
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain)
|
|
{
|
|
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByAll(_appPatchManifest);
|
|
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
|
return operation;
|
|
}
|
|
|
|
// 设置资源清单
|
|
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
|
{
|
|
_appPatchManifest = patchManifest;
|
|
_appPatchManifest.InitAssetPathMapping(_locationToLower);
|
|
}
|
|
|
|
#region IBundleServices接口
|
|
private BundleInfo CreateBundleInfo(string bundleName)
|
|
{
|
|
if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
|
{
|
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
|
return bundleInfo;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("Should never get here !");
|
|
}
|
|
}
|
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
|
{
|
|
if (assetInfo.IsInvalid)
|
|
throw new Exception("Should never get here !");
|
|
|
|
string bundleName = _appPatchManifest.GetBundleName(assetInfo.AssetPath);
|
|
return CreateBundleInfo(bundleName);
|
|
}
|
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
|
{
|
|
if (assetInfo.IsInvalid)
|
|
throw new Exception("Should never get here !");
|
|
|
|
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
|
foreach (var bundleName in depends)
|
|
{
|
|
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
|
|
result.Add(bundleInfo);
|
|
}
|
|
return result.ToArray();
|
|
}
|
|
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
|
{
|
|
return PatchHelper.GetAssetsInfoByTags(_appPatchManifest, tags);
|
|
}
|
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
|
{
|
|
if (_appPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
|
return patchAsset;
|
|
else
|
|
return null;
|
|
}
|
|
string IBundleServices.MappingToAssetPath(string location)
|
|
{
|
|
return _appPatchManifest.MappingToAssetPath(location);
|
|
}
|
|
#endregion
|
|
}
|
|
} |