前端之家收集整理的这篇文章主要介绍了
Unity3D如何使用Sqlite数据库,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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:
@H_301_43@01
using UnityEngine; |
@H_301_43@02
using System.Collections; |
@H_301_43@03
using System.Collections.Generic; |
@H_301_43@04
using System; |
@H_301_43@05
using System.Data; |
@H_301_43@06
using Mono.Data.sqliteClient; |
@H_301_43@07
using System.Text; |
@H_301_43@08
using System.IO; |
@H_301_43@10
public class DBHelp : MonoBehavIoUr { |
@H_301_43@11
static string conn= string .Empty; |
@H_301_43@14
public static string getConstr() |
@H_301_43@18
#ifUNITY_EDITOR |
@H_301_43@19
conn = "URI=file:" + Application.dataPath + "/StreamingAssets/KLandNG.db" ; |
@H_301_43@23
#elifUNITY_ANDROID |
@H_301_43@26
conn = "URI=file:" + Application.persistentDataPath + "/" + "daniya.db" ; |
@H_301_43@34
public static bool UpdateScoll() |
@H_301_43@36
int i = sqliteHelper.ExecuteNonQuery(getConstr(),CommandType.Text, |
@H_301_43@37
"update ItemInfo set name ='haha' where Type =1;" |
@H_301_43@40
return i > 0; |