Beispiel #1
0
        public override void ReadInto <T>(ES3Reader reader, object obj)
        {
            string propertyName;

            while (true)
            {
                propertyName = ReadPropertyName(reader);

                if (propertyName == ES3Type.typeFieldName)
                {
                    ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).ReadInto <T>(reader, obj);
                    return;
                }
                // This is important we return if the enumerator returns null, otherwise we will encounter an endless cycle.
                else if (propertyName == null)
                {
                    return;
                }
                else
                {
                    reader.overridePropertiesName = propertyName;
                    ReadObject <T>(reader, obj);
                }
            }
        }
Beispiel #2
0
        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 <long>(ES3Type_long.Instance);
                obj = ES3ReferenceMgrBase.Current.Get(id);
                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);
        }
Beispiel #3
0
        public override object Read <T>(ES3Reader reader)
        {
            string propertyName;

            while (true)
            {
                propertyName = ReadPropertyName(reader);

                if (propertyName == ES3Type.typeFieldName)
                {
                    return(ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).Read <T>(reader));
                }
                else if (propertyName == null)
                {
                    return(null);
                }
                else
                {
                    reader.overridePropertiesName = propertyName;
                    return(ReadObject <T>(reader));
                }
            }
        }
Beispiel #4
0
        public override void ReadInto <T>(ES3Reader reader, object obj)
        {
            string propertyName;

            while (true)
            {
                propertyName = ReadPropertyName(reader);

                if (propertyName == ES3Type.typeFieldName)
                {
                    ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).ReadInto <T>(reader, obj);
                    return;
                }
                else if (propertyName == null)
                {
                    return;
                }
                else
                {
                    reader.overridePropertiesName = propertyName;
                    ReadObject <T>(reader, obj);
                }
            }
        }
Beispiel #5
0
        public override void ReadInto <T>(ES3Reader reader, object obj)
        {
            if (members == null)
            {
                GetMembers(reader.settings.safeReflection);
            }

            string propertyName = reader.ReadPropertyName();

            // If we're loading a derived type, use it's specific ES3Type.
            if (propertyName == ES3Type.typeFieldName)
            {
                ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).ReadInto <T>(reader, obj);
                return;
            }
            else
            {
                reader.overridePropertiesName = propertyName;
            }

            // Iterate through each property in the file and try to load it using the appropriate
            // ES3Property in the members array.
            ReadProperties(reader, obj);
        }
Beispiel #6
0
 protected void ReadUsingDerivedType <T>(ES3Reader reader, object obj)
 {
     ES3TypeMgr.GetOrCreateES3Type(reader.ReadType()).ReadInto <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);
        }
Beispiel #8
0
        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 <long>(ES3Type_long.Instance);
                    obj = refMgr.Get(id);
                }
                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 <long>(ES3Type_long.Instance);
                    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);
                    }
                }
                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);
        }
Beispiel #9
0
        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();
        }
Beispiel #10
0
        public override object Read <T>(ES3Reader reader)
        {
            UnityEngine.Object obj = null;

            // Read the intial properties regarding the instance we're loading.
            while (true)
            {
                var refMgr = ES3ReferenceMgrBase.Current;
                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;
                    }

                    long id = reader.Read <long>(ES3Type_long.Instance);
                    obj = refMgr.Get(id);

                    if (obj == null)
                    {
                        // If an instance isn't already registered for this object, create an instance and register the reference.
                        obj = new GameObject();
                        refMgr.Add(obj, id);
                    }
                    else if (!ES3Reflection.IsAssignableFrom(typeof(T), obj.GetType()))
                    {
                        throw new MissingReferenceException("The instance with ID \"" + id + "\" is a different type than expected. Expected \"" + typeof(T) + "\", found \"" + obj.GetType() + "\"");
                    }
                }

                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 <long>(ES3Type_long.Instance);
                    refMgr.Add(((GameObject)obj).transform, transformID);
                }

                else if (propertyName == prefabPropertyName)
                {
                    if (ES3ReferenceMgrBase.Current == null)
                    {
                        reader.Skip();
                    }
                    else
                    {
                        obj = reader.Read <GameObject>(ES3Type_ES3PrefabInternal.Instance);
                    }
                }
                else if (propertyName == null)
                {
                    return(obj);
                }
                else
                {
                    reader.overridePropertiesName = propertyName;
                    break;
                }
            }

            if (obj == null)
            {
                obj = new GameObject();
            }

            ReadInto <T>(reader, obj);
            return(obj);
        }