加載我使用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