public override object PopulateMember(string memberName, JsonContract contract, JsonReader reader, Type objectType, object targetObject, JsonSerializerReader internalReader)
        {
            Texture2D instance = (Texture2D)targetObject;

            if (instance == null)
            {
                int width = reader.ReadAsInt32().GetValueOrDefault();
                reader.Read();
                int height = reader.ReadAsInt32().GetValueOrDefault();
                reader.Read();
                TextureFormat format = internalReader.Deserialize <TextureFormat>(reader);
                reader.Read();
                int mipmapCount = reader.ReadAsInt32().GetValueOrDefault();
                instance = new Texture2D(width, height, format, mipmapCount > 1);
            }
            else
            {
                switch (memberName)
                {
                case "filterMode":
                    instance.filterMode = internalReader.Deserialize <FilterMode>(reader);
                    break;

                case "anisoLevel":
                    instance.anisoLevel = reader.ReadAsInt32().GetValueOrDefault();
                    break;

                case "wrapMode":
                    instance.wrapMode = internalReader.Deserialize <TextureWrapMode>(reader);
                    break;

                case "mipMapBias":
                    instance.mipMapBias = (float)reader.ReadAsDecimal();
                    break;

                case "rawTextureData":
                    // LoadRawTextureData requires that the correct width, height, TextureFormat and mipMaps are set before being called.
                    // If an error occurs here, it's likely that we're using LoadInto to load into a Texture which differs in these values.
                    // In this case, LoadInto should be avoided and Load should be used instead.
                    instance.LoadRawTextureData(reader.ReadAsBytes());
                    instance.Apply();
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
            return(instance);
        }
        internal virtual object DeserializeInternal(JsonReader reader, Type objectType)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            JsonSerializerReader serializerReader = new JsonSerializerReader(this);

            return(serializerReader.Deserialize(reader, objectType));
        }
Example #3
0
 protected override object DeserializeInternal(JsonReader reader, Type objectType)
 {
     if (_serializerReader != null)
     {
         return(_serializerReader.Deserialize(reader, objectType, false));
     }
     else
     {
         return(_serializer.Deserialize(reader, objectType));
     }
 }
Example #4
0
        public override object PopulateMember(string memberName, JsonContract contract, JsonReader reader, Type objectType, object targetObject, JsonSerializerReader internalReader)
        {
            if (objectType == typeof(Rect))
            {
                var rect = (Rect)targetObject;
                switch (memberName)
                {
                case "position":
                    rect.position = internalReader.Deserialize <Vector2>(reader);
                    break;

                case "size":
                    rect.size = internalReader.Deserialize <Vector2>(reader);
                    break;

                default:
                    reader.Skip();
                    break;
                }
                return(rect);
            }
            else
            {
                var rect = (RectInt)targetObject;
                switch (memberName)
                {
                case "position":
                    rect.position = internalReader.Deserialize <Vector2Int>(reader);
                    break;

                case "size":
                    rect.size = internalReader.Deserialize <Vector2Int>(reader);
                    break;

                default:
                    reader.Skip();
                    break;
                }
                return(rect);
            }
        }
Example #5
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);
        }