Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
        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);
            }
        }
Пример #7
0
        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);
 }
Пример #9
0
 public void AddComponent(MyComponentContainer container, MyComponentBase component)
 {
     m_components.Add(component);
 }
Пример #10
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);
 }
Пример #11
0
 public static void AddComponent(this IMyComponentAggregate aggregate, MyComponentBase component)
 {
     aggregate.ChildList.AddComponent(aggregate.ContainerBase, component);
     component.SetContainer(aggregate.ContainerBase);
     aggregate.AfterComponentAdd(component);
 }
Пример #12
0
 public int GetComponentIndex(MyComponentBase component)
 {
     return(m_components.IndexOf(component));
 }
Пример #13
0
 protected virtual void OnComponentRemoved(Type t, MyComponentBase component)
 {
 }
Пример #14
0
 public void AddComponent(MyComponentBase component)
 {
     m_components.Add(component);
 }