hoj*_*ane 3 android caching unity-game-engine
我想统一为Android平台缓存图像。我使用WWW下载图像,但是每次都会重新下载它们。我在统一文档和网络中进行搜索,发现没有任何用处。任何帮助将不胜感激。
您可以做两件事之一
资产捆绑包是一项内置功能,非常易于集成和使用。此外,一旦通过AssetBundle下载了任何资产,它也会自动缓存(默认情况下),下次,您无需重新下载。
这种方法比较复杂,但是如果由于某种原因您无权访问Asset Bundles(在4.x中是Pro专用功能),则这是唯一的方法。
方法2的部分示例
public class TestMyDownload : Monobehaviour {
public string url = "http://www.foo.com/bar.png";
IEnumerator Start () {
WWW www = new WWW(url);
yield return www;
if(www.bytes != null) {
System.IO.File.WriteAllBytes(Application.persistentDataPath + "/myfile.png");
Debug.Log("Writing Success");
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:仅供参考,方法二可以处理所有类型的数据,而不仅仅是图像。如果100%确定只需要图像,则还可以访问WWW.image