unity 发布WebGL 读取streamingAssets文件夹内的TXT 遇到的问题

 读取的文件路径上代码

        string path = Path.Combine(Application.streamingAssetsPath, "data.txt");               //unity Editor,webgl 端  都可以读取
        string path = Application.streamingAssetsPath + "/data.txt";                           //unity Editor,webgl 端  都可以读取
        //string path = "file://" + Path.Combine(Application.streamingAssetsPath, "data.txt");   //unity Editor可以读取,webgl 端 读取不到
        //string path = "file://" + Application.streamingAssetsPath + "/data.txt";               //unity Editor可以读取,webgl 端 读取不到
        //string path = @"file://" + Application.streamingAssetsPath + "/data.txt";              //unity Editor可以读取,webgl 端 读取不到
        //string path = "file:///" + Application.streamingAssetsPath + "/data.txt";              //unity Editor可以读取,webgl 端 读取不到

读取方式

    IEnumerator LoadTxt()
    {
 
        string path = Application.streamingAssetsPath + "/data.txt";
 
        ///第一种方式
        WWW www = new WWW(path);
        yield return www;
        string data = www.text;
        Debug.Log(data);
 
 
        ///第二种方式
        UnityWebRequest request = UnityWebRequest.Get(path);
        yield return request.SendWebRequest();
        if (request.isNetworkError || request.isHttpError)
        {
            Debug.Log(request.error);
        }
        else
        {
            string data = request.downloadHandler.text;
            Debug.Log(data);
        }
    }

相关推荐

  1. Unity发布webgl之后打开streamingAssetshtml文件

    2023-12-23 06:52:03       27 阅读
  2. js读取本地 excel文件txt文件内容

    2023-12-23 06:52:03       19 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-23 06:52:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-23 06:52:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-23 06:52:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-23 06:52:03       18 阅读

热门阅读

  1. 【cesium-2】Cesium相机系统

    2023-12-23 06:52:03       43 阅读
  2. R-列表、矩阵、数组转化为向量

    2023-12-23 06:52:03       40 阅读
  3. 【数据分析】数据指标的分类及应用场景

    2023-12-23 06:52:03       38 阅读
  4. RabbitMQ消息确认机制

    2023-12-23 06:52:03       41 阅读
  5. Node.js —— EventEmitter

    2023-12-23 06:52:03       41 阅读
  6. uniapp 统一获取授权提示和48小时间隔授权

    2023-12-23 06:52:03       34 阅读