Beispiel #1
0
    public void FillComponent(JsonHelperReader json, GameObject go)
    {
        json.Read(); // Drop StartObject
        string metaProp = json.ReadPropertyName();

        if (metaProp == JSONHelper.META.PROP)
        {
            Type componentType = json.ReadMetaObjectType();
            json.FillObject(go.GetComponent(componentType), componentType, null, true);
            return;
        }

        if (metaProp == JSONHelper.META.MARKER)
        {
            // Only meta currently allowed here is an external reference.
            // References back aren't allowed as one would need to read the same .json
            // and read / skip until the ref ID required is reached, then fill the component.
            // But doing even that only creates a shallow clone...
            // TODO do dat if it should be a shallow clone anyway.
            json.Read();    // Drop value
            using (JsonHelperReader ext = json.OpenMetaExternal(true)) {
                ext.Read(); // Go to Start
                FillComponent(ext, go);
            }
        }
    }
Beispiel #2
0
    public virtual string ReadMetaHeader(JsonHelperReader json, ref Type type)
    {
        string metaProp = json.ReadPropertyName();

        if (metaProp != JSONHelper.META.PROP)
        {
            return(metaProp);
        }

        Type typeR = json.ReadMetaObjectType();

        if (JSONHelper.CheckOnRead && !type.IsAssignableFrom(typeR))
        {
            throw new JsonReaderException("Type mismatch! Expected " + type.FullName + ", got " + typeR.FullName);
        }
        type = typeR;

        return(null);
    }