【发布时间】:2016-07-18 14:35:26
【问题描述】:
我目前正在开发一款需要将关卡、记录和其他一些大型数据结构上传到 MySQL 数据库的视频游戏。我将这些对象解析为十六进制字符串,然后通过 Unity3D 中的 WWW 帖子将数据作为 varbinary 上传到我的数据库。
object codedLevel = SaveGame.codedLevel;
byte[] codedLevelBin = ObjectToByteArray(codedLevel);
string codedLevelStr = "0x" + BitConverter.ToString (codedLevelBin).Replace("-", "");
由于url的长度有限,我必须将十六进制字符串拆分,分段上传,下载时再次合并。
int partSize = 2000;
for( int i= 0; i <= codedLevelStr.Length ;i = i+partSize){
string part = "";
if (codedLevelStr.Length - i > partSize)
part = codedLevelStr.Substring (i, partSize);
else if (codedLevelStr.Length < partSize)
part = codedLevelStr;
else
part = codedLevelStr.Substring (i);
codedLevelLengthParts = codedLevelLengthParts + part.Length;
//This connects to a server side php script that will add the level to a MySQL DB.
// Supply it with a string representing the level
string hash = Md5Sum(User + part+ i + LVLName + secretKey);
string post_url = addLevelURL+ "&LVL=" + part + "&name=" + WWW.EscapeURL(User) + "&part=" + i/partSize + "&LVLName=" + WWW.EscapeURL(LVLName) + "&hash=" + hash;
// Post the URL to the site and create a download object to get the result.
WWW hs_post = new WWW(post_url);
yield return hs_post; // Wait until the download is do
}
如何在 Unity3D 中从 C# 脚本上传所有 codedLevel 对象¿
谢谢!
【问题讨论】: