作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用可寻址 Assets 从服务器远程下载新场景,我想做的是如果可寻址场景已经下载并在缓存中,则激活一个播放按钮,如果没有,则激活一个下载按钮在缓存中,这样玩家就不会在每次想要播放场景时都从服务器下载可寻址。
我尝试使用缓存。 IsVersionCached
使用包名称检查包是否在缓存中,但这里的问题是名称不是一个好的引用,因为在可寻址系统中我使用 Addressable 加载场景。 loadscene
直接加载场景而不提供对 Assets 包的任何引用。所以问题是如何检查场景是否被缓存?这是我尝试过的,但它不起作用,因为我已经知道 Assets 包名称至少在这个例子中不会是很好的引用。
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;
}
}
最佳答案
据我所知Addressable assets是unity自动缓存的,不会被二次下载。但是您必须确保在统一编辑器中构建可寻址对象时,您选择“更新现有构建”(或类似的)而不是干净的构建。但如果您仍想手动检查,可以使用“Addressables.GetDownloadSizeAsync()”方法。 (请在统一文档中阅读更多相关信息)。
希望对您有所帮助。
关于c# - 统一下载后如何检查可寻址 Assets 或场景是否被缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55665355/
我是一名优秀的程序员,十分优秀!