如何在Unity 3D 5中连接sqlite DB?(无插件) [英] how to connect a sqlite DB in unity 3d 5?(no plugins)

查看:240
本文介绍了如何在Unity 3D 5中连接sqlite DB?(无插件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在unity3d 5(语言C#)中的一个Android游戏项目中工作,该项目需要将一些数据保存到sqlite数据库中. 游戏没有太多数据要存储,它只有1张桌子.有一些统一插件可以连接到sqlite,但我不想使用它们. 那么如何将数据统一存储在sqlite文件中?

Hello i'm working on an android game project in unity3d 5 (language c#)that needs to save some data to sqlite database. the game doesn't have a lot of data to store it has only 1 table .there are some plugins for unity that connect to sqlite but i don't want to use them . so how can i store my data on sqlite file in unity ?

推荐答案

您可以找到答案

  1. 在资产"文件夹下创建新文件夹,将其重命名为插件.
  2. sqlite3.def sqlite3.dll 复制到统一项目中的资产/插件中.您可以在此处下载这些文件 Windows的 http://www.sqlite.org/download.html (预编译的二进制文件) 对于Windows)
  3. 下载SQLite浏览器 http://sourceforge.net/projects/sqlitebrowser/ http://sqliteadmin.orbmu2k.de/下载SQLite管理员工具
  4. 使用SQLite浏览器在统一项目的资产文件夹中创建数据库.
  5. 从** C:\ Program Files(x86)\ Unity \ Editor \ Data \ Mono复制 System.Data.dll Mono.Data.Sqlite.dll \ lib \ mono \ 2.0 *并将其粘贴到统一项目中的Assets/Plugins *文件夹中.
  6. 使用Mono.Data.Sqlite添加这些名称空间;使用System.Data;使用系统;
  7. string conn ="URI =文件:" + Application.dataPath +"/PickAndPlaceDatabase.s3db";
  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";

用您的数据库名称替换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;
}

进一步的SQLite帮助访问: http://www.tutorialspoint.com/sqlite/

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

这篇关于如何在Unity 3D 5中连接sqlite DB?(无插件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆