Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
/// <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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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!");
            }
        }
Exemplo n.º 7
0
 /// <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);
 }
Exemplo n.º 8
0
 public static void AddComponent(this IMyComponentAggregate aggregate, MyComponentBase component)
 {
     aggregate.ChildList.AddComponent(aggregate.ContainerBase, component);
     component.SetContainer(aggregate.ContainerBase);
     aggregate.AfterComponentAdd(component);
 }
Exemplo n.º 9
0
 /// <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);
 }