gpt4 book ai didi

c# - 统一下载后如何检查可寻址 Assets 或场景是否被缓存?

转载 作者:行者123 更新时间:2023-12-04 15:46:15 24 4
gpt4 key购买 nike

我正在使用可寻址 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com