我尝试下载,设置并保存iOS手机上的纹理,但我一直有同样的错误:
(纹理需要标记为读/写才能在播放器中使用GetRawTextureData 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();
}