Exemple #1
0
 protected override object DeserializeIntoInternal(JsonReader reader, object target)
 {
     if (_serializerReader != null)
     {
         return(_serializerReader.DeserializeInto(reader, target.GetType(), target, false));
     }
     else
     {
         return(_serializer.DeserializeInto(reader, target));
     }
 }
Exemple #2
0
        public override object PopulateMember(string memberName, JsonContract contract, JsonReader reader, Type objectType, object targetObject, JsonSerializerReader internalReader)
        {
            GameObject gameObject = (GameObject)targetObject;
            bool       finished;

            switch (memberName)
            {
            case "name":
                gameObject.name = reader.ReadAsString();
                break;

            case "tag":
                gameObject.tag = reader.ReadAsString();
                break;

            case "active":
                gameObject.SetActive(reader.ReadAsBoolean().GetValueOrDefault());
                break;

            case "isStatic":
                gameObject.isStatic = reader.ReadAsBoolean().GetValueOrDefault();
                break;

            case "layer":
                gameObject.layer = reader.ReadAsInt32().GetValueOrDefault();
                break;

            case "hideFlags":
                gameObject.hideFlags = (HideFlags)reader.ReadAsInt32().GetValueOrDefault();
                break;

            case "components":

                // Skip property name
                reader.ReadAndAssert();

                // Skipy array start
                reader.ReadAndAssert();

                finished = false;
                do
                {
                    switch (reader.TokenType)
                    {
                    case JsonToken.EndArray:
                        finished = true;
                        break;

                    default:
                        if (reader.TokenType != JsonToken.StartObject)
                        {
                            reader.Read();
                            continue;
                        }
                        reader.ReadAndAssert();
                        string       qualifiedTypeName = reader.ReadAsString();
                        Type         componentType     = null;
                        JsonContract componentContract = null;
                        internalReader.ResolveTypeName(reader, ref componentType, ref componentContract, null, null, null, qualifiedTypeName);
                        reader.ReadAndAssert();
                        reader.ReadAndAssert();
                        Component component = gameObject.GetComponent(componentType);
                        if (component == null)
                        {
                            component = gameObject.AddComponent(componentType);
                        }
                        internalReader.DeserializeInto(reader, componentType, component, false);
                        break;
                    }
                } while (!finished);
                break;

            case "children":

                // Skip property name
                reader.ReadAndAssert();

                // Skipy array start
                reader.ReadAndAssert();

                finished = false;
                do
                {
                    switch (reader.TokenType)
                    {
                    case JsonToken.EndArray:
                        finished = true;
                        break;

                    default:
                        if (reader.TokenType != JsonToken.StartObject)
                        {
                            reader.Read();
                            continue;
                        }
                        GameObject child = internalReader.Deserialize <GameObject>(reader);
                        child.transform.SetParent(gameObject.transform);
                        //child.transform.parent = gameObject.transform;
                        break;
                    }
                } while (!finished);
                break;

            default:
                base.PopulateMember(memberName, contract, reader, objectType, targetObject, internalReader);
                break;
            }
            return(gameObject);
        }