public ObjectModel Disassemble(Component component, DisassemblyContext context) { var converter = GetComponentConverter(component.GetType()); if (converter != null) { Component converted = converter.ConvertComponent(component, component.gameObject); return(context.MakeReferencable(component, (ObjectModel)Disassemble(converted, context).MakeExplicit(converted.GetType()))); } var assembler = GetEngineComponentAssembler(component.GetType()); if (assembler != null) { return(context.MakeReferencable(component, (ObjectModel)assembler.Disassemble(component, context).MakeExplicit(component.GetType()))); // Components are always explicit. } ObjectPopulator populator = new ObjectPopulator(); return((ObjectModel)populator.Extract(component, context).MakeExplicit(component.GetType())); }
public ObjectModel RecursiveDisassemble(GameObject gameObject, DisassemblyContext context) { var children = new List <ObjectModel>(); Component[] components = gameObject.GetComponents <Component>().Where(x => !x.GetType().IsDefined(typeof(DontSerializeAttribute), false)).ToArray(); var componentModels = new List <ObjectModel>(); foreach (Component component in components) { componentModels.Add(_componentAssembler.Disassemble(component, context)); } return(context.MakeReferencable(gameObject, new ObjectModel( new ObjectField("Name", ValueModelFactory.Create(gameObject.name, context)), new ObjectField("Tag", ValueModelFactory.Create(gameObject.tag, context)), new ObjectField("Layer", ValueModelFactory.Create(gameObject.layer, context)), new ObjectField("Static", ValueModelFactory.Create(gameObject.isStatic, context)), new ObjectField("Components", new ArrayModel(componentModels)), new ObjectField("Children", new ArrayModel(GetChildren(gameObject).Select(x => RecursiveDisassemble(x, context)))) ))); }