Mercurial > hg > Database > jungle-sharp
diff Main/ObjectMapper/ConvertObject.cs @ 20:1f99e150f336
fix folder and add Object Mapper.
author | Kazuma Takeda |
---|---|
date | Thu, 15 Dec 2016 22:52:48 +0900 |
parents | |
children | e954d456665c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Main/ObjectMapper/ConvertObject.cs Thu Dec 15 22:52:48 2016 +0900 @@ -0,0 +1,28 @@ +using UnityEngine; +using System.Collections; +using System; +using System.Runtime.Serialization.Formatters.Binary; +using System.Runtime.Serialization; +using System.IO; +[Serializable] +public class ConvertObject : MonoBehaviour { + + public static byte[] Convert (object target) { + IFormatter formatter = new BinaryFormatter(); + MemoryStream ms = new MemoryStream(); + formatter.Serialize(ms, target); + byte[] myByteArray = ms.ToArray(); + return myByteArray; + } + + public static object UnConvert(byte[] target) { + using (var memStream = new MemoryStream()) + { + var binForm = new BinaryFormatter(); + memStream.Write(target, 0, target.Length); + memStream.Seek(0, SeekOrigin.Begin); + var obj = binForm.Deserialize(memStream); + return obj; + } + } +}