1,需要用到这几个dll文件:Mono.Data.sqlite.dll和sqlite3.dll和Mono.Data.sqliteClient.dll
2,将这几个dll文件放在Plugins下,必须放这里。
3,在Player Setting里的 OtherSettings里有个Optimization 下边的API Compatbility Level 选择.NET 2.0。
4,添加个sqliteHelper类。这个网上有,当然也可以自己写 - -!
5,数据库要放在StreamingAssets这个文件夹下。
5,剩下的就是操作了
随便写点代码:
[code]csharpcode:
01 |
using UnityEngine; |
02 |
using System.Collections; |
03 |
using System.Collections.Generic; |
04 |
using System; |
05 |
using System.Data; |
06 |
using Mono.Data.sqliteClient; |
07 |
using System.Text; |
08 |
using System.IO; |
09 |
|
10 |
public class DBHelp : MonoBehavIoUr { |
11 |
static string conn= string .Empty; |
12 |
// Use this for initialization |
13 |
|
14 |
public static string getConstr() //得到字符串 |
15 |
{ |
16 |
|
17 |
|
18 |
#ifUNITY_EDITOR |
19 |
conn = "URI=file:" + Application.dataPath + "/StreamingAssets/KLandNG.db" ; |
20 |
|
21 |
|
22 |
|
23 |
#elifUNITY_ANDROID |
24 |
|
25 |
|
26 |
conn = "URI=file:" + Application.persistentDataPath + "/" + "daniya.db" ; |
27 |
|
28 |
#endif |
29 |
|
30 |
|
31 |
return conn; |
32 |
} |
33 |
|
34 |
public static bool UpdateScoll() |
35 |
{ |
36 |
int i = sqliteHelper.ExecuteNonQuery(getConstr(),CommandType.Text, |
37 |
"update ItemInfo set name ='haha' where Type =1;" |
38 |
|
39 |
); |
40 |
return i > 0; |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
} |
46 |
} |