【发布时间】:2017-02-05 01:05:42
【问题描述】:
我正在使用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.
我认为我需要以某种方式使其可读。我用谷歌搜索了它,但我得到的唯一答案是如何通过编辑器使其可读。
【问题讨论】: