示例#1
0
    private static Vector3 ReadVector3(int depth, ObjectDeserializer.ObjectReader reader)
    {
        Vector3 zero = Vector3.zero;

        for (int i = 0; i < 3; i++)
        {
            if (reader.GetIndentation() == depth)
            {
                ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
                if (propertyData.name == "x")
                {
                    zero.x = propertyData.FloatValue;
                }
                else if (propertyData.name == "y")
                {
                    zero.y = propertyData.FloatValue;
                }
                else if (propertyData.name == "z")
                {
                    zero.z = propertyData.FloatValue;
                }
            }
        }
        return(zero);
    }
示例#2
0
 private static void ReadGeneric(object obj, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.ReadComponent(obj, depth, reader);
     }
 }
示例#3
0
 public static void ReadFile(GameObject obj, ObjectDeserializer.ObjectReader reader)
 {
     ObjectDeserializer.PropertyData propertyData = reader.ReadTypeAndName();
     if (propertyData.type == "GameObject" && propertyData.name == obj.name)
     {
         ObjectDeserializer.ReadObject(obj, 1, reader);
     }
 }
示例#4
0
 private static void ReadParticleSystem(ParticleSystem particleSystem, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
         if (propertyData.type == "Generic" && (propertyData.name == "InitialModule" || propertyData.name == "EmissionModule" || propertyData.name == "ShapeModule"))
         {
             ObjectDeserializer.ReadParticleSystemModule(particleSystem, propertyData.name, depth + 1, reader);
         }
     }
 }
示例#5
0
    private static Bounds ReadBounds(int depth, ObjectDeserializer.ObjectReader reader)
    {
        Bounds result = default(Bounds);

        reader.GetIndentation();
        reader.ReadProperty();
        result.center = ObjectDeserializer.ReadVector3(depth + 1, reader);
        reader.GetIndentation();
        reader.ReadProperty();
        result.extents = ObjectDeserializer.ReadVector3(depth + 1, reader);
        return(result);
    }
示例#6
0
    private void ReadPrefabOverrides(GameObject obj, BinaryReader reader)
    {
        int num = reader.ReadInt32();

        byte[] buffer = new byte[num];
        reader.Read(buffer, 0, num);
        using (MemoryStream memoryStream = new MemoryStream(buffer))
        {
            using (StreamReader streamReader = new StreamReader(memoryStream, Encoding.UTF8))
            {
                ObjectDeserializer.ObjectReader reader2 = new ObjectDeserializer.ObjectReader(streamReader, this.m_references);
                ObjectDeserializer.ReadFile(obj, reader2);
            }
        }
        obj.SendMessage("OnDataLoaded", SendMessageOptions.DontRequireReceiver);
    }
示例#7
0
 private static void ReadObject(GameObject obj, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.PropertyData propertyData = reader.ReadTypeAndName();
         if (propertyData.type == "Component")
         {
             string text;
             if (propertyData.name.Contains("."))
             {
                 text = propertyData.name.Substring(propertyData.name.LastIndexOf(".") + 1);
             }
             else
             {
                 text = propertyData.name;
             }
             Component component = obj.GetComponent(text);
             if (component == null)
             {
                 Type componentTypeByName = ComponentHelper.GetComponentTypeByName(text);
                 component = (componentTypeByName == null) ? null : obj.AddComponent(componentTypeByName);
             }
             if (component != null)
             {
                 if (component is ParticleSystem)
                 {
                     ObjectDeserializer.ReadParticleSystem((ParticleSystem)component, depth + 1, reader);
                 }
                 else
                 {
                     ObjectDeserializer.ReadComponent(component, depth + 1, reader);
                 }
             }
         }
         else if (propertyData.type == "GameObject")
         {
             GameObject gameObject = obj.transform.Find(propertyData.name).gameObject;
             if (gameObject)
             {
                 ObjectDeserializer.ReadObject(gameObject, depth + 1, reader);
             }
         }
     }
 }
示例#8
0
 private static void ReadComponent(object component, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
         if (propertyData.type == "Integer")
         {
             ObjectDeserializer.SetProperty(component, propertyData.name, propertyData.IntegerValue);
         }
         else if (propertyData.type == "Float")
         {
             ObjectDeserializer.SetProperty(component, propertyData.name, propertyData.FloatValue);
         }
         else if (propertyData.type == "String")
         {
             ObjectDeserializer.SetProperty(component, propertyData.name, propertyData.StringValue);
             reader.ReadProperty();
         }
         else if (propertyData.type == "Boolean")
         {
             ObjectDeserializer.SetProperty(component, propertyData.name, propertyData.BoolValue);
         }
         else if (propertyData.type == "Enum")
         {
             ObjectDeserializer.SetProperty(component, propertyData.name, propertyData.IntegerValue);
         }
         else if (propertyData.type == "Bounds")
         {
             ObjectDeserializer.SetProperty(component, propertyData.name, ObjectDeserializer.ReadBounds(depth + 1, reader));
         }
         else if (propertyData.type == "ObjectReference")
         {
             UnityEngine.Object referencedObject = reader.GetReferencedObject(propertyData.IntegerValue);
             if (referencedObject)
             {
                 ObjectDeserializer.SetProperty(component, propertyData.name, referencedObject);
             }
             else
             {
                 ObjectDeserializer.SetProperty(component, propertyData.name, null);
             }
             if (reader.GetIndentation() == depth + 1)
             {
                 reader.ReadProperty();
             }
             if (reader.GetIndentation() == depth + 1)
             {
                 reader.ReadProperty();
             }
         }
         else if (propertyData.type == "Array")
         {
             ObjectDeserializer.ReadArray(component, propertyData.name, depth + 1, reader);
         }
         else if (propertyData.type == "AnimationCurve")
         {
             ObjectDeserializer.ReadAnimationCurve(component, propertyData.name, depth + 1, reader);
         }
         else if (propertyData.type == "Generic" || propertyData.type == "Color" || propertyData.type == "Vector2" || propertyData.type == "Vector3" || propertyData.type == "Rect" || propertyData.type == "16" || propertyData.type == "Quaternion")
         {
             FieldInfo field = component.GetType().GetField(propertyData.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
             if (field != null)
             {
                 object value = field.GetValue(component);
                 ObjectDeserializer.ReadGeneric(value, depth + 1, reader);
                 if (field.FieldType.IsValueType)
                 {
                     field.SetValue(component, value);
                 }
             }
             else if (component is Camera && propertyData.name == "m_BackGroundColor")
             {
                 object obj = default(Color);
                 ObjectDeserializer.ReadGeneric(obj, depth + 1, reader);
                 ((Camera)component).backgroundColor = (Color)obj;
             }
             else if (component is BoxCollider && propertyData.name == "m_Center")
             {
                 Vector3 center = ((BoxCollider)component).center;
                 object  obj2   = new Vector3(center.x, center.y, center.z);
                 ObjectDeserializer.ReadGeneric(obj2, depth + 1, reader);
                 ((BoxCollider)component).center = (Vector3)obj2;
             }
             else if (component is BoxCollider && propertyData.name == "m_Size")
             {
                 Vector3 size = ((BoxCollider)component).size;
                 object  obj3 = new Vector3(size.x, size.y, size.z);
                 ObjectDeserializer.ReadGeneric(obj3, depth + 1, reader);
                 ((BoxCollider)component).size = (Vector3)obj3;
             }
             else if (component is Transform && propertyData.name == "m_LocalRotation")
             {
                 Quaternion localRotation = ((Transform)component).localRotation;
                 object     obj4          = new Quaternion(localRotation.x, localRotation.y, localRotation.z, localRotation.w);
                 ObjectDeserializer.ReadGeneric(obj4, depth + 1, reader);
                 ((Transform)component).localRotation = (Quaternion)obj4;
             }
             else if (component is Transform && propertyData.name == "m_LocalPosition")
             {
                 Vector3 localPosition = ((Transform)component).localPosition;
                 object  obj5          = new Vector3(localPosition.x, localPosition.y, localPosition.z);
                 ObjectDeserializer.ReadGeneric(obj5, depth + 1, reader);
                 ((Transform)component).localPosition = (Vector3)obj5;
             }
             else if (component is Transform && propertyData.name == "m_LocalScale")
             {
                 Vector3 localScale = ((Transform)component).localScale;
                 object  obj6       = new Vector3(localScale.x, localScale.y, localScale.z);
                 ObjectDeserializer.ReadGeneric(obj6, depth + 1, reader);
                 ((Transform)component).localScale = (Vector3)obj6;
             }
             else if (component is HingeJoint)
             {
             }
         }
     }
 }
示例#9
0
    private static void ReadArray(object component, string fieldName, int depth, ObjectDeserializer.ObjectReader reader)
    {
        FieldInfo field = component.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

        if (field == null)
        {
            return;
        }
        object obj = field.GetValue(component);

        if (obj == null)
        {
            obj = Activator.CreateInstance(field.FieldType);
            field.SetValue(component, obj);
        }
        int num = 0;

        if (reader.GetIndentation() == depth)
        {
            ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
            num = propertyData.IntegerValue;
        }
        IList list = (IList)obj;

        while (list.Count > num)
        {
            list.RemoveAt(list.Count - 1);
        }
        int num2 = 0;

        while (reader.GetIndentation() == depth)
        {
            ObjectDeserializer.PropertyData propertyData2 = reader.ReadProperty();
            if (propertyData2.type == "Element")
            {
                int  num3 = int.Parse(propertyData2.name);
                Type type = list.GetType().GetGenericArguments()[0];
                if (type.IsValueType)
                {
                    if (num3 > list.Count)
                    {
                        list.Add(ObjectDeserializer.GetDefaultValue(type));
                        num3 -= num3 - list.Count;
                    }
                    if (num3 < list.Count)
                    {
                        list[num3] = ObjectDeserializer.ReadValueType(depth + 1, reader);
                    }
                    else
                    {
                        list.Insert(num3, ObjectDeserializer.ReadValueType(depth + 1, reader));
                    }
                }
                else if (type.IsSubclassOf(typeof(UnityEngine.Object)))
                {
                    reader.GetIndentation();
                    propertyData2 = reader.ReadProperty();
                    UnityEngine.Object referencedObject = reader.GetReferencedObject(propertyData2.IntegerValue);
                    if (referencedObject != null)
                    {
                        if (list.Count <= num3)
                        {
                            list.Insert(num3, referencedObject);
                        }
                        else
                        {
                            list[num3] = referencedObject;
                        }
                    }
                }
                else
                {
                    reader.GetIndentation();
                    propertyData2 = reader.ReadProperty();
                    if (list.Count <= num3)
                    {
                        list.Insert(num3, Activator.CreateInstance(type));
                    }
                    object obj2 = list[num3];
                    ObjectDeserializer.ReadGeneric(obj2, depth + 1, reader);
                }
            }
            num2++;
        }
    }
示例#10
0
    private static void ReadAnimationCurve(object component, string fieldName, int depth, ObjectDeserializer.ObjectReader reader)
    {
        FieldInfo field = component.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

        if (field == null)
        {
            return;
        }
        object obj = field.GetValue(component);

        if (obj == null)
        {
            obj = Activator.CreateInstance(field.FieldType);
            field.SetValue(component, obj);
        }
        while (reader.GetIndentation() == depth)
        {
            ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
            Type         type     = obj.GetType();
            PropertyInfo property = type.GetProperty("keys", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            object       value    = property.GetValue(obj, null);
            int          length   = 0;
            depth++;
            if (reader.GetIndentation() == depth)
            {
                propertyData = reader.ReadProperty();
                length       = propertyData.IntegerValue;
            }
            IEnumerable enumerable = (IEnumerable)value;
            Type        type2      = null;
            Array       array      = null;
            int         num        = 0;
            IEnumerator enumerator = enumerable.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    object obj2 = enumerator.Current;
                    if (array == null)
                    {
                        type2 = obj2.GetType();
                        array = Array.CreateInstance(type2, length);
                    }
                    if (array.GetLength(0) <= num)
                    {
                        break;
                    }
                    array.SetValue(obj2, num);
                    num++;
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            while (array.GetLength(0) > num)
            {
                if (array.GetValue(num) == null)
                {
                    array.SetValue(Activator.CreateInstance(type2), num);
                }
                num++;
            }
            while (reader.GetIndentation() == depth)
            {
                propertyData = reader.ReadProperty();
                if (propertyData.type == "Element")
                {
                    num = int.Parse(propertyData.name);
                    while (reader.GetIndentation() == depth + 1)
                    {
                        propertyData = reader.ReadProperty();
                        if (propertyData.type == "Generic" || propertyData.type == "Keyframe")
                        {
                            object value2 = array.GetValue(num);
                            ObjectDeserializer.ReadGeneric(value2, depth + 1, reader);
                            array.SetValue(value2, num);
                        }
                    }
                }
            }
            depth--;
            property.SetValue(obj, array, null);
            field.SetValue(component, obj);
        }
    }
示例#11
0
 private static object ReadValueType(int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
         if (propertyData.type == "Integer")
         {
             return(propertyData.IntegerValue);
         }
         if (propertyData.type == "Float")
         {
             return(propertyData.FloatValue);
         }
         if (propertyData.type == "String")
         {
             return(propertyData.StringValue);
         }
         if (propertyData.type == "Boolean")
         {
             return(propertyData.BoolValue);
         }
         if (propertyData.type == "Enum")
         {
             return(propertyData.IntegerValue);
         }
         if (propertyData.type == "Bounds")
         {
             return(ObjectDeserializer.ReadBounds(depth + 1, reader));
         }
         if (propertyData.type == "Color")
         {
             object obj = default(Color);
             ObjectDeserializer.ReadGeneric(obj, depth, reader);
             return(obj);
         }
         if (propertyData.type == "Vector2")
         {
             object obj2 = default(Vector2);
             ObjectDeserializer.ReadGeneric(obj2, depth, reader);
             return(obj2);
         }
         if (propertyData.type == "Vector3")
         {
             object obj3 = default(Vector3);
             ObjectDeserializer.ReadGeneric(obj3, depth, reader);
             return(obj3);
         }
         if (propertyData.type == "Quaternion")
         {
             object obj4 = default(Quaternion);
             ObjectDeserializer.ReadGeneric(obj4, depth, reader);
             return(obj4);
         }
         if (propertyData.type == "Rect")
         {
             object obj5 = default(Rect);
             ObjectDeserializer.ReadGeneric(obj5, depth, reader);
             return(obj5);
         }
         if (propertyData.type == "Keyframe")
         {
             object obj6 = default(Keyframe);
             ObjectDeserializer.ReadGeneric(obj6, depth, reader);
             return(obj6);
         }
     }
     return(null);
 }
示例#12
0
 private static void ReadParticleSystemModule(ParticleSystem particleSystem, string module, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
         if (module == "InitialModule")
         {
             if (propertyData.type == "Generic" && propertyData.name == "startLifetime")
             {
                 if (reader.GetIndentation() == depth + 1)
                 {
                     propertyData = reader.ReadProperty();
                     particleSystem.startLifetime = propertyData.FloatValue;
                 }
             }
             else if (propertyData.type == "Generic" && propertyData.name == "startSpeed" && reader.GetIndentation() == depth + 1)
             {
                 propertyData = reader.ReadProperty();
                 particleSystem.startSpeed = propertyData.FloatValue;
             }
         }
         else if (module == "EmissionModule")
         {
             if (propertyData.type == "Generic" && propertyData.name == "rate" && reader.GetIndentation() == depth + 1)
             {
                 propertyData = reader.ReadProperty();
             }
         }
         else if (!(module == "ShapeModule") || propertyData.type != "Boolean" || propertyData.name != "enabled" || !propertyData.BoolValue)
         {
         }
     }
 }