Mercurial > hg > Members > kazuma > JungleforUnity
view Assets/Application/Scripts/ConvertObject.cs @ 3:2dd40b4412e4
Create game base.
author | Kazuma |
---|---|
date | Mon, 07 Nov 2016 18:42:01 +0900 |
parents | ca28bf83fc89 |
children | 2878be4487ec |
line wrap: on
line source
using UnityEngine; using System.Collections; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO; public class ConvertObject : MonoBehaviour { public static byte[] Convert (object target) { BinaryFormatter bf = new BinaryFormatter(); using (var ms = new MemoryStream()) { bf.Serialize(ms, target); return ms.ToArray(); } } 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); return binForm.Deserialize(memStream) as object; } } }