我拿到了userinfo.avatarUrl,然后用的unity下载下来,对其赋值,就是无法显示。
Unity的代码:
IEnumerator LoadTextureFromInternet(string path)
{
Texture2D pic = new Texture2D(100, 100);
UnityWebRequest request = new UnityWebRequest(path);
//给request的downloadhandle赋值,new出来的UnityWebRequest不附加downloadhandle
//数据,不赋值的话访问不到下载出来的数据
DownloadHandlerTexture texture = new DownloadHandlerTexture(true);
request.downloadHandler = texture;
yield return request.SendWebRequest();
if (string.IsNullOrEmpty(request.error))
{
pic = texture.texture;
}
Sprite sp = Sprite.Create((Texture2D)pic, new Rect(0, 0, pic.width, pic.height), Vector2.zero);
touxiang.sprite = sp;
Debug.Log("图像设置完毕!");
}