当前位置:网站首页>UnityWebRequest基础使用之下载文本、图片、AB包
UnityWebRequest基础使用之下载文本、图片、AB包
2022-07-07 07:31:00 【心前阳光】
准备
UnityWebRequest
downloadHandler是一个下载助手,下载的资源可以通过它直接获取
UnityWebRequest继承IDisposable接口
注意:访问的服务器要有下载权限 才能下载
下载文本
IEnumerator LoadText(string url)
{
using (UnityWebRequest req = UnityWebRequest.Get(url))
{
yield return req.SendWebRequest();//发出get请求
if (req.error == null)
{
Debug.Log(req.downloadHandler.text);
Debug.Log(req.downloadHandler.data.Length);
}
else
{
Debug.Log("下载出错" + req.responseCode + "," + req.error);
}
}
}
下载图片
IEnumerator LoadTexture(string url)
{
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(url))
{
yield return req.SendWebRequest();
if (req.error == null)
{
Debug.Log((req.downloadHandler as DownloadHandlerTexture).texture.width);
Debug.Log(DownloadHandlerTexture.GetContent(req).height);
}
else
{
Debug.Log("下载出错" + req.responseCode + "," + req.error);
}
}
}
下载AB包
IEnumerator LoadAB(string url)
{
using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(url))
{
yield return req.SendWebRequest();
if (req.error == null)
{
Debug.Log((req.downloadHandler as DownloadHandlerAssetBundle).assetBundle.name);
Debug.Log(DownloadHandlerAssetBundle.GetContent(req).name);
}
else
{
Debug.Log("下载出错" + req.responseCode + "," + req.error);
}
}
}
边栏推荐
- C socke server, client, UDP
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
- Interface test
- Apprentissage avancé des fonctions en es6
- 【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
- STM32产品介绍
- Introduction to energy Router: Architecture and functions for energy Internet
- The request object parses the request body and request header parameters
- [original] what is the core of programmer team management?
- 能源路由器入门必读:面向能源互联网的架构和功能
猜你喜欢

Es classes and objects, prototypes

Basic chapter: take you through notes

Flex flexible layout

Applet sliding, clicking and switching simple UI

arcgis操作:dwg数据转为shp数据

ORM--数据库增删改查操作逻辑

喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法

Enterprise practice | construction of banking operation and maintenance index system under complex business relations

Win10安装VS2015

ISP、IAP、ICP、JTAG、SWD的编程特点
随机推荐
2016 CCPC Hangzhou Onsite
CDZSC_2022寒假个人训练赛21级(2)
Pit encountered by vs2015 under win7 (successful)
中国首款电音音频类“山野电音”数藏发售来了!
ORM -- query type, association query
Parameter sniffing (2/2)
Deadlock caused by non clustered index in SQL Server
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
Introduction to automated testing framework
ISP、IAP、ICP、JTAG、SWD的编程特点
MCU与MPU的区别
Advanced function learning in ES6
Introduction to energy Router: Architecture and functions for energy Internet
A wave of open source notebooks is coming
CDZSC_ 2022 winter vacation personal training match level 21 (2)
Gym - 102219j kitchen plates (violent or topological sequence)
Or in SQL, what scenarios will lead to full table scanning
能源路由器入门必读:面向能源互联网的架构和功能
Scratch crawler mysql, Django, etc
Main (argc, *argv[]) details