我正在使用DownloadHandlerTexture.GetContent
来获取我的纹理:
www = UnityWebRequest.GetTexture("http://www.example.com/loadTex/?tag=" + tag);
www.SetRequestHeader("Accept", "image/*");
async = www.Send();
while (!async.isDone)
yield return null;
if (www.isError) {
Debug.Log(www.error);
} else {
yield return null;
tex = DownloadHandlerTexture.GetContent(www);
}
加载后,我想将其缓存到文件中,因此我执行以下操作:
byte[] pic = tex.EncodeToPNG();
File.WriteAllBytes(Application.persistentDataPath + "/art/" + tag + ".png", pic);
此时我会收到异常:
UnityException: Texture '' is not readable, the texture memory can not be accessed from
scripts. You can make the texture readable in the Texture Import Settings.
我认为我需要以某种方式使它易读。我搜索了一下,但我得到的唯一答案是如何通过编辑器使其易读。
DownloadHandlerTexture.GetContent
的原因是它针对内存进行了优化。 - sergeDownloadHandlerTexture.GetContent
效率低? - serge