UnityWebRequest可以用来请求网络上的图片或者请求一张本地图片。
除了GetTexture之外,还有ab包的下载等。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class LoadSp : MonoBehaviour
{
public Image Image_Main;
private void Start()
{
StartCoroutine(DonwoladPic());
}
IEnumerator DonwoladPic()
{
string url = "http://api.map.baidu.com/images/weather/day/qing.png";
// string path= "E:/Screenshot/caidan.png";
using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(url))
{
yield return request.SendWebRequest();
Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
Image_Main.sprite = sprit