存储和加载:
public void ConnectTosqlite (string dbname) { //判断名字是否规范,如果不规范就加上后缀 if (!dbname.Contains (".sqlite")) { dbname += ".sqlite"; } //如果运行在编辑器中 #if UNITY_EDITOR //获取路径 sqlitePath = "Data Source =" + Application.streamingAssetsPath + "/" + dbname; //实例连接对象 connection = new sqliteConnection (sqlitePath); //如果运行在Android设备中 #elif UNITY_ANDROID //数据库连接的字符串 string connectionStr = "URI = file:" + Application.persistentDataPath + "/" + dbname; //Android APK中数据库文件的路径 string androidpath = "jar:file://" + Application.dataPath + "!/assets/" + dbname; //Android沙盒路径 string androidFilePath = Application.persistentDataPath + "/" + dbname; //如果Android项目源文件中不存在数据库文件,说明没有加载过,需要加载 if(!File.Exists(androidFilePath)) { //从APK路径拿到sqlite数据库文件,下载 WWW www = new WWW(androidpath); //下载未完成时,保持等待 while(!www.isDone){} //下载完成,IO流写入到沙盒路径 File.WriteallBytes(androidFilePath, www.bytes); } //实例连接对象 connection = new sqliteConnection(connectionStr); #endif //创建数据库命令对象 command = connection.CreateCommand (); try { //打开数据库 connection.Open (); } catch (System.Exception ex) { //输出报错信息 print (ex); } }
原文地址:https://www.jb51.cc/android/1053185.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。