private void Add(Type type, MyComponentBase component) { MyComponentBase containedComponent; if (m_components.TryGetValue(type, out containedComponent)) { if (containedComponent is IMyComponentAggregate) { (containedComponent as IMyComponentAggregate).AddComponent(component); return; } else if (component is IMyComponentAggregate) { Remove(type); (component as IMyComponentAggregate).AddComponent(containedComponent); m_components[type] = component; component.SetContainer(this); OnComponentAdded(type, component); return; } } Remove(type); if (component != null) { m_components[type] = component; component.SetContainer(this); OnComponentAdded(type, component); } }
public void Add(Type type, MyComponentBase component) { System.Diagnostics.Debug.Assert(typeof(MyComponentBase).IsAssignableFrom(type), "Unsupported type of component!"); if (!typeof(MyComponentBase).IsAssignableFrom(type)) { return; } MyComponentBase containedComponent; if (m_components.TryGetValue(type, out containedComponent)) { if (containedComponent is IMyComponentAggregate) { (containedComponent as IMyComponentAggregate).AddComponent(component); return; } else if (component is IMyComponentAggregate) { Remove(type); (component as IMyComponentAggregate).AddComponent(containedComponent); m_components[type] = component; component.SetContainer(this); OnComponentAdded(type, component); return; } } Remove(type); if (component != null) { m_components[type] = component; component.SetContainer(this); OnComponentAdded(type, component); } }
/// <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); } }
protected override void OnComponentRemoved(Type t, MyComponentBase component) { base.OnComponentRemoved(t, component); var entityComponent = component as MyEntityComponentBase; var handler = ComponentRemoved; if (handler != null && entityComponent != null) { handler(t, entityComponent); } }
protected override void OnComponentAdded(Type t, MyComponentBase component) { base.OnComponentAdded(t, component); var entityComponent = component as MyEntityComponentBase; Debug.Assert(entityComponent != null, "The component added to the entity component container was not derived from MyEntityComponentBase!"); var handler = ComponentAdded; if (handler != null && entityComponent != null) { handler(t, entityComponent); } }
public static MyObjectBuilder_ComponentBase CreateObjectBuilder(MyComponentBase instance) { var objectBuilder = m_objectFactory.CreateObjectBuilder <MyObjectBuilder_ComponentBase>(instance); //if (objectBuilder == null) //{ // var baseType = instance.GetType().BaseType; // while (baseType != null && baseType != typeof(object) && objectBuilder == null) // { // objectBuilder = m_objectFactory.CreateObjectBuilder<MyObjectBuilder_ComponentBase>(baseType); // baseType = baseType.BaseType; // } //} return(objectBuilder); }
public bool RemoveComponent(MyComponentBase component) { if (m_components.Remove(component)) { return(true); } foreach (var childComponent in m_components) { if (childComponent is IMyComponentAggregate) { if ((childComponent as IMyComponentAggregate).ChildList.RemoveComponent(component)) { return(true); } } } return(false); }
public void AddComponent(MyComponentContainer container, MyComponentBase component) { m_components.Add(component); }
/// <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); }
public int GetComponentIndex(MyComponentBase component) { return(m_components.IndexOf(component)); }
protected virtual void OnComponentRemoved(Type t, MyComponentBase component) { }
public void AddComponent(MyComponentBase component) { m_components.Add(component); }