less than 1 minute read


1. SQLite ๋‹ค์šด๋กœ๋“œ


๋‹ค์Œ ์‚ฌ์ดํŠธ์—์„œ 3๋ฒˆ์งธ ์ค„์— ์žˆ๋Š” ๊ฒƒ์„ ๋‹ค์šด๋ฐ›์œผ๋ฉด ๋œ๋‹ค.

https://sqlitebrowser.org/dl/

image


2. Unity ์ƒ์„ฑ

Unity์—์„œ ์ƒˆ Project๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

์•„๋ž˜ DDL์„ ๋‹ค์šด ๋ฐ›์€ ํ›„ Asset ํด๋” ์•ˆ์˜ Plugins ํด๋”๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋„ฃ๋Š”๋‹ค.

was-practice.zip

์ž์‹ ์˜ ์œ ๋‹ˆํ‹ฐ ํ”„๋กœ์ ํŠธ Assets ํด๋” ์•ˆ์— StreamingAssets ํด๋”๋ฅผ ๋งŒ๋“  ํ›„ DB Browser for SQLite.exe๋ฅผ ์‹คํ–‰์‹œ์ผœ์„œ MyDB๋กœ ์ƒˆ ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.


3. ๊ธฐ๋ณธ์ฐฝ ๊ตฌ์„ฑ

Hierarchy์— Canvas๋ฐ‘์œผ๋กœ Panel์„ ๋งŒ๋“ ํ›„ Input Field 2๊ฐœ์™€ Button์„ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
์ดํ›„ ์ด๋ฆ„์„ ๋ฐ”๊ฟ”์ฃผ๊ณ , ID์™€ Password ๊ฐ์ฒด์˜ ์•ˆ์˜ Placeholder์•ˆ์˜ text๋ฅผ ๊ฐ๊ฐ Id์™€ Password๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.
๋˜ create Empty๋กœ script ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.


image

์ดํ›„ Scripts๋ผ๋Š” ํด๋”๋ฅผ ๋งŒ๋“ค์–ด์ค€ ํ›„ ์•ˆ์— LogIn Script๋ฅผ ์ƒ์„ฑํ•ด์ค€๋‹ค.


4. DB ์ฝ”๋“œ ์ž‘์„ฑ


IEnumerator DBCreate()
{
    string filepath = string.Empty;
    filepath = Application.dataPath + "/MyDB.db";
    if (!File.Exists(filepath))
    {
        File.Copy(Application.streamingAssetsPath + "/MyDB.db", filepath);
    }
    yield return new WaitForSeconds(0.1f);
    print("DB ์ƒ์„ฑ ์™„๋ฃŒ");
}

public string GetDBFilePath()
{
    string str = string.Empty;
    if (Application.platform == RuntimePlatform.Android)
    {
        str = "URI=file:" + Application.persistentDataPath + "/MyDB.db";
    }
    else
    {
        str = "URI=file:" + Application.streamingAssetsPath + "/MyDB.db";
    }
    return str;
}

public void DBConnectionCheck()
{
    try
    {
        dbConnection = new SqliteConnection(GetDBFilePath());
        dbConnection.Open();

        if (dbConnection.State == ConnectionState.Open)
        {
            print("DB์—ฐ๊ฒฐ ์„ฑ๊ณต");
        }
        else
        {
            print("์—ฐ๊ฒฐ์‹คํŒจ[ERROR]");
        }
    }
    catch (Exception e)
    {
        print(e);
    }
}



๊ฐœ์ธ ๊ณต๋ถ€ ๊ธฐ๋ก์šฉ ๋ธ”๋กœ๊ทธ์ž…๋‹ˆ๋‹ค.
ํ‹€๋ฆฌ๊ฑฐ๋‚˜ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ์ œ๋ณดํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.๐Ÿ˜