[Unity] SQLite가 안드로이드에 발표하면서 생긴 구덩이들.

Android에 게시하려면 libsqlite3.so 파일, 해당 Mono.Data.Sqlite.dll、sqlite3.dll、System.Data.dll 라이브러리 주의: 모든 파일을 Plugins 폴더에 두고libsqlite3.so Android 폴더 아래 놓기
*Player Setting에 있는 (안드로이드 옵션 중) Other Settings에 Optimization 아래에 있는 API Compatbility Level 선택이 있습니다.NET 2.0(그렇지 않으면 System.Data.dll 포장에 실패하는 상황이 발생할 수 있다. 왜 그런지 나도 모르겠다. 연구해 본 적이 없다. 외국의 대신에게서 알게 되었다...)
using UnityEngine;
using System.Collections;
using Mono.Data.Sqlite;
using UnityEngine.UI;
using System.IO;


public class AndroidLoadData : MonoBehaviour {

	private Text name;
	private Text score;

	// Use this for initialization
	void Start () {
		name = GameObject.Find ("name").GetComponent ();
		score = GameObject.Find ("score").GetComponent ();
		ConnectionDataBase ();
	}
	


	public void ConnectionDataBase()
	{
		// 【    】
		string  sandboxPath = Application.persistentDataPath + "/Data0118.sqlite";

		// 【  www        】     unity   StreamingAssets       
		//    APK     ,       
		string downPath = "jar:file://" + Application.dataPath + "!/assets" + "/Data0118.sqlite";

		// 【   】               
		//      ,  StreamingAssets         
		if (!File.Exists(sandboxPath)) {

			Debug.Log ("    ,           Data0118.sqlite   ");

			//            ,       
			// 1.  sqlite  ,    ,       ,        
			// 2.       ,        ,         

			WWW www = new WWW (downPath);

			//           ,            
			while (!www.isDone) {
				
			}
			//  www         ,    sandboxPath   
			File.WriteAllBytes (sandboxPath, www.bytes);
		}

		//              
		string dataSandboxPath = "URI = file:" + Application.persistentDataPath + "/Data0118.sqlite";
		SqliteConnection con = new SqliteConnection (dataSandboxPath);

		//      
		con.Open ();


		//        
		SqliteCommand com = con.CreateCommand ();

		//           
		com.CommandText = "select name from MyTable where name = 'XiXi'";


		//        
		name.text = com.ExecuteScalar ().ToString();


		//         
		com.CommandText = "select score from MyTable where name = 'XiXi'";

		//        
		score.text = com.ExecuteScalar ().ToString ();

		//      
		con.Close ();

	}

}

좋은 웹페이지 즐겨찾기