我需要获取位于 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
,如文档中所写
It is not possible to access the StreamingAssets folder on WebGL and Android platforms
好的,所以我开始了解如何去做。我找到了这样的帖子
不完全一样,但是这里有一个人也尝试从 复制Application.streamingAssetsPath
,但我不明白它是如何工作的?因为最后他使用了这条线
WWW www = new WWW(Application.streamingAssetsPath + "/Data.tgz");
但是再次根据文档(上面的链接),无法在 android 上访问。
那么,该怎么做呢?奇怪的是我有一个文件并且我知道它驻留在哪里,但是我没有任何选项可以获取它的路径。即使复制也不起作用。