public override void Serialize(JsonHelperWriter json, object obj)
    {
        Vector2 v = (Vector2)obj;

        json.WriteProperty("x", v.x);
        json.WriteProperty("y", v.y);
    }
    public override void Serialize(JsonHelperWriter json, object obj)
    {
        DictionaryEntry entry = (DictionaryEntry)obj;

        json.WriteProperty("key", entry.Key);
        json.WriteProperty("value", entry.Value);
    }
Exemple #3
0
 public override void Serialize(JsonHelperWriter json, object obj)
 {
     try {
         json.WriteProperty("text", ((TextAsset)obj).text);
     } catch {
         json.WriteProperty("text", null);
     }
 }
Exemple #4
0
    public void SerializeMain(JsonHelperWriter json, GameObject go)
    {
        json.WriteProperty("name", go.name);

        json.WriteProperty("tag", go.tag);
        json.WriteProperty("layer", go.layer);
        json.WriteProperty("activeSelf", go.activeSelf);
    }
    public override void Serialize(JsonHelperWriter json, object obj)
    {
        Quaternion q = (Quaternion)obj;

        json.WriteProperty("x", q.x);
        json.WriteProperty("y", q.y);
        json.WriteProperty("z", q.z);
        json.WriteProperty("w", q.w);
    }
Exemple #6
0
    protected override void Serialize_(JsonHelperWriter json, object obj)
    {
        Transform t = (Transform)obj;

        // TODO all the (2) various types of Transforms
        json.WriteProperty("position", t.position);
        json.WriteProperty("rotation", t.rotation);
        json.WriteProperty("localScale", t.localScale);
    }
 public static void WriteMetaArrayData(this JsonHelperWriter json, string type, int size = -1)
 {
     json.WriteStartMetadata(META.ARRAYTYPE);
     json.WriteProperty(META.TYPE_FULLNAME, type);
     if (type == META.ARRAYTYPE_ARRAY)
     {
         json.WriteProperty(META.ARRAYTYPE_ARRAY_SIZE, size);
     }
     json.WriteEndMetadata();
 }
    public static void WriteMetaExternal(this JsonHelperWriter json, string path, string @in = META.EXTERNAL_IN_RESOURCES)
    {
        json.WriteStartMetadata(META.EXTERNAL);

        if (@in != META.EXTERNAL_IN_RESOURCES)
        {
            json.WriteProperty(META.EXTERNAL_IN, @in);
        }
        json.WriteProperty(META.EXTERNAL_PATH, path);

        json.WriteEndMetadata();
    }
Exemple #9
0
    public override void Serialize(JsonHelperWriter json, object obj)
    {
        Component c = (Component)obj;

        if (json.At(-2) is GameObject)
        {
            json.WriteProperty(JSONHelper.META.TYPE, JSONHelper.META.COMPONENTTYPE_DEFINITION);
            Serialize_(json, obj);
        }
        else
        {
            json.WriteProperty(JSONHelper.META.TYPE, JSONHelper.META.COMPONENTTYPE_REFERENCE);
            json.WriteProperty("name", c.gameObject.name);
            json.WriteProperty("path", c.transform.GetPath());
        }
    }
Exemple #10
0
    public static bool TryWriteMetaReference(this JsonHelperWriter json, object obj, bool register = false)
    {
        int id = json.GetReferenceID(obj);

        if (id != META.REF_NONE)
        {
            json.WriteStartMetadata(META.REF);

            json.WriteProperty(META.REF_ID, id);
            json.WriteProperty(META.REF_TYPE, json.GetReferenceType(id, obj));

            json.WriteEndMetadata();
            return(true);
        }

        if (register)
        {
            json.RegisterReference(obj);
        }
        return(false);
    }
Exemple #11
0
    private static void WriteMetaType_(this JsonHelperWriter json, Type type, string metaType)
    {
        json.WriteStartMetadata(metaType);

        json.WriteProperty(META.TYPE_FULLNAME, type.FullName);

        /*string ns = type.Namespace;
         * if (ns != null) {
         *  json.WritePropertyName(META.TYPE_SPLIT);
         *  json.WriteStartArray();
         *  json.Write(ns);
         *  json.Write(type.Name);
         *  json.WriteEndArray();
         * }*/
        Type[] genparams = type.GetGenericArguments();
        if (genparams.Length != 0)
        {
            json.WriteProperty(META.TYPE_GENPARAMS, genparams);
        }

        json.WriteEndMetadata();
    }
Exemple #12
0
    public virtual void Serialize(JsonHelperWriter json, object obj)
    {
        if (obj is UnityEngine.Object && !(obj is Component))
        {
            json.WriteProperty("name", ((UnityEngine.Object)obj).name);
        }

        if (ForceSerializeProperties)
        {
            for (int i = 0; i < _Properties.Length; i++)
            {
                Serialize(json, obj, _Properties[i]);
            }
        }

        for (int i = 0; i < _Fields.Length; i++)
        {
            Serialize(json, obj, _Fields[i]);
        }
    }
Exemple #13
0
 public static void WriteStartMetadata(this JsonHelperWriter json, string metaType)
 {
     json.WriteStartObject();
     json.WriteProperty(META.MARKER, metaType);
 }
Exemple #14
0
 public override void Serialize(JsonHelperWriter json, object obj)
 {
     json.WriteProperty(JSONHelper.META.UNSUPPORTED, JSONHelper.META.UNSUPPORTED_USE_EXTERNAL);
 }
Exemple #15
0
    public override void Serialize(JsonHelperWriter json, object obj)
    {
        string name = ((Texture)obj).name;

        json.WriteProperty("name", name);
        json.WriteProperty("type", obj.GetType().Name.Substring(7));

        if (!(obj is Texture2D))
        {
            return;
        }
        Texture2D t2D = (Texture2D)obj;

        json.WriteProperty("format", t2D.format);
        json.WriteProperty("mipmaps", 1 < t2D.mipmapCount);
        json.WriteProperty("readwrite", t2D.IsReadable());

        string dumproot = null;
        string path     = name;
        bool   sharedDumpBlacklisted = SharedDumpBlacklist.Contains(name);

        if (JSONHelper.SharedDir != null && !sharedDumpBlacklisted)
        {
            dumproot = Path.Combine(JSONHelper.SharedDir, "Texture2Ds");

            int id;
            if (!_DumpNameIdMap.TryGetValue(name, out id))
            {
                id = -1;
            }
            _DumpNameIdMap[name] = ++id;

            if (id != 0)
            {
                path += "." + id;
            }
            _DumpTex2DPathMap[t2D] = path;

            json.WriteProperty(JSONHelper.META.EXTERNAL_IN, JSONHelper.META.EXTERNAL_IN_SHARED);
        }
        else if (json.DumpRelatively || sharedDumpBlacklisted)
        {
            dumproot = json.RelativeDir;
            json.WriteProperty(JSONHelper.META.EXTERNAL_IN, JSONHelper.META.EXTERNAL_IN_RELATIVE);
        }
        if (dumproot == null)
        {
            json.WriteProperty(JSONHelper.META.EXTERNAL_IN, "");
            json.WriteProperty(JSONHelper.META.EXTERNAL_PATH, "");
            return;
        }

        string dumppath = Path.Combine(dumproot, path.Replace('/', Path.DirectorySeparatorChar) + ".png");

        Directory.GetParent(dumppath).Create();
        if (File.Exists(dumppath))
        {
            json.WriteProperty(JSONHelper.META.EXTERNAL_PATH, dumppath);
            return;
        }
        File.WriteAllBytes(dumppath, t2D.GetRW().EncodeToPNG());
        json.WriteProperty(JSONHelper.META.EXTERNAL_PATH, path);
    }