当前位置:网站首页>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);
}
}
}
边栏推荐
- Pytest learning - dayone
- The landing practice of ByteDance kitex in SEMA e-commerce scene
- In addition to the objective reasons for overtime, what else is worth thinking about?
- 2016 CCPC Hangzhou Onsite
- CDZSC_2022寒假个人训练赛21级(2)
- ORM--查询类型,关联查询
- Some test points about coupon test
- 2020ccpc Weihai J - Steins; Game (SG function, linear basis)
- STM32中AHB总线_APB2总线_APB1总线这些是什么
- Phpcms realizes PC website access to wechat native payment
猜你喜欢

Win10安装VS2015

企业实战|复杂业务关系下的银行业运维指标体系建设

The Himalaya web version will pop up after each pause. It is recommended to download the client solution

中国首款电音音频类“山野电音”数藏发售来了!

Software modeling and analysis

request对象对请求体,请求头参数的解析

Basic chapter: take you through notes

Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance

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

ES类和对象、原型
随机推荐
Deadlock caused by non clustered index in SQL Server
Can I open a stock trading account online? Is it safe
Gauss elimination
web3.0系列之分布式存储IPFS
There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
Application of C # XML
XML配置文件解析与建模
arcgis操作:dwg数据转为shp数据
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
C# Socke 服务器,客户端,UDP
CDZSC_ 2022 winter vacation personal training match level 21 (1)
Writing file types generated by C language
ORM -- grouping query, aggregation query, query set queryset object properties
CDZSC_ 2022 winter vacation personal training match level 21 (2)
20排位赛3
uboot机构简介
视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」
ORM--查询类型,关联查询
2020ccpc Weihai J - Steins; Game (SG function, linear basis)
Some test points about coupon test