mirror of https://github.com/tuyoogame/YooAsset
parent
b238759f61
commit
fb5e289de0
|
@ -382,7 +382,7 @@ namespace YooAsset
|
||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (appPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (appPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -203,7 +203,7 @@ namespace YooAsset
|
||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (_impl.AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (_impl.AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -42,13 +42,13 @@ namespace YooAsset
|
||||||
/// 资源包集合(提供BundleName获取PatchBundle)
|
/// 资源包集合(提供BundleName获取PatchBundle)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public readonly Dictionary<string, PatchBundle> Bundles = new Dictionary<string, PatchBundle>();
|
public readonly Dictionary<string, PatchBundle> BundleDic = new Dictionary<string, PatchBundle>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源映射集合(提供AssetPath获取PatchAsset)
|
/// 资源映射集合(提供AssetPath获取PatchAsset)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public readonly Dictionary<string, PatchAsset> Assets = new Dictionary<string, PatchAsset>();
|
public readonly Dictionary<string, PatchAsset> AssetDic = new Dictionary<string, PatchAsset>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源路径映射集合
|
/// 资源路径映射集合
|
||||||
|
@ -138,18 +138,18 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源包名称
|
/// 获取主资源包
|
||||||
/// 注意:传入的资源路径一定合法有效!
|
/// 注意:传入的资源路径一定合法有效!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetBundleName(string assetPath)
|
public PatchBundle GetMainPatchBundle(string assetPath)
|
||||||
{
|
{
|
||||||
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset))
|
||||||
{
|
{
|
||||||
int bundleID = patchAsset.BundleID;
|
int bundleID = patchAsset.BundleID;
|
||||||
if (bundleID >= 0 && bundleID < BundleList.Count)
|
if (bundleID >= 0 && bundleID < BundleList.Count)
|
||||||
{
|
{
|
||||||
var patchBundle = BundleList[bundleID];
|
var patchBundle = BundleList[bundleID];
|
||||||
return patchBundle.BundleName;
|
return patchBundle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -166,17 +166,17 @@ namespace YooAsset
|
||||||
/// 获取资源依赖列表
|
/// 获取资源依赖列表
|
||||||
/// 注意:传入的资源路径一定合法有效!
|
/// 注意:传入的资源路径一定合法有效!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] GetAllDependencies(string assetPath)
|
public PatchBundle[] GetAllDependencies(string assetPath)
|
||||||
{
|
{
|
||||||
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset))
|
||||||
{
|
{
|
||||||
List<string> result = new List<string>(patchAsset.DependIDs.Length);
|
List<PatchBundle> result = new List<PatchBundle>(patchAsset.DependIDs.Length);
|
||||||
foreach (var dependID in patchAsset.DependIDs)
|
foreach (var dependID in patchAsset.DependIDs)
|
||||||
{
|
{
|
||||||
if (dependID >= 0 && dependID < BundleList.Count)
|
if (dependID >= 0 && dependID < BundleList.Count)
|
||||||
{
|
{
|
||||||
var dependPatchBundle = BundleList[dependID];
|
var dependPatchBundle = BundleList[dependID];
|
||||||
result.Add(dependPatchBundle.BundleName);
|
result.Add(dependPatchBundle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -191,6 +191,22 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尝试获取补丁资源
|
||||||
|
/// </summary>
|
||||||
|
public bool TryGetPatchAsset(string assetPath, out PatchAsset result)
|
||||||
|
{
|
||||||
|
return AssetDic.TryGetValue(assetPath, out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尝试获取补丁资源包
|
||||||
|
/// </summary>
|
||||||
|
public bool TryGetPatchBundle(string bundleName, out PatchBundle result)
|
||||||
|
{
|
||||||
|
return BundleDic.TryGetValue(bundleName, out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 序列化
|
/// 序列化
|
||||||
|
@ -212,7 +228,7 @@ namespace YooAsset
|
||||||
foreach (var patchBundle in patchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
{
|
{
|
||||||
patchBundle.ParseFlagsValue();
|
patchBundle.ParseFlagsValue();
|
||||||
patchManifest.Bundles.Add(patchBundle.BundleName, patchBundle);
|
patchManifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssetList
|
// AssetList
|
||||||
|
@ -220,10 +236,10 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
// 注意:我们不允许原始路径存在重名
|
// 注意:我们不允许原始路径存在重名
|
||||||
string assetPath = patchAsset.AssetPath;
|
string assetPath = patchAsset.AssetPath;
|
||||||
if (patchManifest.Assets.ContainsKey(assetPath))
|
if (patchManifest.AssetDic.ContainsKey(assetPath))
|
||||||
throw new Exception($"AssetPath have existed : {assetPath}");
|
throw new Exception($"AssetPath have existed : {assetPath}");
|
||||||
else
|
else
|
||||||
patchManifest.Assets.Add(assetPath, patchAsset);
|
patchManifest.AssetDic.Add(assetPath, patchAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return patchManifest;
|
return patchManifest;
|
||||||
|
|
|
@ -43,17 +43,11 @@ namespace YooAsset
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
string bundleName = _simulatePatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
if (_simulatePatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
var patchBundle = _simulatePatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
{
|
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
|
||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Should never get here !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@ -64,7 +58,7 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (_simulatePatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (_simulatePatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
return patchAsset;
|
return patchAsset;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -136,7 +136,7 @@ namespace YooAsset
|
||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
|
@ -168,7 +168,7 @@ namespace YooAsset
|
||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
|
@ -215,23 +215,19 @@ namespace YooAsset
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
string mainBundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
if (LocalPatchManifest.Bundles.TryGetValue(mainBundleName, out PatchBundle mainBundle))
|
PatchBundle mainBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
{
|
|
||||||
if (checkList.Contains(mainBundle) == false)
|
if (checkList.Contains(mainBundle) == false)
|
||||||
checkList.Add(mainBundle);
|
checkList.Add(mainBundle);
|
||||||
}
|
|
||||||
|
|
||||||
string[] dependBundleNames = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
foreach (var dependBundleName in dependBundleNames)
|
PatchBundle[] dependBundles = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
{
|
foreach (var dependBundle in dependBundles)
|
||||||
if (LocalPatchManifest.Bundles.TryGetValue(dependBundleName, out PatchBundle dependBundle))
|
|
||||||
{
|
{
|
||||||
if (checkList.Contains(dependBundle) == false)
|
if (checkList.Contains(dependBundle) == false)
|
||||||
checkList.Add(dependBundle);
|
checkList.Add(dependBundle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
||||||
foreach (var patchBundle in checkList)
|
foreach (var patchBundle in checkList)
|
||||||
|
@ -242,7 +238,7 @@ namespace YooAsset
|
||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
|
@ -376,10 +372,11 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
private BundleInfo CreateBundleInfo(string bundleName)
|
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
||||||
{
|
|
||||||
if (LocalPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
|
||||||
{
|
{
|
||||||
|
if (patchBundle == null)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 查询沙盒资源
|
// 查询沙盒资源
|
||||||
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
||||||
{
|
{
|
||||||
|
@ -388,7 +385,7 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询APP资源
|
// 查询APP资源
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle appPatchBundle))
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
{
|
{
|
||||||
|
@ -400,29 +397,26 @@ namespace YooAsset
|
||||||
// 从服务端下载
|
// 从服务端下载
|
||||||
return ConvertToDownloadInfo(patchBundle);
|
return ConvertToDownloadInfo(patchBundle);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Should never get here !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
string bundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
return CreateBundleInfo(bundleName);
|
var patchBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
|
return CreateBundleInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||||
foreach (var bundleName in depends)
|
foreach (var patchBundle in depends)
|
||||||
{
|
{
|
||||||
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
|
BundleInfo bundleInfo = CreateBundleInfo(patchBundle);
|
||||||
result.Add(bundleInfo);
|
result.Add(bundleInfo);
|
||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
|
@ -433,7 +427,7 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (LocalPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (LocalPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
return patchAsset;
|
return patchAsset;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -38,36 +38,34 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
private BundleInfo CreateBundleInfo(string bundleName)
|
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
||||||
{
|
|
||||||
if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
|
||||||
{
|
{
|
||||||
|
if (patchBundle == null)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Should never get here !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
string bundleName = _appPatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
return CreateBundleInfo(bundleName);
|
var patchBundle = _appPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
|
return CreateBundleInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||||
foreach (var bundleName in depends)
|
foreach (var patchBundle in depends)
|
||||||
{
|
{
|
||||||
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
|
BundleInfo bundleInfo = CreateBundleInfo(patchBundle);
|
||||||
result.Add(bundleInfo);
|
result.Add(bundleInfo);
|
||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
|
@ -78,7 +76,7 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (_appPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (_appPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
return patchAsset;
|
return patchAsset;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue