1

我需要获取位于 Application.streamingAssetsPath 下的文件路径,但我知道我不能只获取位于 streaminAssets 目录下的文件路径,因为该文件将在 apk 中压缩。因此,为了获得路径,我需要将文件从 Application.streamingAssetsPath 复制到 Application.persistentDataPath,这样我就可以获得文件的路径。

为了复制我使用这种方法

    IEnumerator CopyFile(string from, string to)
    {
        WWW www = new WWW(from);

        while (!www.isDone)
        {
            //Must yield below/wait for a frame
            yield return null;
        }

        Debug.Log("Done downloading");

        byte[] yourBytes = www.bytes;
        Debug.Log($"Unity HERE lenght:: {www.bytes.Length}");    <----- here I get 0kb.

        //Now Save it
        File.WriteAllBytes(to, yourBytes);
    }

字节数组的长度为 0。

问题是 - 我试图从中复制的路径是 : /jar:file:/data/app/com.co.unityandroidplayer-7msilEGHVZkbwTrDAvgfig==/base.apk!/assets/3.co,如文档中所写

https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html?_ga=2.262004941.1502410520.1604388002-954575440.1598172327

It is not possible to access the StreamingAssets folder on WebGL and Android platforms

好的,所以我开始了解如何去做。我找到了这样的帖子

https://forum.unity.com/threads/copying-everyhting-under-streamingassets-to-persistentdatapath-on-android.431269/#post-3276021

不完全一样,但是这里有一个人也尝试从 复制Application.streamingAssetsPath,但我不明白它是如何工作的?因为最后他使用了这条线

WWW www = new WWW(Application.streamingAssetsPath + "/Data.tgz");

但是再次根据文档(上面的链接),无法在 android 上访问。

那么,该怎么做呢?奇怪的是我有一个文件并且我知道它驻留在哪里,但是我没有任何选项可以获取它的路径。即使复制也不起作用。

4

1 回答 1

1

Android 中 StreamingAssets 的路径 - "jar:file://" + Application.dataPath + "!/assets"

于 2020-11-03T15:43:48.953 回答