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);
                        }
                    }
                }
            }
        }
Example #2
0
 public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     ComponentSerializationUtility.SerializableComponent(component, ref info);
 }