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
@@ -5,6 +5,11 @@ namespace YooAsset
[Serializable]
internal class PatchAsset
{
/// <summary>
/// 可寻址地址
/// </summary>
public string Address;
/// <summary>
/// 资源路径
/// </summary>
@@ -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;
}
}
@@ -31,6 +31,10 @@ namespace YooAsset
BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
}
string IBundleServices.ConvertAddress(string address)
{
throw new Exception($"Editor play mode not support addressable.");
}
string IBundleServices.GetBundleName(string assetPath)
{
return assetPath;
@@ -237,6 +237,10 @@ namespace YooAsset
return bundleInfo;
}
}
string IBundleServices.ConvertAddress(string address)
{
return LocalPatchManifest.ConvertAddress(address);
}
string IBundleServices.GetBundleName(string assetPath)
{
return LocalPatchManifest.GetBundleName(assetPath);
@@ -56,6 +56,10 @@ namespace YooAsset
return bundleInfo;
}
}
string IBundleServices.ConvertAddress(string address)
{
return AppPatchManifest.ConvertAddress(address);
}
string IBundleServices.GetBundleName(string assetPath)
{
return AppPatchManifest.GetBundleName(assetPath);