Unity3D如何使用Sqlite数据库

来源:互联网 发布:炫舞辅助源码 编辑:程序博客网 时间:2024/06/11 20:09

1,需要用到这几个dll文件:Mono.Data.Sqlite.dllsqlite3.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:

01using UnityEngine;
02using System.Collections;
03using System.Collections.Generic;
04using System;
05using System.Data;
06using Mono.Data.SqliteClient;
07using System.Text;
08using System.IO;
09  
10public class DBHelp : MonoBehaviour {
11    static string conn=string.Empty;
12    // Use this for initialization
13  
14    public static string getConstr()//得到字符串
15    {
16  
17  
18#if UNITY_EDITOR
19        conn = "URI=file:" + Application.dataPath + "/StreamingAssets/KLandNG.db";
20  
21       
22  
23#elif UNITY_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}
0 0
原创粉丝点击