public static BuildableComponent Deserialize(XmlReader xmlReader)
        {
            if (componentTypes == null)
            {
                componentTypes = FindComponentsInAssembly();
            }

            string componentTypeName = xmlReader.GetAttribute("type");

            if (componentTypes.ContainsKey(componentTypeName))
            {
                xmlReader = xmlReader.ReadSubtree();
                Type               t          = componentTypes[componentTypeName];
                XmlSerializer      serializer = new XmlSerializer(t);
                BuildableComponent component  = (BuildableComponent)serializer.Deserialize(xmlReader);
                //// need to set name explicitly (not part of deserialization as it's passed in)
                component.Type = componentTypeName;
                return(component);
            }
            else
            {
                UnityDebugger.Debugger.LogErrorFormat(ComponentLogChannel, "There is no deserializer for component '{0}'", componentTypeName);
                return(null);
            }
        }
Exemplo n.º 2
0
        public static BuildableComponent Deserialize(JToken jtoken)
        {
            if (componentTypes == null)
            {
                componentTypes = FindComponentsInAssembly();
            }

            JToken jcomponent        = jtoken["Component"];
            string componentTypeName = jcomponent["Type"].ToString();

            Type t;

            if (componentTypes.TryGetValue(componentTypeName, out t))
            {
                BuildableComponent component = (BuildableComponent)jcomponent.ToObject(t);

                // need to set name explicitly (not part of deserialization as it's passed in)
                component.Type = componentTypeName;
                return(component);
            }
            else
            {
                UnityDebugger.Debugger.LogErrorFormat(ComponentLogChannel, "There is no deserializer for component '{0}'", componentTypeName);
                return(null);
            }
        }
Exemplo n.º 3
0
        public static BuildableComponent FromJson(JToken componentToken)
        {
            if (componentTypes == null)
            {
                componentTypes = FindComponentsInAssembly();
            }

            JProperty componentProperty = (JProperty)componentToken;
            string    componentTypeName = componentProperty.Name;
            Type      t;

            if (componentTypes.TryGetValue(componentTypeName, out t))
            {
                BuildableComponent component = (BuildableComponent)componentProperty.Value.ToObject(t);

                // need to set name explicitly (not part of deserialization as it's passed in)
                component.Type = componentProperty.Name;

                return(component);
            }
            else
            {
                return(null);
            }
        }
        public static BuildableComponent Deserialize(JToken jtoken)
        {
            if (componentTypes == null)
            {
                componentTypes = FindComponentsInAssembly();
            }

            string componentTypeName = jtoken["Component"]["Type"].ToString();

            if (componentTypes.ContainsKey(componentTypeName))
            {
                Type t = componentTypes[componentTypeName];
                BuildableComponent component = (BuildableComponent)jtoken["Component"].ToObject(t);
                //// need to set name explicitly (not part of deserialization as it's passed in)
                component.Type = componentTypeName;
                return(component);
            }
            else
            {
                Debug.ULogErrorChannel(ComponentLogChannel, "There is no deserializer for component '{0}'", componentTypeName);
                return(null);
            }
        }
 public BuildableComponent(BuildableComponent other)
 {
     Type = other.Type;
 }