public override void ReadInto(ES3Reader reader, object obj) { var collection = (IList)obj; if (collection.Count == 0) { ES3Debug.LogWarning("LoadInto/ReadInto expects a collection containing instances to load data in to, but the collection is empty."); } if (reader.StartReadCollection()) { throw new NullReferenceException("The Collection we are trying to load is stored as null, which is not allowed when using ReadInto methods."); } int itemsLoaded = 0; // Iterate through each item in the collection and try to load it. foreach (var item in collection) { itemsLoaded++; if (!reader.StartReadCollectionItem()) { break; } reader.ReadInto <object>(item, elementType); // If we find a ']', we reached the end of the array. if (reader.EndReadCollectionItem()) { break; } // If there's still items to load, but we've reached the end of the collection we're loading into, throw an error. if (itemsLoaded == collection.Count) { throw new IndexOutOfRangeException("The collection we are loading is longer than the collection provided as a parameter."); } } // If we loaded fewer items than the parameter collection, throw index out of range exception. if (itemsLoaded != collection.Count) { throw new IndexOutOfRangeException("The collection we are loading is shorter than the collection provided as a parameter."); } reader.EndReadCollection(); }
public override void ReadInto(ES3Reader reader, object obj) { var array = (Array)obj; if (reader.StartReadCollection()) { throw new NullReferenceException("The Collection we are trying to load is stored as null, which is not allowed when using ReadInto methods."); } bool iHasBeenRead = false; for (int i = 0; i < array.GetLength(0); i++) { bool jHasBeenRead = false; if (!reader.StartReadCollectionItem()) { throw new IndexOutOfRangeException("The collection we are loading is smaller than the collection provided as a parameter."); } reader.StartReadCollection(); for (int j = 0; j < array.GetLength(1); j++) { if (!reader.StartReadCollectionItem()) { throw new IndexOutOfRangeException("The collection we are loading is smaller than the collection provided as a parameter."); } reader.ReadInto <object>(array.GetValue(i, j), elementType); jHasBeenRead = reader.EndReadCollectionItem(); } if (!jHasBeenRead) { throw new IndexOutOfRangeException("The collection we are loading is larger than the collection provided as a parameter."); } reader.EndReadCollection(); iHasBeenRead = reader.EndReadCollectionItem(); } if (!iHasBeenRead) { throw new IndexOutOfRangeException("The collection we are loading is larger than the collection provided as a parameter."); } reader.EndReadCollection(); }
public override void ReadInto <T>(ES3Reader reader, object obj) { if (reader.StartReadCollection()) { throw new NullReferenceException("The Collection we are trying to load is stored as null, which is not allowed when using ReadInto methods."); } int itemsLoaded = 0; var stack = (Stack <T>)obj; // Iterate through each item in the collection and try to load it. foreach (var item in stack) { itemsLoaded++; if (!reader.StartReadCollectionItem()) { break; } reader.ReadInto <T>(item, elementType); // If we find a ']', we reached the end of the array. if (reader.EndReadCollectionItem()) { break; } // If there's still items to load, but we've reached the end of the collection we're loading into, throw an error. if (itemsLoaded == stack.Count) { throw new IndexOutOfRangeException("The collection we are loading is longer than the collection provided as a parameter."); } } // If we loaded fewer items than the parameter collection, throw index out of range exception. if (itemsLoaded != stack.Count) { throw new IndexOutOfRangeException("The collection we are loading is shorter than the collection provided as a parameter."); } reader.EndReadCollection(); }
public void ReadInto(ES3Reader reader, object obj) { if (reader.StartReadDictionary()) { throw new NullReferenceException("The Dictionary we are trying to load is stored as null, which is not allowed when using ReadInto methods."); } var dict = (IDictionary)obj; // Iterate through each character until we reach the end of the array. while (true) { if (!reader.StartReadDictionaryKey()) { return; } var key = reader.Read <object>(keyType); if (!dict.Contains(key)) { throw new KeyNotFoundException("The key \"" + key + "\" in the Dictionary we are loading does not exist in the Dictionary we are loading into"); } var value = dict[key]; reader.EndReadDictionaryKey(); reader.StartReadDictionaryValue(); reader.ReadInto <object>(value, valueType); if (reader.EndReadDictionaryValue()) { break; } } reader.EndReadDictionary(); }
protected override void ReadComponent <T>(ES3Reader reader, object obj) { var instance = (UnityEngine.ParticleSystem)obj; // Pause particle system as some properties require it to not be playing to be set. instance.Pause(); foreach (string propertyName in reader.Properties) { switch (propertyName) { case "time": instance.time = reader.Read <System.Single>(); break; case "hideFlags": instance.hideFlags = reader.Read <UnityEngine.HideFlags>(); break; case "collision": reader.ReadInto <UnityEngine.ParticleSystem.CollisionModule>(instance.collision, ES3Type_CollisionModule.Instance); break; case "colorBySpeed": reader.ReadInto <UnityEngine.ParticleSystem.ColorBySpeedModule>(instance.colorBySpeed, ES3Type_ColorBySpeedModule.Instance); break; case "colorOverLifetime": reader.ReadInto <UnityEngine.ParticleSystem.ColorOverLifetimeModule>(instance.colorOverLifetime, ES3Type_ColorOverLifetimeModule.Instance); break; case "emission": reader.ReadInto <UnityEngine.ParticleSystem.EmissionModule>(instance.emission, ES3Type_EmissionModule.Instance); break; case "externalForces": reader.ReadInto <UnityEngine.ParticleSystem.ExternalForcesModule>(instance.externalForces, ES3Type_ExternalForcesModule.Instance); break; case "forceOverLifetime": reader.ReadInto <UnityEngine.ParticleSystem.ForceOverLifetimeModule>(instance.forceOverLifetime, ES3Type_ForceOverLifetimeModule.Instance); break; case "inheritVelocity": reader.ReadInto <UnityEngine.ParticleSystem.InheritVelocityModule>(instance.inheritVelocity, ES3Type_InheritVelocityModule.Instance); break; case "lights": reader.ReadInto <UnityEngine.ParticleSystem.LightsModule>(instance.lights, ES3Type_LightsModule.Instance); break; case "limitVelocityOverLifetime": reader.ReadInto <UnityEngine.ParticleSystem.LimitVelocityOverLifetimeModule>(instance.limitVelocityOverLifetime, ES3Type_LimitVelocityOverLifetimeModule.Instance); break; case "main": reader.ReadInto <UnityEngine.ParticleSystem.MainModule>(instance.main, ES3Type_MainModule.Instance); break; case "noise": reader.ReadInto <UnityEngine.ParticleSystem.NoiseModule>(instance.noise, ES3Type_NoiseModule.Instance); break; case "rotationBySpeed": reader.ReadInto <UnityEngine.ParticleSystem.RotationBySpeedModule>(instance.rotationBySpeed, ES3Type_RotationBySpeedModule.Instance); break; case "rotationOverLifetime": reader.ReadInto <UnityEngine.ParticleSystem.RotationOverLifetimeModule>(instance.rotationOverLifetime, ES3Type_RotationOverLifetimeModule.Instance); break; case "subEmitters": reader.ReadInto <UnityEngine.ParticleSystem.SubEmittersModule>(instance.subEmitters, ES3Type_SubEmittersModule.Instance); break; case "textureSheetAnimation": reader.ReadInto <UnityEngine.ParticleSystem.TextureSheetAnimationModule>(instance.textureSheetAnimation, ES3Type_TextureSheetAnimationModule.Instance); break; case "trails": reader.ReadInto <UnityEngine.ParticleSystem.TrailModule>(instance.trails, ES3Type_TrailModule.Instance); break; case "trigger": reader.ReadInto <UnityEngine.ParticleSystem.TriggerModule>(instance.trigger, ES3Type_TriggerModule.Instance); break; case "useAutoRandomSeed": instance.useAutoRandomSeed = reader.Read <bool>(ES3Type_bool.Instance); break; case "velocityOverLifetime": reader.ReadInto <UnityEngine.ParticleSystem.VelocityOverLifetimeModule>(instance.velocityOverLifetime, ES3Type_VelocityOverLifetimeModule.Instance); break; case "isPaused": if (reader.Read <bool>(ES3Type_bool.Instance)) { instance.Pause(); } break; case "isPlaying": if (reader.Read <bool>(ES3Type_bool.Instance)) { instance.Play(); } break; case "isStopped": if (reader.Read <bool>(ES3Type_bool.Instance)) { instance.Stop(); } break; default: reader.Skip(); break; } } }
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.ReadInto <GameObject>(obj); // ReadInto to apply the prefab references. } else { obj = reader.Read <GameObject>(ES3Type_ES3PrefabInternal.Instance); ES3ReferenceMgrBase.Current.Add(obj, id); } } else if (propertyName == null) { /*if (obj == null) * obj = CreateNewGameObject(refMgr, id);*/ return(obj); } else { reader.overridePropertiesName = propertyName; break; } } if (obj == null) { obj = CreateNewGameObject(refMgr, id); } ReadInto <T>(reader, obj); return(obj); }