unity : messagepack

messagepack http://msgpack.org/

他の物はunsafeが利用出来なかったり、ビルド手順が必要だったので

https://github.com/masharada/msgpack-unity

こちらを利用させていただきます。

string test = "unity test";
MsgPack.ObjectPacker bp = new MsgPack.ObjectPacker ();
byte[] packed = bp.Pack (test);
// print binary
Debug.Log (Encoding.Unicode.GetString (packed));
string unpackedText = (string)bp.Unpack(packed);
// pring "unity test"
Debug.Log(unpackedText);

クラスとリスト
public class TestData{
public int score;
public string playerName;
public Dictionary myDict;
public TestData( int s, string n ){
score = s;
playerName = n;
myDict = new Dictionary();
myDict.Add("poteto","apple");
}
}

Dictionary test = new Dictionary ();
test.Add (1, new TestData( 999, "unity" ));
test.Add (2, new TestData( 777, "seven" ));
MsgPack.ObjectPacker bp = new MsgPack.ObjectPacker ();
byte[] packed = bp.Pack (test);
Dictionary unpacked = (Dictionary)bp.Unpack> (packed);
// pring "unity"
Debug.Log (unpacked[1].playerName);
Debug.Log (unpacked[1].myDict["poteto"]);

適当に動きました。

実際にはobjectPackerではなくboxingPackerを利用しました。

This entry was posted on 月曜日, 7月 28th, 2014 at 10:57 AM and is filed under unity. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。