简体   繁体   中英

Connecting to MySQL server with Unity3d?

I am trying to create an Android game that needs to send information to be stored in a remote database. The MySQL database is stored on my university's server, which I usually access through SSH. What I'm trying to do right now is to use ODBC to connect to the database, but I am having trouble getting it to interact with Unity3d (C#). If anybody has experience with this, I would appreciate any help or direction to get my past this hurdle!

Unity Wiki have defined a complete procedure ( Server side high score ) with PHP, MySql and C#/JavaScript. Hope this will solve your problem.

The recommended solution is not directly connecting your app with the DB, but to implement that via some layer of API or backend service.

One of the simplest approaches is to use Parse.com , which is free if your traffic is not very large.

Example code:

ParseObject gameScore = new ParseObject("GameScore");
gameScore["score"] = 1337;
gameScore["playerName"] = "Sean Plott";
Task saveTask = gameScore.SaveAsync();

Another similiar cloud storage or service might be Firebase , which offers JSON based API for you to read/write your own data. Example usage:

public class Item
{
    public Guid Id { get; set; }
    public string Name { get; set; }  
    public string Value { get; set; }
}

var data = new Item(...); // or List<Item>() whatever
var str_data= JsonConvert.SerializeObject<Item>(data);
Firebase fb = new Firebase(new Uri("https://abcdefg.firebaseio.com/"));

//Write
string path = "/path";    // where to keep data in firebase
string id = fb.Post(path, data);

//Read back
string jsonData = fb.Get(path); 
var data2 = JsonConvert.DeserializeObject<Item>(jsonData);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM