美文网首页
unity读取streamingassets路径下文件

unity读取streamingassets路径下文件

作者: UnityAsk | 来源:发表于2016-11-24 20:02 被阅读2610次

It’s always best to use Application.streamingAssetsPath
to get the location of the StreamingAssets folder, as it will always point to the correct location on the platform where the application is running.

On a desktop computer (Mac OS or Windows) the location of the files can be obtained with the following code:
path = Application.dataPath + "/StreamingAssets";
On iOS, use:
path = Application.dataPath + "/Raw";
On Android, use:
path = "jar:file://" + Application.dataPath + "!/assets/";

On Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity’s WWW class to retrieve the file, you need to use additional software to see inside the .jar archive and obtain the file.

  public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile");
  public string result = "";
  IEnumerator Example() {
    if (filePath.Contains("://")) {
        WWW www = new WWW(filePath);
        yield return www;
        result = www.text;
    } else
        result = System.IO.File.ReadAllText(filePath);
}

相关文章

网友评论

      本文标题:unity读取streamingassets路径下文件

      本文链接:https://www.haomeiwen.com/subject/ywfipttx.html