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); }
/// <summary> /// Removes from list, but doesn't change ownership /// </summary> public static void DetachComponent(this IMyComponentAggregate aggregate, MyComponentBase component) { int index = aggregate.ChildList.GetComponentIndex(component); if (index != -1) { aggregate.ChildList.RemoveComponentAt(index); } }
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 void AddComponent(this IMyComponentAggregate aggregate, MyComponentBase component) { Debug.Assert(aggregate != component, "Can not add to itself!"); if (component.ContainerBase != null) { component.OnBeforeRemovedFromContainer(); } aggregate.ChildList.AddComponent(component); component.SetContainer(aggregate.ContainerBase); aggregate.AfterComponentAdd(component); }
public static void GetComponentsFlattened(this IMyComponentAggregate aggregate, List <MyComponentBase> output) { foreach (var child in aggregate.ChildList.Reader) { var childAggregate = child as IMyComponentAggregate; if (childAggregate != null) { childAggregate.GetComponentsFlattened(output); } else { output.Add(child); } } }
public void Remove(Type t, MyComponentBase component) { MyComponentBase storedComponent = null; m_components.TryGetValue(t, out storedComponent); if (storedComponent == null) { System.Diagnostics.Debug.Assert(false, "Removing component from a container, but that container does not contain the component!"); return; } IMyComponentAggregate storedAggregate = storedComponent as IMyComponentAggregate; if (storedAggregate == null) { System.Diagnostics.Debug.Assert(storedComponent == component, "Removing component from a container, but that container does not contain the component!"); RemoveComponentInternal(t, component); } else { bool removed = storedAggregate.RemoveComponent(component); System.Diagnostics.Debug.Assert(removed, "Component could not be removed because it was not present in the container!"); } }
/// <summary> /// Adds to list but doesn't change ownership /// </summary> public static void AttachComponent(this IMyComponentAggregate aggregate, MyComponentBase component) { aggregate.ChildList.AddComponent(aggregate.ContainerBase, component); }
public static void AddComponent(this IMyComponentAggregate aggregate, MyComponentBase component) { aggregate.ChildList.AddComponent(aggregate.ContainerBase, component); component.SetContainer(aggregate.ContainerBase); aggregate.AfterComponentAdd(component); }
/// <summary> /// Adds to list but doesn't change ownership /// </summary> public static void AttachComponent(this IMyComponentAggregate aggregate, MyComponentBase component) { Debug.Assert(aggregate != component, "Can not add to itself!"); aggregate.ChildList.AddComponent(component); }