【发布时间】:2019-12-20 22:02:56
【问题描述】:
我是 AssetBundle 的新手,并尝试了解这一点。目前,我可以从服务器加载资产,但无法从资产文件本身获取哈希。它保持返回 NullException。
我已尝试按照此处的文档进行操作: https://docs.unity3d.com/ScriptReference/Caching.html
但还是不知道,在Hash上也得到NullException。
也找到了这个,但没有运气: How to get AssetBundleManifest from AssetBundle in Unity3D
然后我尝试按照这篇文章中的说明进行操作: Get Hash128 from AssetBundle for the Caching.IsVersionCached function
但仍然得到 NullException()
这是我按照最新链接的代码:
IEnumerator DownloadAssetBundle()
{
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle("https://www.dropbox.com/s/66psd4aphlgpo2j/testasset?dl=1");
yield return www.SendWebRequest();
if(www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
AssetBundleRequest asset = bundle.LoadAssetAsync<AssetBundleManifest>("assetManifestName");
yield return asset;
//Get the AssetBundleManifest
AssetBundleManifest loadedAssetMf = asset.asset as AssetBundleManifest;
//Get Hash128 from the AssetBundleManifest
Hash128 tempHash128 = loadedAssetMf.GetAssetBundleHash("");
//Pass to the IsVersionCached function
Caching.IsVersionCached("https://www.dropbox.com/s/66psd4aphlgpo2j/testasset?dl=1", tempHash128);
//Instantiate(bundle.LoadAsset("RayBan_Sunglasses"));
}
}
谁能解释如何从assetBundle 获取哈希我做错了什么?
我的 Asset Bundle 的文件名为"testasset"
如果您愿意,请指定将"testasset" 放在哪里,这将是一种乐趣。非常感谢您的每一个回答。
【问题讨论】:
标签: c# unity3d caching hash assetbundle