Unity3D如何使用Sqlite数据库

前端之家收集整理的这篇文章主要介绍了Unity3D如何使用Sqlite数据库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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:

@H_301_43@01
usingUnityEngine;
@H_301_43@02
usingSystem.Collections;
@H_301_43@03
usingSystem.Collections.Generic;
@H_301_43@04
usingSystem;
@H_301_43@05
usingSystem.Data;
@H_301_43@06
usingMono.Data.sqliteClient;
@H_301_43@07
usingSystem.Text;
@H_301_43@08
usingSystem.IO;
@H_301_43@09
@H_301_43@10
publicclassDBHelp : MonoBehavIoUr {
@H_301_43@11
staticstringconn=string.Empty;
@H_301_43@12
// Use this for initialization
@H_301_43@13
@H_301_43@14
publicstaticstringgetConstr()//得到字符串
@H_301_43@15
{
@H_301_43@16
@H_301_43@17
@H_301_43@18
#ifUNITY_EDITOR
@H_301_43@19
conn ="URI=file:"+ Application.dataPath +"/StreamingAssets/KLandNG.db";
@H_301_43@20
@H_301_43@21
@H_301_43@22
@H_301_43@23
#elifUNITY_ANDROID
@H_301_43@24
@H_301_43@25
@H_301_43@26
conn ="URI=file:"+ Application.persistentDataPath +"/"+"daniya.db";
@H_301_43@27
@H_301_43@28
#endif
@H_301_43@29
@H_301_43@30
@H_301_43@31
returnconn;
@H_301_43@32
}
@H_301_43@33
@H_301_43@34
publicstaticboolUpdateScoll()
@H_301_43@35
{
@H_301_43@36
inti = sqliteHelper.ExecuteNonQuery(getConstr(),CommandType.Text,
@H_301_43@37
"update ItemInfo set name ='haha' where Type =1;"
@H_301_43@38
@H_301_43@39
);
@H_301_43@40
returni > 0;
@H_301_43@41
@H_301_43@42
@H_301_43@43
@H_301_43@44
@H_301_43@45
}
@H_301_43@46
}

猜你在找的Sqlite相关文章