示例#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);
            }
        }
    }
示例#2
0
    public void DeserializeComponentData(JsonHelperReader json, GameObject go, bool property = true)
    {
        Transform transform = go.transform;
        int       children  = transform.childCount;

        if (property)
        {
            json.ReadPropertyName("componentData");
        }
        json.Read(); // Drop StartArray

        int components = (int)(long)json.Value; json.Read();

        for (int i = 0; i < components; i++)
        {
            FillComponent(json, go);
        }

        json.Read(); // Drop StartArray
        int ii = -1;

        while (json.TokenType != JsonToken.EndArray)
        {
            GameObject child = transform.GetChild(++ii).gameObject;
            DeserializeComponentData(json, child, false);
        }
        json.Read(); // Drop EndArray

        json.Read(); // Drop EndArray
    }
示例#3
0
    public virtual object Deserialize(JsonHelperReader json, object obj)
    {
        if (obj is UnityEngine.Object && !(obj is Component))
        {
            ((UnityEngine.Object)obj).name = (string)json.ReadRawProperty("name");
        }

        while (json.TokenType != JsonToken.EndObject)
        {
            Deserialize(json, obj, json.ReadPropertyName());
        }

        return(obj);
    }
示例#4
0
 public void DeserializeComponentTypes(JsonHelperReader json, GameObject go)
 {
     json.ReadPropertyName("componentTypes");
     json.Read(); // Drop StartArray
     while (json.TokenType != JsonToken.EndArray)
     {
         Type componentType = json.ReadObject <Type>();
         if (go.GetComponent(componentType) == null)
         {
             go.AddComponent(componentType);
         }
     }
     json.Read(); // Drop EndArray
 }
示例#5
0
    public void DeserializeHierarchy(JsonHelperReader json, GameObject go)
    {
        json.ReadPropertyName("hierarchy");
        Transform transform = go.transform;

        json.Read(); // Drop StartArray
        while (json.TokenType != JsonToken.EndArray)
        {
            GameObject child = new GameObject();
            child.transform.SetParent(transform);
            json.Read(); // Drop StartObject
            DeserializeMain(json, child);
            DeserializeComponentTypes(json, child);
            DeserializeHierarchy(json, child);
            json.Read(); // Drop EndObject
        }
        json.Read();     // Drop EndArray
    }
示例#6
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);
    }