Unity3d 读取 Sqlite数据库

首先需要一个sqlite的DLL文件,在Unity安装目录可以找到。

@H_502_3@

http://download.csdn.net/detail/cp790621656/8017075
@H_502_3@ @H_502_3@

@H_502_3@

代码如下:

using UnityEngine;
using System.Collections;
using Mono.Data.sqlite;
using System;

public class Helper : MonoBehavIoUr {

	private sqliteConnection msqliteConnection;
	private sqliteCommand msqliteCommand;
	private sqliteDataReader msqliteDataReader;

	// Use this for initialization
	void Start () {

		//打开数据库
		try
		{
			string dbpath=Application.dataPath+"/game.db";
			msqliteConnection = new sqliteConnection("URI=file:"+dbpath);
			msqliteConnection.open();
		}
		catch(Exception e)
		{
			Debug.Log(e.ToString());
		}

		//查询一个数据
		string sqlquerystr = "select * from type_skill_attribute where id < 30";
		msqliteCommand = msqliteConnection.CreateCommand ();
		msqliteCommand.CommandText = sqlquerystr;
		msqliteDataReader = msqliteCommand.ExecuteReader ();

		while(msqliteDataReader.Read())
		{
			int customid=msqliteDataReader.Getordinal("skill_id"); //获取列ID,从0开始
			Debug.Log("customid = "+customid);
			int skill_id=msqliteDataReader.GetInt32(customid);

			customid=msqliteDataReader.Getordinal("type");
			Debug.Log("customid = "+customid);
			string type=msqliteDataReader.GetString(customid);

			Debug.Log("skill_id = "+skill_id+" type = "+type);
		}

		msqliteDataReader.Close ();
		if(msqliteCommand!=null)
		{
			msqliteCommand.dispose ();
		}
		if(msqliteConnection!=null)
		{
			msqliteConnection.Close ();
            msqliteConnection = null;
		}
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
挂载到Camera上就可以。

相关文章

前言 本文记录unity3D开发环境的搭建 unity安装 unity有中文...
前言 有时候我们希望公告牌跟随镜头旋转永远平行面向屏幕,同...
前言 经过一段时间的学习与实际开发,unity3D也勉强算是强行...
前言 在unity中我们常用的获取鼠标点击的方法有: 1、在3D场...
前言 在之前的例子中,我们都没有用到unity的精髓,例如地形...
这篇文章将为大家详细讲解有关Unity3D中如何通过Animator动画...