Unity3d Android的ApplicationData.persistentDataPath统一编辑器
有人知道吗,我必须将文件(sqlite文件)放在unity项目目录结构的何处,以便在apk编译和安装之后,该文件仍然存储在Android端的persistentDataPath中Unity3d Android的ApplicationData.persistentDataPath统一编辑器,unity3d,unityscript,Unity3d,Unityscript,有人知道吗,我必须将文件(sqlite文件)放在unity项目目录结构的何处,以便在apk编译和安装之后,该文件仍然存储在Android端的persistentDataPath中 提前谢谢 直接在Assets文件夹内,创建一个名为“StreamingAssets”的文件夹,并将您的sqlite数据库文件放入该文件夹中,然后使用以下代码将sqlite数据库提取并复制到persistentDataPath: void InitSqliteFile (string dbName) { // d
提前谢谢 直接在Assets文件夹内,创建一个名为“StreamingAssets”的文件夹,并将您的sqlite数据库文件放入该文件夹中,然后使用以下代码将sqlite数据库提取并复制到persistentDataPath:
void InitSqliteFile (string dbName)
{
// dbName = "example.sqlite";
pathDB = System.IO.Path.Combine (Application.persistentDataPath, dbName);
//original path
string sourcePath = System.IO.Path.Combine (Application.streamingAssetsPath, dbName);
//if DB does not exist in persistent data folder (folder "Documents" on iOS) or source DB is newer then copy it
if (!System.IO.File.Exists (pathDB) || (System.IO.File.GetLastWriteTimeUtc(sourcePath) > System.IO.File.GetLastWriteTimeUtc(pathDB))) {
if (sourcePath.Contains ("://")) {
// Android
WWW www = new WWW (sourcePath);
// Wait for download to complete - not pretty at all but easy hack for now
// and it would not take long since the data is on the local device.
while (!www.isDone) {;}
if (String.IsNullOrEmpty(www.error)) {
System.IO.File.WriteAllBytes(pathDB, www.bytes);
} else {
CanExQuery = false;
}
} else {
// Mac, Windows, Iphone
//validate the existens of the DB in the original folder (folder "streamingAssets")
if (System.IO.File.Exists (sourcePath)) {
//copy file - alle systems except Android
System.IO.File.Copy (sourcePath, pathDB, true);
} else {
CanExQuery = false;
Debug.Log ("ERROR: the file DB named " + dbName + " doesn't exist in the StreamingAssets Folder, please copy it there.");
}
}
}
}
应标记为正确答案。我一直在努力解决这个问题,但我想StreamingAssets文件夹是关键。这么多的陷阱,这么少的时间。