Exemplo n.º 1
0
    public override object Deserialize(JsonHelperReader json, object obj)
    {
        Texture t = null;

        string name = (string)json.ReadRawProperty("name");
        string type = (string)json.ReadRawProperty("type");
        bool   mipmaps, readwrite;

        if (type == "2D")
        {
            TextureFormat format = json.ReadProperty <TextureFormat>("format");
            mipmaps   = (bool)json.ReadRawProperty("mipmaps");
            readwrite = (bool)json.ReadRawProperty("readwrite");

            obj = t = new Texture2D(2, 2, format, mipmaps);
        }
        else
        {
            throw new JsonReaderException("Texture types other than Texture2D not supported!");
        }

        t.name = name;

        if (t is Texture2D)
        {
            Texture2D t2D = (Texture2D)t;

            string dumppath = null;
            string @in      = (string)json.ReadRawProperty(JSONHelper.META.EXTERNAL_IN);
            string path     = (string)json.ReadRawProperty(JSONHelper.META.EXTERNAL_PATH);
            if (@in == JSONHelper.META.EXTERNAL_IN_SHARED && JSONHelper.SharedDir != null)
            {
                dumppath = Path.Combine(JSONHelper.SharedDir, "Texture2Ds");
            }
            else if (@in == JSONHelper.META.EXTERNAL_IN_RELATIVE && json.RelativeDir != null)
            {
                dumppath = json.RelativeDir;
            }
            if (dumppath == null)
            {
                t2D.Apply(mipmaps, !readwrite);
                return(t2D);
            }

            dumppath = Path.Combine(dumppath, path);
            if (!File.Exists(dumppath))
            {
                return(t2D);
            }
            t2D.LoadImage(File.ReadAllBytes(dumppath), false);
            t2D.Apply(mipmaps, !readwrite);
            return(t2D);
        }

        return(t);
    }
Exemplo n.º 2
0
    protected override object Deserialize_(JsonHelperReader json, object obj)
    {
        if (obj == null)
        {
            // TODO all the (2) various types of Transforms
            /*Drop */ json.ReadProperty <Vector3>("position");
            /*Drop */ json.ReadProperty <Quaternion>("rotation");
            /*Drop */ json.ReadProperty <Vector3>("localScale");
            return(null);
        }

        Transform t = (Transform)obj;

        // TODO all the (2) various types of Transforms
        t.position   = json.ReadProperty <Vector3>("position");
        t.rotation   = json.ReadProperty <Quaternion>("rotation");
        t.localScale = json.ReadProperty <Vector3>("localScale");

        return(t);
    }