public static void RemoveComponent(this IMyComponentAggregate aggregate, MyComponentBase component) { int index = aggregate.ChildList.GetComponentIndex(component); if (index != -1) { aggregate.BeforeComponentRemove(component); component.SetContainer(null); aggregate.ChildList.RemoveComponentAt(index); } }
public static bool RemoveComponent(this IMyComponentAggregate aggregate, MyComponentBase component) { int index = aggregate.ChildList.GetComponentIndex(component); if (index != -1) { aggregate.BeforeComponentRemove(component); component.SetContainer(null); aggregate.ChildList.RemoveComponentAt(index); return true; } foreach (var child in aggregate.ChildList.Reader) { var childAggregate = child as IMyComponentAggregate; if (childAggregate == null) continue; bool removed = childAggregate.RemoveComponent(component); if (removed) return true; } return false; }