简体   繁体   English

使用Unity3d连接到MySQL服务器吗?

[英]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. 我正在尝试创建一个Android游戏,该游戏需要发送信息以存储在远程数据库中。 The MySQL database is stored on my university's server, which I usually access through SSH. MySQL数据库存储在我大学的服务器上,我通常通过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#). 我现在想做的是使用ODBC连接到数据库,但是我很难让它与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. Unity Wiki使用PHP,MySql和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. 推荐的解决方案不是直接将您的应用程序与数据库连接,而是通过API或后端服务层来实现。

One of the simplest approaches is to use Parse.com , which is free if your traffic is not very large. 最简单的方法之一是使用Parse.com ,如果流量不是很大,则可以免费使用。

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. 另一个类似的云存储或服务可能是Firebase ,它提供了基于JSON的API供您读取/写入自己的数据。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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