c# - 如何在 unity 3d 5 中连接 sqlite 数据库?(无插件)

标签 c# android sqlite unity3d

您好,我正在使用 unity3d 5(c# 语言)开发一个安卓游戏项目,该项目需要将一些数据保存到 sqlite 数据库中。 游戏没有太多数据来存储它只有 1 个表。有一些连接到 sqlite 的统一插件,但我不想使用它们。 那么如何将我的数据统一存储在 sqlite 文件中?

最佳答案

你可以找到你的答案here

  1. Create new folder under Assets Folder Rename it Plugins .
  2. Copy sqlite3.def and sqlite3.dll into Assets/Plugins in your unity project .You can download these files here http://www.sqlite.org/download.html for windows (Precompiled Binaries for Windows)
  3. Download SQLite Browser http://sourceforge.net/projects/sqlitebrowser/ or http://sqliteadmin.orbmu2k.de/ download SQLite Administrator tool
  4. Create Database in Assets folder in your unity project using SQLite Browser.
  5. Copy System.Data.dll and Mono.Data.Sqlite.dll from **C:\Program Files (x86)\Unity \Editor\Data\Mono\lib\mono\2.0* and paste them in your Assets/Plugins* folder in your unity project.
  6. Add these namespaces using Mono.Data.Sqlite; using System.Data; using System;
  7. string conn= "URI=file:" + Application.dataPath + "/PickAndPlaceDatabase.s3db";

Replace PickAndPlaceDatabase.s3db with your database name

void Start () {
    string conn = "URI=file:" + Application.dataPath + "/PickAndPlaceDatabase.s3db"; //Path to database.
    IDbConnection dbconn;
    dbconn = (IDbConnection) new SqliteConnection(conn);
    dbconn.Open(); //Open connection to the database.
    IDbCommand dbcmd = dbconn.CreateCommand();
    string sqlQuery = "SELECT value,name, randomSequence " + "FROM PlaceSequence";
    dbcmd.CommandText = sqlQuery;
    IDataReader reader = dbcmd.ExecuteReader();
    while (reader.Read())
    {
        int value = reader.GetInt32(0);
        string name = reader.GetString(1);
        int rand = reader.GetInt32(2);

        Debug.Log( "value= "+value+"  name ="+name+"  random ="+  rand);
    }
    reader.Close();
    reader = null;
    dbcmd.Dispose();
    dbcmd = null;
    dbconn.Close();
    dbconn = null;
}

enter image description here enter image description here

Further SQLite Help Visit : http://www.tutorialspoint.com/sqlite/

关于c# - 如何在 unity 3d 5 中连接 sqlite 数据库?(无插件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33705925/

相关文章:

java - 使用 JavaMail API 的电子邮件线程消息

java - GestureBuilder 无法保存重命名的手势

c# - Java - Java 有类似 C# 的结构自动构造函数的东西吗

c# - 如果不存在则更改表添加 Cassandra

c# - 通过引用传递 VS 静态变量

android - 我怎样才能使这个 sqlite 查询工作?

iphone - iPhone应用程序之间如何共享数据

c# - ASP MVC 5 路由映射

android - 如何使用 Xamarin/Monogame 在 Android 应用程序的屏幕底部显示 AdMob 广告?

c++ - 如何在 C++ 中为 sqlite 进行非静态回调?