public TurretComponent Assemble(ObjectModel model, Transform parent, TurretAssembly assembly, AssemblyContext context) { IContentCachedPrefab component = GetComponent(model.GetValue <string>("UniqueIdentifier")); ValueAssembler assembler = new ValueAssembler(); GameObject obj = component.Instantiate(); TurretComponent newComponent = obj.GetComponent <TurretComponent>(); if (parent != null) { obj.transform.SetParent(parent.transform); var position = (Vector2)assembler.Assemble(model.GetObject("LocalPosition"), typeof(Vector2), context); obj.transform.localPosition = (Vector3)position + Vector3.back * 0.1f; if (model.HasProperty("Angle")) { obj.transform.localRotation = Quaternion.Euler(0f, 0f, model.GetValue <float>("Angle")); } if (model.HasProperty("Flipped")) { if (model.GetValue <bool>("Flipped")) { newComponent.Flip(); } } TurretComponent parentComponent = parent.GetComponent <TurretComponent>(); foreach (var point in newComponent.AttachmentPoints) { AttachmentSlot slot = FindSlotForPoint(parentComponent.AttachmentSlots.GetSupportingPoints(point), point, obj.transform, parent.transform); if (slot != null) { slot.Attach(newComponent); } } } else { obj.transform.SetParent(assembly.transform); obj.transform.localPosition = Vector3.zero; } foreach (ValueModel child in model.GetArray("Children")) { Assemble(child as ObjectModel, newComponent.transform, assembly, context); } return(newComponent); }