コード例 #1
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializerWriter internalWriter)
        {
            ReflectionObject reflectionObject = ReflectionObjectPerType.Get(value.GetType());

            DefaultContractResolver resolver = internalWriter.Serializer.ContractResolver as DefaultContractResolver;

            writer.WriteStartObject();
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(KeyName) : KeyName);
            internalWriter.Serialize(writer, reflectionObject.GetValue(value, KeyName), reflectionObject.GetType(KeyName));
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(ValueName) : ValueName);
            internalWriter.Serialize(writer, reflectionObject.GetValue(value, ValueName), reflectionObject.GetType(ValueName));
            writer.WriteEndObject();
        }
コード例 #2
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializerWriter internalWriter)
        {
            DefaultContractResolver resolver = internalWriter.Serializer.ContractResolver as DefaultContractResolver;

            Type  unionType = UnionTypeLookupCache.Get(value.GetType());
            Union union     = UnionCache.Get(unionType);

            int       tag      = (int)union.TagReader.Invoke(value);
            UnionCase caseInfo = union.Cases.Single(c => c.Tag == tag);

            writer.WriteStartObject();
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(CasePropertyName) : CasePropertyName);
            writer.WriteValue(caseInfo.Name);
            if (caseInfo.Fields != null && caseInfo.Fields.Length > 0)
            {
                object[] fields = (object[])caseInfo.FieldReader.Invoke(value);

                writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(FieldsPropertyName) : FieldsPropertyName);
                writer.WriteStartArray();
                foreach (object field in fields)
                {
                    internalWriter.Serialize(writer, field, field.GetType());
                }
                writer.WriteEndArray();
            }
            writer.WriteEndObject();
        }
コード例 #3
0
        internal virtual void SerializeInternal(JsonWriter jsonWriter, object value)
        {
            ValidationUtils.ArgumentNotNull(jsonWriter, "jsonWriter");

            JsonSerializerWriter serializerWriter = new JsonSerializerWriter(this);

            serializerWriter.Serialize(jsonWriter, value);
        }
コード例 #4
0
        public override void WriteProperties(JsonObjectContract contract, JsonWriter writer, object value, Type objectType, JsonSerializerWriter internalWriter)
        {
            var instance = (UnityEngine.Mesh)value;

#if UNITY_2017_3
            internalWriter.SerializeProperty(writer, "indexFormat", instance.indexFormat);
#endif
            internalWriter.SerializeProperty(writer, "bindposes", instance.bindposes);
            writer.WriteProperty("subMeshCount", instance.subMeshCount);
            internalWriter.SerializeProperty(writer, "bounds", instance.bounds);
            internalWriter.SerializeProperty(writer, "vertices", instance.vertices);
            internalWriter.SerializeProperty(writer, "normals", instance.normals);
            internalWriter.SerializeProperty(writer, "tangents", instance.tangents);
            internalWriter.SerializeProperty(writer, "uv", instance.uv);
            internalWriter.SerializeProperty(writer, "uv2", instance.uv2);
            internalWriter.SerializeProperty(writer, "uv3", instance.uv3);
            internalWriter.SerializeProperty(writer, "uv4", instance.uv4);
            internalWriter.SerializeProperty(writer, "colors", instance.colors);
            internalWriter.SerializeProperty(writer, "colors32", instance.colors32);

            writer.WritePropertyName("triangles");
            writer.WriteStartArray();
            for (int i = 0; i < instance.subMeshCount; i++)
            {
                internalWriter.Serialize(writer, instance.GetTriangles(i));
            }
            writer.WriteEndArray();

            writer.WritePropertyName("indices");
            writer.WriteStartArray();
            for (int i = 0; i < instance.subMeshCount; i++)
            {
                SerializedIndices serializedIndices = new SerializedIndices();
                serializedIndices.meshTopology = instance.GetTopology(i);
                serializedIndices.indices      = instance.GetIndices(i);
                internalWriter.Serialize(writer, serializedIndices);
            }
            writer.WriteEndArray();

            internalWriter.SerializeProperty(writer, "boneWeights", instance.boneWeights);
            writer.WriteProperty("name", instance.name);
            internalWriter.SerializeProperty(writer, "hideFlags", instance.hideFlags);
        }
コード例 #5
0
 protected override void SerializeInternal(JsonWriter jsonWriter, object value, Type rootType)
 {
     if (_serializerWriter != null)
     {
         _serializerWriter.Serialize(jsonWriter, value, rootType);
     }
     else
     {
         _serializer.Serialize(jsonWriter, value);
     }
 }
コード例 #6
0
        public override void WriteProperties(JsonObjectContract contract, JsonWriter writer, object value, Type objectType, JsonSerializerWriter internalWriter)
        {
            base.WriteProperties(contract, writer, value, objectType, internalWriter);

            GameObject gameObject = (GameObject)value;
            GameObjectSerializationHandler serializationHandler = gameObject.GetComponent <GameObjectSerializationHandler>();

            writer.WriteProperty("name", gameObject.name);
            writer.WriteProperty("tag", gameObject.tag);
            writer.WriteProperty("active", gameObject.activeSelf);
            writer.WriteProperty("isStatic", gameObject.isStatic);
            writer.WriteProperty("layer", gameObject.layer);
            writer.WriteProperty("hideFlags", gameObject.hideFlags);

            bool serializeComponents = true;

            if (serializationHandler != null)
            {
                serializeComponents = serializationHandler.SerializeComponents;
            }
            if (serializeComponents)
            {
                writer.WritePropertyName("components");
                writer.WriteStartArray();
                Component[] components = gameObject.GetComponents <Component>();
                for (int i = 0; i < components.Length; i++)
                {
                    Component component       = components[i];
                    bool      shouldSerialize = true;
                    if (serializationHandler != null)
                    {
                        shouldSerialize = serializationHandler.ShouldSerializeComponent(component);
                    }
                    if (shouldSerialize)
                    {
                        writer.WriteStartObject();
                        internalWriter.WriteTypeProperty(writer, component.GetType());
                        writer.WritePropertyName(JsonTypeReflector.ValuePropertyName);
                        internalWriter.Serialize(writer, component);
                        writer.WriteEndObject();
                    }
                }
                writer.WriteEndArray();
            }

            bool serializeChildren = true;

            if (serializationHandler != null)
            {
                serializeChildren = serializationHandler.SerializeChildren;
            }
            if (serializeChildren)
            {
                writer.WritePropertyName("children");
                writer.WriteStartArray();
                for (int i = 0; i < gameObject.transform.childCount; i++)
                {
                    Transform child           = gameObject.transform.GetChild(i);
                    bool      shouldSerialize = true;
                    if (serializationHandler != null)
                    {
                        shouldSerialize = serializationHandler.ShouldSerializeChild(child);
                    }
                    if (shouldSerialize)
                    {
                        internalWriter.Serialize(writer, child.gameObject);
                    }
                }
                writer.WriteEndArray();
            }
        }