public void OnDeserialize(SerializationInfo info, StreamingContext context, IAssetBundle assetBundle) { _persistenceUid = new PersistentUid(info.GetString("uid")); _uidSet = true; this.transform.position = (Vector3)info.GetValue("pos", typeof(Vector3)); this.transform.rotation = (Quaternion)info.GetValue("rot", typeof(Quaternion)); this.transform.localScale = (Vector3)info.GetValue("scale", typeof(Vector3)); SerializationInfoEnumerator e = info.GetEnumerator(); while (e.MoveNext()) { Type componentType = TypeUtil.FindType(e.Name, true); if (componentType == null) { continue; } Component component = this.GetComponent(componentType); if (component == null) { continue; } SerializableComponent serializedComponent = (SerializableComponent)e.Value; ComponentSerializationUtility.DeserializeComponent(ref component, serializedComponent.DeserializeInfo); } int cnt = info.GetInt32("count"); if (cnt > 0) { var lst = new List <IPersistentUnityObject>(); this.GetComponentsInChildren <IPersistentUnityObject>(true, lst); for (int i = 0; i < cnt; i++) { ChildObjectData data = (ChildObjectData)info.GetValue(i.ToString(), typeof(ChildObjectData)); if (data != null && data.ComponentType != null) { IPersistentUnityObject pobj = (from o in lst where o.Uid == data.Uid select o).FirstOrDefault(); if (pobj != null) { pobj.OnDeserialize(data.DeserializeInfo, data.DeserializeContext, assetBundle); } } } } }
public void OnSerialize(SerializationInfo info, StreamingContext context) { info.AddValue("uid", this.Uid.Value); if (_linkedPrefabUid != null) { info.AddValue("linkedPrefabUid", _linkedPrefabUid.ToString()); } else { info.AddValue("linkedPrefabUid", ""); } info.AddValue("pos", this.transform.position); info.AddValue("rot", this.transform.rotation); info.AddValue("scale", this.transform.localScale); Component[] components = _serializeAllComponents ? GetComponents <Component>() : _componentsToSerialize; foreach (Component component in components) { var data = new SerializableComponent(component); info.AddValue(component.GetType().FullName, data, component.GetType()); } var lst = new List <IPersistentUnityObject>(); this.GetComponentsInChildren <IPersistentUnityObject>(true, lst); if (lst.Count > 0) { var data = new ChildObjectData(); int cnt = 0; for (int i = 0; i < lst.Count; i++) { if (object.ReferenceEquals(this, lst[i])) { continue; } data.Uid = lst[i].Uid; data.ComponentType = lst[i].GetType(); data.Pobj = lst[i]; info.AddValue(cnt.ToString(), data, typeof(ChildObjectData)); cnt++; } info.AddValue("count", cnt); } }