如何修复在构建统一期间不起作用的sqlite?
我正在统一制作一款游戏,我想使用SQLite数据库有效地保存ROADONLY数据。 编辑器中的一切都很好,但是当我将其构建到Windows时,它根本无法从中读取。我尝试了所有内容,路径位于流媒体中,我检查了我的数据库不是空的,我有所有必要的.dll文件,我什至尝试使用不同来源的不同版本。我还尝试了我的程序,即使在构建后也会在数据库旁边找到一个简单的TXT文件,因此数据库并不重要。我必须使用数据库,因为我需要数十个已阅读并手动编写的数据。另外,我想要一种灵活而动态的方法来修改播放时间的数据。 这是我的代码,我有多个处理数据库的函数,但这是在这里相关的一个:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Mono.Data.Sqlite;
using System.Data;
using Mono.Data;
using System.IO;
public class DataBaseHandler {
public static Record FindRecord(string database, string table, List<string> fields, string feltetel)
{
Record record = new Record(new List<string>());
string conn = "URI=file:" + System.IO.Path.Combine(Application.streamingAssetsPath, database + ".db");
IDbConnection dbconn;
dbconn = (IDbConnection)new SqliteConnection(conn);
dbconn.Open();
IDbCommand dbcmd = dbconn.CreateCommand();
string field = "";
foreach (var item in fields)
{
if (item == fields[fields.Count - 1])
{
field = field + item + " ";
}
else
{
field = field + item + ", ";
}
}
//Debug.Log(field);
string sqlQuery = "SELECT " + field + "FROM " + table + " WHERE " + feltetel;
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < fields.Count; i++)
{
record.sor.Add(reader.GetString(i));
}
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
return record;
}
}
记录只是一个简单的类,但是我会向您展示:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Record
{
public List<string> sor;
public Record(List<string> sor)
{
this.sor = sor;
}
public Record()
{
}
}
另外,我的文件夹中都有每个Neccessary插件。请帮助我,这让我发疯,我一直在寻找解决方案一个星期。
I am making a game in Unity where I'd like to use SQLite database for saving readonly data effectivly.
Everything is fine in the Editor, but when I build it to windows, it simply couldn't read from it. I tried everything, the path is in the StreamingAssets, I checked that my database is not empty, I have all the neccessary .dll files, I even tried with different versions, from different sources. I also tried that my program, even after build will find a simple txt file next to the database, so it's not matter of the datapath. I must use database, because I need a dozens of data that is readonly and have been written manually. Also I want a flexible and dynamic way to modify my data during playtime.
Here is my code, I have multiple functions handling the database, but this the one that's relevant here:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Mono.Data.Sqlite;
using System.Data;
using Mono.Data;
using System.IO;
public class DataBaseHandler {
public static Record FindRecord(string database, string table, List<string> fields, string feltetel)
{
Record record = new Record(new List<string>());
string conn = "URI=file:" + System.IO.Path.Combine(Application.streamingAssetsPath, database + ".db");
IDbConnection dbconn;
dbconn = (IDbConnection)new SqliteConnection(conn);
dbconn.Open();
IDbCommand dbcmd = dbconn.CreateCommand();
string field = "";
foreach (var item in fields)
{
if (item == fields[fields.Count - 1])
{
field = field + item + " ";
}
else
{
field = field + item + ", ";
}
}
//Debug.Log(field);
string sqlQuery = "SELECT " + field + "FROM " + table + " WHERE " + feltetel;
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < fields.Count; i++)
{
record.sor.Add(reader.GetString(i));
}
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
return record;
}
}
Record is just a simple class, but I will show you:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Record
{
public List<string> sor;
public Record(List<string> sor)
{
this.sor = sor;
}
public Record()
{
}
}
Also, I have every neccessary plugins in my folder. Please help me, this drives me crazy, I have been looking for the solution for a week now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论