当前位置:网站首页>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);
}
}
}
边栏推荐
- EXT2 file system
- ES6中的函數進階學習
- 【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
- STM32基础知识—内存映射
- Performance optimization record of the company's product "yunzhujia"
- Internship log - day04
- Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
- Huffman encoded compressed file
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
- The request object parses the request body and request header parameters
猜你喜欢
能源路由器入门必读:面向能源互联网的架构和功能
The request object parses the request body and request header parameters
ORM--数据库增删改查操作逻辑
Pit encountered by vs2015 under win7 (successful)
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
字节跳动 Kitex 在森马电商场景的落地实践
Agile course training
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
arcgis操作:dwg数据转为shp数据
Arcgis操作: 批量修改属性表
随机推荐
能源路由器入门必读:面向能源互联网的架构和功能
The physical meaning of imaginary number J
AI moves from perception to intelligent cognition
STM32中AHB总线_APB2总线_APB1总线这些是什么
Basic chapter: take you through notes
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
VS Code指定扩展安装位置
Deep understanding of UDP, TCP
内存==c语言1
“十二星座女神降临”全新活动推出
Flex flexible layout
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
Using keras in tensorflow to build convolutional neural network
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
Apprentissage avancé des fonctions en es6
Postman interface test I
【ORM框架】
[untitled]
高斯消元
Agile course training