2019년 4월 12일 금요일

# 유니티엔진에서 Sqlite 적용 방법 Flow

아래 순서대로 진행하면 될 것이다.. 아마도(?)

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;

아래 그림은, 개인 프로젝트에서 해당 파일들을 어디에다 위치시켰는지 보여준다.
(라이브러리는 Plugins 폴더에 넣어야하니까.)




그리고 다음처럼 이용하고 있다. ( in Code-level)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using (IDbConnection dbconn = (IDbConnection)new SqliteConnection(conn.ToString()))
            {
                using (IDbCommand dbcmd = dbconn.CreateCommand())
                {
                    dbconn.Open(); //Open connection to the database.
                    string sqlQuery = "SELECT name, type, amount, id FROM USER_ITEM";
                    dbcmd.CommandText = sqlQuery;
                    using (IDataReader reader = dbcmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            USER_ITEM userItem;
                            userItem.name = reader.GetString(0);
                            userItem.type = reader.GetInt32(1);
                            userItem.amount = reader.GetInt32(2);
                            userItem.id = reader.GetString(3);
                            userItemList.Add(userItem);
                        }
                        reader.Close();
                    }
                }
                dbconn.Close();
            }


p.s. 32bit, 64bit 별로 실행파일을 만드려는 경우
     https://docs.unity3d.com/Manual/PluginsForDesktop.html

댓글 없음:

댓글 쓰기