public void Serialize(IUnityData data, object obj) { if (data == null) { throw new System.ArgumentNullException("data"); } if (obj == null) { throw new System.ArgumentNullException("obj"); } if (obj is UnityEngine.Object) { throw new System.ArgumentException("Can not serialize Unity Reference Objects directly.", "obj"); } var tp = obj.GetType(); if (!IsUnitySerializable(tp)) { throw new System.ArgumentException("Type of object is not serializable."); } if (obj != null) { _surrogate.StartSerialization(); using (var strm = new System.IO.MemoryStream()) { _formatter.Serialize(strm, obj); strm.Position = 0; //byte[] arr = new byte[strm.Length]; //strm.Read(arr, 0, arr.Length); data.SetData(strm, _surrogate.StopSerialization()); } } }