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);
        }
    }

你可能感兴趣的:(Unity,C#,unity,webgl)