【发布时间】:2017-12-15 09:28:37
【问题描述】:
我正在尝试在 iOS 手机上下载、设置和保存纹理,但我一直遇到同样的错误:
(纹理需要被标记为读/写才能在播放器中获取RawTextureData UnityEngine.Texture2D:GetRawTextureData())
它仅在 iPhone 转换后发生,但在 macOS 上运行良好。感谢您的帮助:)
UnityWebRequest www = UnityWebRequest.GetTexture(url);
AsyncOperation op = www.Send();
while (op.isDone == false)
{
yield return new WaitForEndOfFrame();
}
if (www.isError)
{
Debug.Log(www.error);
}
else
{
texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
Texture2D texture2d = new Texture2D(texture.width, texture.height, TextureFormat.ARGB32, false);
texture2d.LoadRawTextureData(texture.GetRawTextureData());
texture2d.Apply();
byte[] bytes = texture2d.EncodeToJPG();
Debug.Log("after");
File.WriteAllBytes(Application.persistentDataPath + "/" + name + ".png", bytes);
texture = texture2d;
setTheTexture();
}
【问题讨论】: