加载我使用DownloadHandlerTexture.GetContent
让我的纹理时一个Texture2D可读的统一:制作从服务器
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.
我在想,我需要它在某种程度上可读。我搜索了它,但我得到的唯一答案是如何通过编辑器使其可读。
我m加载纹理以在我的模型中使用它。但是当程序结束时,我试图将它缓存到文件中。我使用'DownloadHandlerTexture.GetContent'的原因是因为它针对内存进行了优化。 – serge
而不是缓存在最后,缓存当你得到它。这是完全一样的。 – Everts
听起来很合理,我会在我回家时尝试,并尽快报告。从字节加载纹理而不是使用'DownloadHandlerTexture.GetContent' – serge