当前位置:网站首页>Unity UnityWebRequest 下载封装
Unity UnityWebRequest 下载封装
2022-06-26 14:47:00 【帅_shuai_】
Unity UnityWebRequest 下载封装
对unity原生的UnityWebRequest 进行二次封装
public void UnityWebRequestLoad<T>(string path, Action<T> action, string localPath = "",
AudioType audioType = AudioType.MPEG) where T : class
{
StartCoroutine(UnityWebRequestLoadAsync(path, action, localPath, audioType));
}
private IEnumerator UnityWebRequestLoadAsync<T>(string path, Action<T> action, string localPath = "",
AudioType audioType = AudioType.MPEG) where T : class
{
UnityWebRequest req = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET);
if (typeof(T) == typeof(byte[]))
req.downloadHandler = new DownloadHandlerBuffer();
else if (typeof(T) == typeof(File))
req.downloadHandler = new DownloadHandlerFile(localPath);
else if (typeof(T) == typeof(Texture2D))
req.downloadHandler = new DownloadHandlerTexture();
else if (typeof(T) == typeof(AssetBundle))
req.downloadHandler = new DownloadHandlerAssetBundle(req.url, 0);
else if (typeof(T) == typeof(AudioClip))
req.downloadHandler = new DownloadHandlerAudioClip(req.url, audioType);
else
{
Debug.LogWarning("未知类型:" + typeof(T));
yield break;
}
yield return req.SendWebRequest();
if (req.result == UnityWebRequest.Result.Success)
{
if (typeof(T) == typeof(byte[]))
action?.Invoke(req.downloadHandler.data as T);
else if (typeof(T) == typeof(File))
action?.Invoke(null);
else if (typeof(T) == typeof(Texture2D))
action?.Invoke(DownloadHandlerTexture.GetContent(req) as T);
else if (typeof(T) == typeof(AssetBundle))
action?.Invoke(DownloadHandlerAssetBundle.GetContent(req) as T);
else if (typeof(T) == typeof(AudioClip))
action?.Invoke(DownloadHandlerAudioClip.GetContent(req) as T);
}
else
{
Debug.LogWarning("下载失败:" + req.result + req.error);
}
}
边栏推荐
- The intersect function in the dplyr package of R language obtains the data lines that exist in both dataframes and the data lines that cross the two dataframes
- Is it safe to open an online stock account? Somebody give me an answer
- Detailed explanation of C language programming problem: can any three sides form a triangle, output the area of the triangle and judge its type
- 工作上对金额价格类小数点的总结以及坑
- C语言刷题随记 —— 乒乓球比赛
- What is the ranking of Guosen Securities? Is it safe to open a stock account?
- 杜老师说网站更新图解
- Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)
- Kubernetes的pod调度
- Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法
猜你喜欢

View touch analysis

Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution

MySQL master-slave replication and read-write separation

This is the graceful file system mounting method, which is effective through personal testing

NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)...

Use abp Zero builds a third-party login module (I): Principles

Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法

印尼投资部长:鸿海考虑在其新首都建立电动公交系统、城市物联网

One copy ten, CVPR oral was accused of plagiarizing a lot, and it was exposed on the last day of the conference!

710. 黑名单中的随机数
随机推荐
Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
R language GLM function logistic regression model, using epidisplay package logistic The display function obtains the summary statistical information of the model (initial and adjusted odds ratio and
teamviewer显示设备数量上限解决方法
北京银行x华为:网络智能运维夯实数字化转型服务底座
详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
SAP 销售数据 实际发货数据导出 销量
R language uses the aggregate function of epidisplay package to split numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and use agg
网上股票开户安不安全?谁给回答一下
Where do people get their top energy?
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution
Sectigo的IP证书申请流程
Is it safe to open a stock account through the account opening link given by the broker manager? I want to open an account
Summary of decimal point of amount and price at work and pit
Talk about the RPA direction planning: stick to simple and valuable things for a long time
TS common data types summary
券商经理给的开户二维码安全吗?找谁可以开户啊?
重磅白皮书发布,华为持续引领未来智慧园区建设新模式
Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法
fileinput. js php,fileinput