2.Copy sqlite3.def and sqlite3.dll into Plugins folder in your unity project. Sqlite3.dll is needed to link dynamically to the sqlite. And sqlite3.def is needed to define what symbols (or functions) needed to link with program using sqlite. Unity plugins are available for select Play Core APIs, including Play Asset Delivery. Download the latest release from Google Play Plugins for Unity releases. This is a single package that includes Play Core plugins as well as other Play plugins, such as Play In-app Billing and Play Instant. SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. This package contains an extension SDK and all other components needed to use SQLite for UAP application development with Visual Studio 2015.
Using SQLite in Unity allows for full database access without having to send out external information or commands, as the database in stored with the game or app. This is not meant for secure information as anyone can open the database.
I haven’t tried any of this in BOLT yet but I will add to this post after I have tried it.
Steps to get setup
- Create a new folder under Assets called “Plugins” if there isn’t already one there.
- Download SQlite
- Copy “sqlite3.def” and “sqlite3.dll” into that Plugins folder you just created.
- Download an SQLite database manger program
- User the database manager program to create a new database in your projects “Assets” folder. (Make note of the full name of this database file)
- Copy “System.Data.dll” and “Mono.Data.Sqlite.dll” from your Unity install path + ” Unity EditorDataMonolibmono2.0 ” and paste them into the Plugins folder that you created.
If you are using Bolt in the project some of these files are already included and will give you an error in teh console until you remove the duplicate. Just delete the files mentioned as being duplicated in the console and everything will still work.
When used with Bolt.You are now ready to create the C# code to connect to the database. Here is an example.
- Replace “leaderboard.db” with the name of your database
- Edit “SELECT score_id, player_name, player_score ” + “FROM Leaderboard_Table” to reflect actual columns and tables from your database.
- Put this script on an active gameObject in your screen and the Console area should show you the information from your database.
If you are getting complaints about the Table not being found. Call of duty world at war mac free. Take a look at the name of your database and make sure it matches your code. My code said “Leaderboard.s3db” but my actual database was called “leaderboards.db”
SQLite creates a new empty database if it fails to find the one you specified in code, and that database will be completely empty, leading to the lack of finding a table.Inserting data into the database
This code is the same as above except the reading of data has been commented out and an INSERT command had been put in it’s place. Mirc registration bypass. This allows us to add information to the database.
Here are the data types for SQLite
SQLite is a convenient way of implementing a simple database in Unity. Rather than a full-blown client-server based implementation of SQL, SQLite uses a single local file to store the database, and provides access to that file via standard SQL commands.
Advantages of SQLite:
- Easy setup in Javascript
- Easy to view database structure and contents with the free SQLite Browser
- Maintains state over sessions (since it's a local file)
Disadvantages of SQLite:
- Since it's using a local file for the database, it is NOT possible to use it for Web Player applications
- It's a bit finicky to get set up with in C#
- (Advanced) It's doesn't guarantee domain integrity - not usually a problem, since Unity's single threaded nature makes it probably impossible to write two things at the same time, but you might have issues if you're trying to write to your database from a program outside of Unity at the same time.
So how do you set it up, and how do you start working with SQLite in Unity? For now, this guide only focuses on Javascript, since it's easier to set up. And as long as your database-access functions return acceptable types, you can access all the Javascript functions from C# or Boo so long as you put your database scripts in the 'Plugins' or 'Standard Assets' folder of your project, and don't try to access them by scripts that are earlier in the compiler order
|
JavaScript
Unity3d Sqlite
Here are the specific steps to getting SQLite set up in your project.
- Download SQLite - you'll want the ZIP file with the DLL inside that's in the Precompiled Binaries for Windows section.
- Important Copy sqlite3.dll into your into your project's Plugins folder (make a folder called Plugins if you don't have one).
- You won't get a warning if you don't do this, and your project will run fine in the editor, however, it will fail to work when you actually build your project, and will only provide information about this in the log file.
- This will give you a License Error if you're using Unity Indie, but it doesn't seem to have an effect on the actual play in the editor, nor does it seem to effect the ability to build stand-alone versions.
- Alternately, you can leave it out of your project entirely, but when you build your application, you'll need to include a copy of sqlite3.dll in the same directory as the .exe in order for it to work.
- In your project, add in the dbAccess.js file below.
- You should be good to go! An example using the database is also included - ScriptThatUsesTheDatabase.js - It is a GUI script, so attach it to your main camera.
- The commands run by the dbAccess class are IDbCommand commands, and those commands return an IDataReader object. For more information on using those interfaces, the references are here: IDbCommand and IDataReader
dbAccess.js
ScriptThatUsesTheDatabase.js
Troubleshooting
- Everything works fine in the editor, but when I make a build, my SQL stuff doesn't work.
- For whatever reason, the sqlite3.dll file needs to be in the Plugins directory of your project.