Support addressable location

支持可寻址资源定位
This commit is contained in:
hevinci
2022-04-28 17:23:31 +08:00
parent 775c724840
commit 2cb006f3d9
40 changed files with 799 additions and 235 deletions

View File

@@ -12,6 +12,11 @@ namespace YooAsset
[Serializable]
internal class PatchManifest
{
/// <summary>
/// 启用可寻址资源定位
/// </summary>
public bool EnableAddressable;
/// <summary>
/// 资源版本号
/// </summary>
@@ -45,6 +50,12 @@ namespace YooAsset
[NonSerialized]
public readonly Dictionary<string, PatchAsset> Assets = new Dictionary<string, PatchAsset>();
/// <summary>
/// 可寻址地址映射集合
/// </summary>
[NonSerialized]
public readonly Dictionary<string, string> AddressDic = new Dictionary<string, string>();
/// <summary>
/// 获取内置资源标签列表
@@ -108,6 +119,22 @@ namespace YooAsset
}
}
/// <summary>
/// 可寻址地址转换为资源路径
/// </summary>
public string ConvertAddress(string address)
{
if (AddressDic.TryGetValue(address, out string assetPath))
{
return assetPath;
}
else
{
YooLogger.Warning($"Not found address in patch manifest : {address}");
return string.Empty;
}
}
/// <summary>
/// 序列化
@@ -155,6 +182,19 @@ namespace YooAsset
}
}
// Address
if (patchManifest.EnableAddressable)
{
foreach (var patchAsset in patchManifest.AssetList)
{
string address = patchAsset.Address;
if (patchManifest.AddressDic.ContainsKey(address))
throw new Exception($"Address have existed : {address}");
else
patchManifest.AddressDic.Add(address, patchAsset.AssetPath);
}
}
return patchManifest;
}
}