如果使用 UnityWebRequest,如何使用 WriteAllBytes?

问题描述

我使用 UnityWebRequest 来获取流资产文件夹上的文件,因为 WWW 已经过时,现在在 FileWriteallBytes 上我不能正确下载器.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);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...