{ maskTexture = txt; })); IEnumerator UnityWebRequestGetData(string _url, Action 赞 踩 加载到Texture2D上 StartCoroutine(UnityWebRequestGetData(("/StreamingAssets/MaskTexture/" + strName + ".png"),(txt)=> { maskTexture = txt; })); IEnumerator UnityWebRequestGetData(string _url, Action<Texture2D> OnTextureLoad) 加载到image上 IEnumerator UnityWebRequestGetData(Image _imageComp, string _url) Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。
UnityWebRequest加载本地图片_unity unitywebrequest从硬盘中加载图片
{
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(Application.dataPath + _url))
{
yield return uwr.SendWebRequest();
if (uwr.isHttpError || uwr.isNetworkError) Debug.Log(uwr.error);
else if (uwr.isDone) OnTextureLoad?.Invoke(DownloadHandlerTexture.GetContent(uwr));
}
}
{
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(_url))
{
yield return uwr.SendWebRequest();
if (uwr.isHttpError || uwr.isNetworkError) Debug.Log(uwr.error);
else
{
if (uwr.isDone)
{
int width = 1920;
int height = 1080;
Texture2D texture2d = new Texture2D(width, height);
texture2d = DownloadHandlerTexture.GetContent(uwr);
Sprite tempSprite = Sprite.Create(texture2d, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f));
_imageComp.sprite = tempSprite;
Resources.UnloadUnusedAssets();
}
}
}
}