该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public void ConnectionDB()
{
if (conn == null)
{
string path = "/Data.db";
if(Application.platform == RuntimePlatform.IPhonePlayer)
{
path = Application.persistentDataPath + path;
if(!File.Exists(path))
{
WWW loadDB = new WWW("file://" + Application.streamingAssetsPath + "/Data.db");
while (!loadDB.isDone)
{
}
File.WriteAllBytes("file://" + path, loadDB.bytes);
WWW downDB = new WWW(path);
while (!downDB.isDone)
{
}
}
path = "data source=" + path;
}
else if(Application.platform == RuntimePlatform.Android)
{
path = Application.persistentDataPath + path;
if (!File.Exists(path))
{
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/Data.db");
//yield return loadDB;
while (!loadDB.isDone)
{
}
/*
FileStream fsDB = File.Create(path);
fsDB.Write(loadDB.bytes, 0, loadDB.bytes.Length);
fsDB.Flush();
fsDB.Close();
*/
File.WriteAllBytes(path, loadDB.bytes);
WWW downDB = new WWW("file://" + path);
while(!downDB.isDone)
{
}
}
else
{
/*
File.Delete(path);
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/Assets/Data/Data.db");
File.WriteAllBytes(path, loadDB.bytes);
*/
}
path = "URI=file:" + path;
}
else
{
path = "data source=" + Application.dataPath + "/StreamingAssets" + path;
}
conn = new SqliteConnection(path);
}
else
{
Debug.Log("数据库未连接");
}
}