using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class OfflinePlayModeImpl : IBundleServices
{
private PatchManifest _appPatchManifest;
private bool _locationToLower;
///
/// 异步初始化
///
public InitializationOperation InitializeAsync(bool locationToLower)
{
_locationToLower = locationToLower;
var operation = new OfflinePlayModeInitializationOperation(this);
OperationSystem.StartOperaiton(operation);
return operation;
}
///
/// 获取资源版本号
///
public int GetResourceVersion()
{
if (_appPatchManifest == null)
return 0;
return _appPatchManifest.ResourceVersion;
}
///
/// 创建解压器
///
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
{
List unpcakList = PatchHelper.GetUnpackListByTags(_appPatchManifest, tags);
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation;
}
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain)
{
List 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 result = new List(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
}
}