protected override object ReadUnityObject <T>(ES3Reader reader) { var refMgr = ES3ReferenceMgrBase.Current; long id = -1; UnityEngine.Object instance = null; foreach (string propertyName in reader.Properties) { if (propertyName == ES3ReferenceMgrBase.referencePropertyName) { id = reader.Read_ref(); instance = refMgr.Get(id); if (instance != null) { break; } } else if (propertyName == gameObjectPropertyName) { long goID = reader.Read_ref(); var go = (GameObject)refMgr.Get(goID); if (go == null) { go = new GameObject("Easy Save 3 Loaded GameObject"); #if UNITY_EDITOR go.AddComponent <ES3InspectorInfo>().SetMessage("This GameObject was created because Easy Save could not find a GameObject in the scene with the same instance ID as the GameObject the Component we are loading is attached to.\nTo prevent this from being created, use the LoadInto methods to tell Easy Save what Component the data should be loaded in to."); #endif refMgr.Add(go, goID); } instance = GetOrAddComponent(go, type); refMgr.Add(instance, id); break; } else { reader.overridePropertiesName = propertyName; if (instance == null) { var go = new GameObject("Easy Save 3 Loaded GameObject"); #if UNITY_EDITOR go.AddComponent <ES3InspectorInfo>().SetMessage("This GameObject was created because Easy Save could not find a GameObject in the scene with the same instance ID as the GameObject the Component we are loading is attached to.\nTo prevent this from being created, use the LoadInto methods to tell Easy Save what Component the data should be loaded in to."); #endif instance = GetOrAddComponent(go, type); if (refMgr != null) { refMgr.Add(go); refMgr.Add(instance, id); } } break; } } ReadComponent <T>(reader, instance); return(instance); }
protected override object ReadUnityObject <T>(ES3Reader reader) { var refMgr = ES3ReferenceMgrBase.Current; long id = -1; UnityEngine.Object instance = null; foreach (string propertyName in reader.Properties) { if (propertyName == ES3ReferenceMgrBase.referencePropertyName && refMgr != null) { id = reader.Read_ref(); instance = refMgr.Get(id); if (instance != null) { break; } } else { reader.overridePropertiesName = propertyName; if (instance == null) { instance = ScriptableObject.CreateInstance(type); refMgr.Add(instance, id); } break; } } ReadScriptableObject <T>(reader, instance); return(instance); }
protected override void ReadObject <T>(ES3Reader reader, object obj) { var instance = (UnityEngine.GameObject)obj; foreach (string propertyName in reader.Properties) { switch (propertyName) { case ES3ReferenceMgrBase.referencePropertyName: ES3ReferenceMgr.Current.Add(instance, reader.Read_ref()); break; case "prefab": break; case "layer": instance.layer = reader.Read <System.Int32>(ES3Type_int.Instance); break; case "tag": instance.tag = reader.Read <System.String>(ES3Type_string.Instance); break; case "name": instance.name = reader.Read <System.String>(ES3Type_string.Instance); break; case "hideFlags": instance.hideFlags = reader.Read <UnityEngine.HideFlags>(); break; case "active": instance.SetActive(reader.Read <bool>(ES3Type_bool.Instance)); break; case "children": reader.Read <GameObject[]>(); break; case "components": reader.Read <Component[]>(); break; default: reader.Skip(); break; } } }
protected override object ReadObject <T>(ES3Reader reader) { var refMgr = ES3ReferenceMgrBase.Current; if (refMgr == null) { return(ReadUnityObject <T>(reader)); } long id = -1; UnityEngine.Object instance = null; foreach (string propertyName in reader.Properties) { if (propertyName == ES3ReferenceMgrBase.referencePropertyName) { if (refMgr == null) { throw new InvalidOperationException("An Easy Save 3 Manager is required to load references. To add one to your scene, exit playmode and go to Assets > Easy Save 3 > Add Manager to Scene"); } id = reader.Read_ref(); instance = refMgr.Get(id, type); if (instance != null) { break; } } else { reader.overridePropertiesName = propertyName; if (instance == null) { instance = (UnityEngine.Object)ReadUnityObject <T>(reader); refMgr.Add(instance, id); } break; } } ReadUnityObject <T>(reader, instance); return(instance); }
public override object Read <T>(ES3Reader reader) { if (members == null) { GetMembers(reader.settings.safeReflection); } object obj; string propertyName = reader.ReadPropertyName(); // If we're loading a derived type, use it's specific ES3Type. if (propertyName == ES3Type.typeFieldName) { return(ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).Read <T>(reader)); } // If we're loading a reference, load it. Else, create an instance. if (propertyName == ES3ReferenceMgrBase.referencePropertyName) { long id = reader.Read_ref(); obj = ES3ReferenceMgrBase.Current.Get(id, type); if (obj == null) { // If an instance isn't already registered for this object, create an instance and register the reference. obj = ES3Reflection.CreateInstance(this.type); ES3ReferenceMgrBase.Current.Add((UnityEngine.Object)obj, id); } } else { reader.overridePropertiesName = propertyName; obj = ES3Reflection.CreateInstance(this.type); } // Iterate through each property in the file and try to load it using the appropriate // ES3Property in the members array. ReadProperties(reader, obj); return(obj); }
protected override void ReadObject <T>(ES3Reader reader, object obj) { var refMgr = ES3ReferenceMgrBase.Current; if (refMgr != null) { foreach (string propertyName in reader.Properties) { if (propertyName == ES3ReferenceMgrBase.referencePropertyName) { // If the object we're loading into isn't registered with the reference manager, register it. refMgr.Add((UnityEngine.Object)obj, reader.Read_ref()); } else { reader.overridePropertiesName = propertyName; break; } } } ReadUnityObject <T>(reader, obj); }
protected override object ReadObject <T>(ES3Reader reader) { UnityEngine.Object obj = null; var refMgr = ES3ReferenceMgrBase.Current; long id = 0; // Read the intial properties regarding the instance we're loading. while (true) { if (refMgr == null) { throw new InvalidOperationException("An Easy Save 3 Manager is required to load references. To add one to your scene, exit playmode and go to Assets > Easy Save 3 > Add Manager to Scene"); } var propertyName = ReadPropertyName(reader); if (propertyName == ES3Type.typeFieldName) { return(ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).Read <T>(reader)); } else if (propertyName == ES3ReferenceMgrBase.referencePropertyName) { id = reader.Read_ref(); obj = refMgr.Get(id, true); } else if (propertyName == transformPropertyName) { // Now load the Transform's ID and assign it to the Transform of our object. long transformID = reader.Read_ref(); if (obj == null) { obj = CreateNewGameObject(refMgr, id); } refMgr.Add(((GameObject)obj).transform, transformID); } else if (propertyName == prefabPropertyName) { if (obj != null || ES3ReferenceMgrBase.Current == null) { reader.Skip(); } else { obj = reader.Read <GameObject>(ES3Type_ES3PrefabInternal.Instance); ES3ReferenceMgrBase.Current.Add(obj, id); } } else if (propertyName == null) { if (obj == null) { return(CreateNewGameObject(refMgr, id)); } return(obj); } else { reader.overridePropertiesName = propertyName; break; } } if (obj == null) { obj = CreateNewGameObject(refMgr, id); } ReadInto <T>(reader, obj); return(obj); }
private void ReadComponents(ES3Reader reader, GameObject go) { if (reader.StartReadCollection()) { return; } var components = new List <Component>(go.GetComponents <Component>()); // Read each Component in Components array while (true) { if (!reader.StartReadCollectionItem()) { break; } if (reader.StartReadObject()) { return; } Type type = null; string propertyName; while (true) { propertyName = ReadPropertyName(reader); if (propertyName == ES3Type.typeFieldName) { type = reader.ReadType(); } else if (propertyName == ES3ReferenceMgrBase.referencePropertyName) { if (type == null) { throw new InvalidOperationException("Cannot load Component because no type data has been stored with it, so it's not possible to determine it's type"); } var componentRef = reader.Read_ref(); // Rather than loading by reference, load using the Components list. var c = components.Find(x => x.GetType() == type); // If the Component exists in the Component list, load into it and remove it from the list. if (c != null) { if (ES3ReferenceMgrBase.Current != null) { ES3ReferenceMgrBase.Current.Add(c, componentRef); } ES3TypeMgr.GetOrCreateES3Type(type).ReadInto <Component>(reader, c); components.Remove(c); } // Else, create a new Component. else { var component = ES3TypeMgr.GetOrCreateES3Type(type).Read <Component>(reader); if (component != null) { ES3ReferenceMgrBase.Current.Add((Component)component, componentRef); } } break; } else if (propertyName == null) { break; } else { reader.overridePropertiesName = propertyName; ReadObject <Component>(reader); break; } } reader.EndReadObject(); if (reader.EndReadCollectionItem()) { break; } } reader.EndReadCollection(); }
protected override object ReadObject <T>(ES3Reader reader) { UnityEngine.Object obj = null; var refMgr = ES3ReferenceMgrBase.Current; long id = 0; // Read the intial properties regarding the instance we're loading. while (true) { if (refMgr == null) { reader.Skip(); continue; } var propertyName = ReadPropertyName(reader); if (propertyName == ES3Type.typeFieldName) { return(ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).Read <T>(reader)); } else if (propertyName == ES3ReferenceMgrBase.referencePropertyName) { if (refMgr == null) { reader.Skip(); continue; } id = reader.Read_ref(); obj = refMgr.Get(id, true); } else if (propertyName == transformPropertyName) { if (refMgr == null) { reader.Skip(); continue; } // Now load the Transform's ID and assign it to the Transform of our object. long transformID = reader.Read_ref(); if (obj == null) { obj = CreateNewGameObject(refMgr, id); } refMgr.Add(((GameObject)obj).transform, transformID); } else if (propertyName == prefabPropertyName) { if (obj != null || ES3ReferenceMgrBase.Current == null) { reader.Skip(); } else { obj = reader.Read <GameObject>(ES3Type_ES3PrefabInternal.Instance); ES3ReferenceMgrBase.Current.Add(obj, id); } } else if (propertyName == null) { if (obj == null) { return(CreateNewGameObject(refMgr, id)); } return(obj); } else { reader.overridePropertiesName = propertyName; break; } } if (obj == null) { obj = CreateNewGameObject(refMgr, id); } ReadInto <T>(reader, obj); return(obj); }
public override object Read <T>(ES3Reader reader) { return((T)(object)new ES3Ref(reader.Read_ref())); }