当前位置:网站首页>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);
}
}
}
边栏推荐
- Scratch crawler mysql, Django, etc
- 字节跳动 Kitex 在森马电商场景的落地实践
- Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
- CDZSC_ 2022 winter vacation personal training match level 21 (1)
- CDZSC_2022寒假个人训练赛21级(1)
- Deep understanding of UDP, TCP
- Guys, have you ever encountered the case of losing data when Flink CDC reads mysqlbinlog? Every time the task restarts, there is a probability of losing data
- [ORM framework]
- Internship log - day04
- 2020浙江省赛
猜你喜欢

Qualifying 3
![[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)](/img/94/b4df1ce2861a851fcd8de3e08540b0.png)
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)

一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系

20排位赛3

【原创】程序员团队管理的核心是什么?

Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is

Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation

ORM -- logical relation and & or; Sort operation, update record operation, delete record operation

ORM model -- creation and query of data records

Enterprise practice | construction of banking operation and maintenance index system under complex business relations
随机推荐
20排位赛3
MySQL can connect locally through localhost or 127, but cannot connect through intranet IP (for example, Navicat connection reports an error of 1045 access denied for use...)
Google Colab装载Google Drive(Google Colab中使用Google Drive)
【原创】程序员团队管理的核心是什么?
The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
Writing file types generated by C language
STM32基础知识—内存映射
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
ORM--数据库增删改查操作逻辑
In addition to the objective reasons for overtime, what else is worth thinking about?
uboot机构简介
ORM -- database addition, deletion, modification and query operation logic
Guys, have you ever encountered the case of losing data when Flink CDC reads mysqlbinlog? Every time the task restarts, there is a probability of losing data
Pit using BigDecimal
CDZSC_ 2022 winter vacation personal training match level 21 (1)
Advanced function learning in ES6
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
XML配置文件解析与建模
The landing practice of ByteDance kitex in SEMA e-commerce scene
ORM--分组查询,聚合查询,查询集QuerySet对象特性