private IEnumerator GetImage(string url, Image fileImage)
{
UnityWebRequest WebRequest = new UnityWebRequest(url);
DownloadHandlerTexture Download = new DownloadHandlerTexture();
WebRequest.downloadHandler = Download;
yield return WebRequest.SendWebRequest();
if (WebRequest.downloadHandler.isDone)
{
if (!fileImage)
{
if (Application.platform == RuntimePlatform.WindowsEditor ||
Application.platform == RuntimePlatform.WindowsPlayer)
File.WriteAllBytes(Application.streamingAssetsPath + "/HeadPicture.png", Download.data);
else if (Application.platform == RuntimePlatform.Android)
File.WriteAllBytes(Application.persistentDataPath + "/HeadPicture.png", Download.data);
SetHeadPictureComponent();
}
else
{
Rect spriteRect = new Rect(0, 0, Download.texture.width, Download.texture.height);
Sprite sprite = Sprite.Create(Download.texture, spriteRect, Vector2.zero);
fileImage.sprite = sprite;
}
}
}