我的VR Oculus rift有一个高分表,我想将数据保存到sqlite数据库并显示来自VR耳机的数据,但是只有unity能够显示来自数据库的数据到高分板,当我将游戏从unity导入到oculus rift时,VR耳机甚至没有显示来自数据库的任何数据。
下面是我用来显示比分的代码,它只能在unity内部工作,而不能在vr耳机上工作:
private void GetScores()
{
highScores.Clear();
using (IDbConnection dbConnection = new SqliteConnection(connectionString))
{
dbConnection.Open();
Debug.Log("DB Step 1");
using (IDbCommand dbCmd = dbConnection.CreateCommand())
{
Debug.Log("DB Step 2");
string sqlQuery = "SELECT * FROM highscoresss";
dbCmd.CommandText = sqlQuery;
using (IDataReader reader = dbCmd.ExecuteReader())
{
Debug.Log("DB Step 3");
while (reader.Read())
{
Debug.Log("DB Step 4");
highScores.Add(new HighScore(reader.GetInt32(0), reader.GetString(1), reader.GetString(2)));
}
Debug.Log("DB Step 5");
dbConnection.Close();
reader.Close();
}
}
}
}
void Start()
{
connectionString = "URI=file:" + Application.dataPath + "/StreamingAssets/mydatabasess.db";
ChangingText.text = connectionString;
ShowScores();
}我使用Andriodlog捕获错误,它一直显示错误连接数据库:sqlite3
vr Oculus rift错误消息androidlog:

数据整齐划一的高分表:

发布于 2019-12-14 06:05:17
看起来问题出在数据库路径上;你正在为你的Android版本修改它吗?流式资源通常由Unity复制到特定位置accessible through different means depending on the platform。如果我是您,出于调试目的,我会检查您的数据库文件是否在您期望的位置。
if (!File.Exists(yourDatabasePath))
Debug.Log("Couldn't locate database at {0}",yourDatabasePath);如果这最终成为罪魁祸首,使用streamingAssetsPath或只是将数据库复制到设备上的持久存储中,然后通过新路径正常访问它可能会更容易,这将为您的Oculus构建定义如下:
string yourDatabasePath =
#if UNITY_EDITOR
"Assets/StreamingAssets/mydatabasess.db";
#else
"sdcard/MyAppFolder/mydatabasess.db"; //just an example
#endifhttps://stackoverflow.com/questions/59263744
复制相似问题