I`m currently developing a videogame that needs to upload levels, records, and some other large data strunctures to a MySQL database . I parse those objects to an hex string and upload the data to my database througth a WWW post in Unity3D as varbinary.
object codedLevel = SaveGame.codedLevel;
byte[] codedLevelBin = ObjectToByteArray(codedLevel);
string codedLevelStr = "0x" + BitConverter.ToString (codedLevelBin).Replace("-", "");
Since the length of the url is limited in size, I have to split the hex string , upload it in parts and merge the parts again on download.
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
}
How I can upload all the object codedLevel from C# script in Unity3D¿
Thanks!