Unity3D使用SQLite

  • 怎么让移动设备使用SQLite
    1. 把Mono.Data.dll, Mono.Data.Sqlite,System.Data.dll放置Assets/Plugins目录下
    2. 把libsqlite3.0放置在Assets/Android目录下
  • 怎么在打包时将db文件放在合适的位置,然后在代码里怎么加载到合适的路径
    1. Android-->将db文件放置 Assets/Android/assets目录下
    2. IOS-->将db文件放置Assets/StreamingAssets目录下
  • 代码示例
    string localDBFullPath = "";
    string dbName = "";
    if(Application.platform == RuntimePlatfrom.WindowEditor || Application.platform == RuntimePlatform.OSXEidtor)
    {
      localDBFullPath = Application.dataPath + "Plugins/Android/assets/" + dbName;
    }
    else
    {
      if(Application.platform == Runtimeplatform.Android)
      {
        localDBFullPath = Application.persistentDataPath + "/" + dbName;
        if(!File.Exitst(localDBFullName))
        {
          WWW loadDB = new WWW("jar:file://"+Application.dataPath+"!/assets/"+dbName);
          while(!loadDB.isDone)
          {
          }
          File.WriteAllBytes(localDBFullPath, loadDB.bytes);
        }
      }
    }else
    {
      if(Application.platform == RuntimePlatform.IPhonePlayer)
      {
        localDBFullPath = Application.dataPath + "/Raw/"+dbName;
      }
    }
    

results matching ""

    No results matching ""