/// <summary>
    ///读取StreamingAssets中的文件 
    /// </summary>
    /// <param name="path">StreamingAssets下的文件路径</param>
    /// <returns>读取到的字符串</returns>
    public static string GetTextForStreamingAssets(string path)
    {
        string localPath = "";
        if (Application.platform == RuntimePlatform.Android)
        {
            localPath = Application.streamingAssetsPath + "/" + path;
        }
        else
        {
            localPath = "file:///" + Application.streamingAssetsPath + "/" + path;
        }

        WWW www = new WWW(localPath);

        if (www.error != null)
        {
            Debug.LogError("error while reading files : " + localPath);
            return ""; //读取文件出错
        }
        while (!www.isDone) { }
        Debug.Log("File content :  " + www.text);//www下面还有获取字节数组的属性
        return www.text;
    }

相关文章:

  • 2022-12-23
  • 2021-12-24
  • 2021-12-28
  • 2018-05-18
  • 2021-12-16
  • 2022-02-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2018-10-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案