Ejemplo n.º 1
0
        private void RemoveComponentImmediate(GameComponent component)
        {
            if (!Components.ContainsKey(component.GlobalID))
            {
                return;
            }

            Components.Remove(component.GlobalID);
            if (component is IUpdateableComponent)
            {
                var type = component.GetType();
                if (UpdateableComponents.ContainsKey(type))
                {
                    UpdateableComponents[type].Remove(component as IUpdateableComponent);
                }
            }
            if (component is IRenderableComponent)
            {
                RenderableComponents.Remove(component as IRenderableComponent);
            }

            foreach (var child in component.GetAllChildrenRecursive())
            {
                RemoveComponentImmediate(child);
            }
        }
Ejemplo n.º 2
0
 private void AddComponentImmediate(GameComponent component)
 {
     if (Components.ContainsKey(component.GlobalID) && Components[component.GlobalID] != component)
     {
         throw new IndexOutOfRangeException("Component was added that already exists.");
     }
     else if (!Components.ContainsKey(component.GlobalID))
     {
         Components[component.GlobalID] = component;
         if (component is IUpdateableComponent)
         {
             var type = component.GetType();
             if (!UpdateableComponents.ContainsKey(type))
             {
                 UpdateableComponents.Add(type, new List <IUpdateableComponent>());
             }
             UpdateableComponents[type].Add(component as IUpdateableComponent);
         }
         if (component is IRenderableComponent)
         {
             RenderableComponents.Add(component as IRenderableComponent);
         }
     }
 }