2
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
|
3 using System;
|
|
4 using System.Runtime.Serialization.Formatters.Binary;
|
|
5 using System.IO;
|
|
6 public class ConvertObject : MonoBehaviour {
|
|
7
|
|
8 public static byte[] Convert (object target) {
|
|
9 BinaryFormatter bf = new BinaryFormatter();
|
|
10 using (var ms = new MemoryStream())
|
|
11 {
|
|
12 bf.Serialize(ms, target);
|
|
13 return ms.ToArray();
|
|
14 }
|
|
15 }
|
|
16
|
|
17 public static object UnConvert(byte[] target) {
|
|
18 using (var memStream = new MemoryStream())
|
|
19 {
|
|
20 var binForm = new BinaryFormatter();
|
|
21 memStream.Write(target, 0, target.Length);
|
|
22 memStream.Seek(0, SeekOrigin.Begin);
|
|
23 return binForm.Deserialize(memStream) as object;
|
|
24 }
|
|
25 }
|
|
26 }
|