我正在使用可寻址资源从服务器远程下载新场景,我要做的是,如果可寻址场景已经下载并在缓存中,则激活播放按钮;如果可寻址场景不在缓存中,则激活下载按钮,这样播放器就不会在每次想要播放场景时从服务器下载可寻址场景。
我试过使用缓存。使用包名称来检查包在缓存中的IsVersionCached,但这里的问题是这个名称不是一个好的引用,因为在可寻址系统中,我使用Addressable加载场景。loadscene,直接加载场景,而不提供对资源束的任何引用。所以问题是如何检查场景是否被缓存了?下面是我尝试过的方法,但它不起作用,因为我已经知道资产包名称不是很好的引用,至少在本例中是这样。
private IEnumerator LoadRoutine()
{
var lastHash = PlayerPrefs.GetString(LAST_HASH);
if (Caching.IsVersionCached(AssetBundleHavingTheScene.name, Hash128.Parse(lastHash)))
{
Debug.Log("The Bundle is Cached i'll launch it");
Addressables.LoadScene(AddressableScene);
}
else
{
Debug.Log("Not Cached I'm going to download it");
var async = Addressables.LoadScene(AddressableScene);
while (!async.IsDone)
{
ProgressNumber.text = (async.PercentComplete * 100f).ToString("F0") + ("%");
ProgressSlider.value = async.PercentComplete;
Debug.Log(async.PercentComplete);
yield return null;
}
// At this point the scene is loaded and referenced in async.Result
Debug.Log("LOADED!");
Scene myScene = async.Result;
}
}发布于 2020-02-15 07:11:14
据我所知,可寻址资产由unity自动缓存,不会被下载两次。但您必须确保当您在unity编辑器中构建可寻址时,您选择了“更新现有构建”(或类似的),而不是干净的构建。但是如果你仍然想手动检查,你可以使用"Addressables.GetDownloadSizeAsync()“方法。(请在unity文档中阅读更多信息)。
我希望这对你有一点帮助。
https://stackoverflow.com/questions/55665355
复制相似问题