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) { } } } }
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++; } }