void OpenDB()
{
// 电脑端路径
string path = Application.dataPath + "/Hero.sqlite";
string con = "data source=" + path; // data source= 在/asses文件夹平级上创建文件
// 手机端路径
string moblePath = Application.persistentDataPath + "/Hero.sqlite";
string mobleCon = "URI=file:" + path;
Debug.Log(File.Exists(path));
if (!File.Exists(path))
{
// jar:file:是安卓手机路径的意思
// Application.dataPath + "!/assets/" 即 Application.dataPath/StreamingAssets
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + "Hero.sqlite");
while (!loadDB.isDone)
{
Debug.Log("wait");
}
File.WriteAllBytes(path, loadDB.bytes);
}
// con是电脑端,根据需求还可以更换成手机端路径mobleCon
connection = new SqliteConnection(con);
connection.Open();
}
【Unity】在安卓手机上使用SQLite
最新推荐文章于 2024-03-21 10:34:30 发布