Question by
warlordsw · Jul 24, 2020 at 04:10 AM ·
assetbundlecache
Asset Bundle - How to load from cache after download it from webrequest ?
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class DownloadBundle : MonoBehaviour
{
public string url;
static AssetBundle assetBundle;
public Text Info;
CachedAssetBundle CanerStoryCache;
public IEnumerator LoadBundle()
{
CanerStoryCache.name = "cstry";
if (!Caching.IsVersionCached(CanerStoryCache))
{
Info.text = "Downloading";
var uwr = UnityWebRequestAssetBundle.GetAssetBundle(url, CanerStoryCache, 0);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
}
else
{
assetBundle = DownloadHandlerAssetBundle.GetContent(uwr);
Debug.Log("Download Completed");
SceneManager.LoadScene("SeasonScene");
}
}
else
{
//i dont know how to load from cache
SceneManager.LoadScene("SeasonScene");
}
}
public void CanerStoryClick()
{
StartCoroutine(LoadBundle());
}
}
I'm sorry in advance for my english.
On button click, execute the canerstoryclick method. When i play it , it is downloading from web url and entegrate assetbundle (SeasonScene) to the game then when i return the same menu and click again , it isnt downloading the file and enter the SeasonScene because i think it is reading from cache but when i close the game and open again, when i click the button i have an error ,it cant load Assetbundle and i cant enter the SeasonScene. Above is the code i used. Also i shared the screenshot my cache path after download the assetbundle from url. I'm making a game for Android and i need help about load from cache for assetbundle. Thank you all in advance !
forrum.png
(7.1 kB)
Comment