3
有誰知道,我必須在統一項目目錄結構中放置一個文件(sqlite文件),以便在apk編譯和安裝後,文件保存在persistentDataPath中Android方面?ApplicationData.persistentDataPath Unity編輯器到Android
在此先感謝!
有誰知道,我必須在統一項目目錄結構中放置一個文件(sqlite文件),以便在apk編譯和安裝後,文件保存在persistentDataPath中Android方面?ApplicationData.persistentDataPath Unity編輯器到Android
在此先感謝!
直接資產文件夾內,創建一個文件夾名稱爲「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文件夾是關鍵。這麼多問題,很少。 – gdbj 2015-03-03 01:08:57