1
我目前正在開發一個視頻遊戲,需要將級別,記錄和一些其他大數據結構上傳到MySQL數據庫。我將這些對象解析爲一個十六進制字符串,然後將數據通過Unity3D中的WWW作爲varbinary上傳到我的數據庫。Unity3d MYSQL大對象上傳
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
}
如何上傳所有的對象codedLevel從C#腳本Unity3D¿
謝謝!
非常感謝!!!!!! 10/10 – Charles
@Charles歡迎您! – Programmer