public void SetObjectData(UnitySerializationInfo info) { var cnt = info.GetInt32("count"); _elementType = TypeUtil.ParseType(info.GetString("assembly"), info.GetString("type")); _isArray = info.GetBoolean("isArray"); if (_isArray) { var arr = System.Array.CreateInstance(_elementType, cnt); for (int i = 0; i < cnt; i++) { arr.SetValue(info.GetValue("element" + i.ToString(), _elementType), i); } _lst = arr as System.Collections.IList; } else { var lstType = typeof(List <>); var genLstType = lstType.MakeGenericType(_elementType); var lst = System.Activator.CreateInstance(genLstType) as System.Collections.IList; for (int i = 0; i < cnt; i++) { lst.Add(info.GetValue("element" + i.ToString(), _elementType)); } _lst = lst; } }
public void GetObjectData(UnitySerializationInfo info) { int cnt = (_lst != null) ? _lst.Count : 0; info.AddValue("count", cnt); info.AddValue("assembly", _elementType.Assembly.GetName().Name); info.AddValue("type", _elementType.FullName); info.AddValue("isArray", _isArray); for (int i = 0; i < cnt; i++) { info.AddValue("element" + i.ToString(), _lst[i], _elementType); } }