我想知道AssetBundle已经在缓存中 . 这通常使用 Caching.IsVersionCached
函数完成 .
Unity 2017.1不再支持 Caching.IsVersionCached(string url, int version)
函数重载 .
Unity 2017.3建议我使用 Caching.IsVersionCached(string url, Hash128 hash)
重载 .
我不知道 Hash128
是什么以及如何获取和使用它 . 什么是 Hash128
用于如何从AssetBundle获取它?
谢谢您的回答 .
但我无法解决我的问题 .
这是我的代码
for(int i = 0; i <assetInfoList.Count; i){
while (!Caching.ready)
yield return null;
string url = GetUrl(assetInfoList[i].assetbundle_name);
string keyName = url + assetInfoList[i].version_no.ToString();
using (UnityWebRequest request = UnityWebRequest.GetAssetBundle(url,(uint)assetInfoList[i].version_no, 0))
{
if (Caching.IsVersionCached(url, assetInfoList[i].version_no) == true)
continue;
if (i == 0)
{
string wifiConnectRecommend = Message.Ins.WIFI_ONLY;
PopUpManager.Instance.PopUp_YesORNoForAssetBundle(wifiConnectRecommend.ToString(), ClickWifi, availableBytes, totalBytes);
while (!SceneManager.Ins.isWifiUseConfirm)
yield return null;
}
request.SendWebRequest();
while (request.isDone == false)
{
progressbar.value = request.downloadProgress;
currentCount.text = countString + " (" + (request.downloadProgress * 100).ToString("N2") + "%)";
yield return null;
}
if (request.error != null)
{
Debug.Log("www.error");
}
else
{
AssetBundleRef abRef = new AssetBundleRef(url, assetInfoList[i].version_no);
abRef.assetBundle = DownloadHandlerAssetBundle.GetContent(request);
dictAssetBundleRefs.Add(keyName, abRef);
}
}
我的目的是当assetbundle已经在缓存中,继续并需要下载,在PopUp_YesORNoForAssetBundle上设置 .
检查assetbundle下载或版本检查时需要hash128 .
但是在你的解释中,hash128只能在上次加载资源包或在资源文件夹中保存manifestfile之后才能获得 .
我想知道如何检查assetbunle是否在缓存中 .
如果你建议的话,我真的很感谢你 .
1 回答
Hash128表示AssetBundle文件的哈希值,可以在下载时更轻松地比较AssetBundle文件版本 .
没有关于如何从文档中执行此操作的示例 . 以下是 three 获取Hash128的方法 . 使用哪一个取决于
AssetBundle
所在的条件以及是否要下载它以检查Hash128 . 在您的情况下, #1 很可能是您正在寻找的 .1 . Obtain Hash128 during AssetBundle build from the Editor then save to the Resources folder :
使用BuildPipeline.BuildAssetBundles函数构建AssetBundle时,此函数返回AssetBundleManifest . 您可以使用AssetBundleManifest.GetAssetBundleHash函数获取Hash128 . 将Hash128转换为带有Hash128.ToString()的字符串,然后将其保存到Resources文件夹,以便在运行时访问它 .
将构建AssetBundle并将
Hash128
保存到Resources文件夹的 Editor 构建脚本示例:在运行时加载
Hash128
的简单函数:如何使用:
你也可以根据需要使用json来表示和保存许多
Hash128
.2 . Download the AssetBundle from server then obtain Hash128 during run-time without the Resources folder . 不幸的是,您必须首先使用此方法下载AssetBundle,然后才能获得
Hash128
. 下载后,将数据加载为AssetBundleManifest
,然后使用AssetBundleManifest.GetAssetBundleHash
函数从中获取Hash128
. 然后,您可以保存此Hash128
供以后使用 .下面的示例应从AssetBundle URL下载并解压缩
Hash128
. 没有涉及编辑器代码 .3 . Obtain Hash128 from an AssetBundle in the file system. 如果您已经是knew AssetBundle的路径,请从该路径加载AssetBundle,然后将数据加载为
AssetBundleManifest
,最后使用AssetBundleManifest.GetAssetBundleHash
函数从中获取Hash128
. 然后,您可以保存此Hash128
供以后使用 .这显示了如何从StreamingAsset路径加载AssetBundle并获取其
Hash128
: