unity版本2019.4.9。问题:项目中用Unity的WWW下载PNG图片,赋值给RawImage后,出现图片模糊、发虚问题(编辑器模式下无问题,打包后出现问题)。
问题的下载PNG图代码:
private IEnumerator onDownLoadTexture(string path, RawImage raw)
{
WWW www = new WWW(path);
yield return www;
if (www.isDone)
{
Texture2D texture = www.texture;
texture.filterMode = FilterMode.Trilinear;
texture.Apply();
raw.texture = texture;
}
}
修改后的代码:
private IEnumerator onDownLoadTexture(string path, RawImage raw)
{
UnityWebRequest wr = new UnityWebRequest(path);
DownloadHandlerTexture texDl = new DownloadHandlerTexture(true);
wr.downloadHandler = texDl;
yield return wr.SendWebRequest();
if (!(wr.isNetworkError || wr.isHttpError))
{
Texture2D t = texDl.texture;
t.filterMode = FilterMode.Trilinear;
t.Apply();
raw.texture = t;
}
}
发虚问题解决!