Unity Android 的 StreamingAssets 文件夹位置

Unity Android's StreamingAssets folder location

我在 Android 游戏中使用 StreamingAssets, 并希望在安装 APK 后在 StreamingAssets 文件夹中添加文件, 但是我不知道这个文件夹的位置。

你能帮帮我吗?

构建后不要执行此操作。

在您的 Assets/ 目录中的 Unity Editor 中创建 StreamingAssets 目录,并将所有文件添加到那里。它们将自动包含在构建中。

如果由于 Play 商店的 .apk 大小限制而需要此文件,则可以创建一个包含所有附加资产(包括 SteamingAssets 目录中的资产)的 .obb 文件。在这里检查 - https://docs.unity3d.com/Manual/android-OBBsupport.html.

您无法在构建后添加或修改流资产文件夹中的文件,因为在几乎所有平台上,该目录都是只读。来自 the docs:

On many platforms, the streaming assets folder location is read-only; you can not modify or write new files there at runtime. Use Application.persistentDataPath for a folder location that is writable.

也就是说,在 Android 上,流式资产的文件路径位于 "jar:file://" + Application.dataPath + "!/assets,来自相同的文档:

Android uses files inside a compressed APK /JAR file, "jar:file://" + Application.dataPath + "!/assets".

请注意,您无法通过标准 C# File 函数访问此文件位置,但需要使用 webrequest 访问它。

如果在 运行 期间需要一个目录来存储数据,则需要使用 Application.persistenDataPath 代替。 来自 the docs:

This value is a directory path where you can store data that you want to be kept between runs. When you publish on iOS and Android, persistentDataPath points to a public directory on the device. Files in this location are not erased by app updates. The files can still be erased by users directly.