Skip to content

Instantly share code, notes, and snippets.

@fogmoon
Forked from amowu/GetStreamingAssetsPath.cs
Created September 26, 2017 03:44
Show Gist options
  • Save fogmoon/6dd3626e98354eed05da6942240cf2dc to your computer and use it in GitHub Desktop.
Save fogmoon/6dd3626e98354eed05da6942240cf2dc to your computer and use it in GitHub Desktop.
Get Unity StreamingAssets file path with Android and iOS.
// Put your file to "YOUR_UNITY_PROJ/Assets/StreamingAssets"
// example: "YOUR_UNITY_PROJ/Assets/StreamingAssets/db.bytes"
string dbPath = "";
if (Application.platform == RuntimePlatform.Android)
{
// Android
string oriPath = System.IO.Path.Combine(Application.streamingAssetsPath, "db.bytes");
// Android only use WWW to read file
WWW reader = new WWW(oriPath);
while ( ! reader.isDone) {}
realPath = Application.persistentDataPath + "/db";
System.IO.File.WriteAllBytes(realPath, reader.bytes);
dbPath = realPath;
}
else
{
// iOS
dbPath = System.IO.Path.Combine(Application.streamingAssetsPath, "db.bytes");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment