unity3d - 如果使用 UnityWebRequest,如何使用 WriteAllBytes?
问题描述
我使用 UnityWebRequest 获取流资产文件夹上的文件,因为 WWW 已过时,现在在 FileWriteAllBytes 上我无法正确 downloader.bytes 因为它向我返回错误,有人可以帮助我吗
#if UNITY_ANDROID
// path on streamingasset folder
string path = System.IO.Path.Combine(Application.streamingAssetsPath, "game.dat");
UnityWebRequest downloader = UnityWebRequest.Get(path);
yield return downloader.SendWebRequest();
while (!downloader.isDone)
{
// nothing to be done while downloader gets our db file
}
// then save to application.persistentdatapath
// on this second param i dont know what do right i cant put donwloader.bytes because is obsolete
File.WriteAllBytes(dataFilePath, missing);
#endif
解决方案
使用下载处理程序
UnityWebRequest downloader = UnityWebRequest.Get(path);
yield return downloader.SendWebRequest();
DownloadHandler handler = downloader.downloadHandler;
File.WriteAllBytes(dataFilePath, handler.data);
推荐阅读
- c# - 在不使用 htmlagilitypack 的情况下从 html 中获取价值
- java - 如何使用 JDBC 使用准备好的语句在同一个表上加入别名?
- sql - 如何在 SQL Server 中进行网络类型分布?
- c++ - 是
char32_t 的等价物 - javascript - 为什么 clear 函数在给定的代码中不起作用?
- java - Java最终变量 - 显示两次初始化,请解释
- r - 缺少条形图上的 LIkert 图标签
- async-await - 您可以在 paperjs 中使用 await 吗?
- java - DataInputStream readUTF 给出了不正确的字符串值
- laravel - Laravel 观察者没有触发条件