当前位置:网站首页>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);
}
}
}
边栏推荐
- Why does the starting service report an error when installing MySQL? (operating system Windows)
- Postman tutorial - scripting
- Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
- Internship log - day04
- Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
- uboot机构简介
- Introduction to automated testing framework
- C# Socke 服务器,客户端,UDP
- Pytest learning - dayone
- Main (argc, *argv[]) details
猜你喜欢

Qualifying 3

ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作

Memory ==c language 1

【ORM框架】
![[ORM framework]](/img/72/13eef38fc14d85978f828584e689a0.png)
[ORM framework]

VS Code指定扩展安装位置

Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation

ORM -- database addition, deletion, modification and query operation logic

Win10安装VS2015

STM32中AHB总线_APB2总线_APB1总线这些是什么
随机推荐
Some thoughts on the testing work in the process of R & D
2020 Zhejiang Provincial Games
Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
STM32中AHB总线_APB2总线_APB1总线这些是什么
uboot机构简介
ORM -- query type, association query
STM32基础知识—内存映射
Postman interface test I
HCIP 第一天 笔记整理
Introduction to uboot
Win10 installation vs2015
Writing file types generated by C language
In addition to the objective reasons for overtime, what else is worth thinking about?
Delete a record in the table in pl/sql by mistake, and the recovery method
A wave of open source notebooks is coming
Before joining the chain home, I made a competitive product analysis for myself
Deadlock caused by non clustered index in SQL Server
The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
Apprentissage avancé des fonctions en es6
Huffman encoded compressed file