protected virtual void OnComponentRemoved(GameComponentEventArgs <ComponentType> e) { if (!m_IsInitialized) { m_UninitializedComponents.Remove(e.GameComponent); } IUpdateable updatable = e.GameComponent as IUpdateable; if (updatable != null) { m_UpdateableComponents.Remove(updatable); updatable.UpdateOrderChanged -= childUpdateOrderChanged; } Sprite sprite = e.GameComponent as Sprite; if (sprite != null) { m_Sprites.Remove(sprite); sprite.DrawOrderChanged -= childDrawOrderChanged; sprite.Dispose(); } else { IDrawable drawable = e.GameComponent as IDrawable; if (drawable != null) { m_DrawableComponents.Remove(drawable); drawable.DrawOrderChanged -= childDrawOrderChanged; } } // raise the Removed event: if (ComponentRemoved != null) { ComponentRemoved(this, e); } }
protected virtual void OnComponentAdded(GameComponentEventArgs <ComponentType> e) { if (m_IsInitialized) { InitializeComponent(e.GameComponent); } else { m_UninitializedComponents.Add(e.GameComponent); } // If the new component implements IUpdateable: // 1. find a spot for it on the updateable list // 2. hook it's UpdateOrderChanged event IUpdateable updatable = e.GameComponent as IUpdateable; if (updatable != null) { insertSorted(updatable); updatable.UpdateOrderChanged += new EventHandler <EventArgs>(childUpdateOrderChanged); } // If the new component implements IDrawable: // 1. find a spot for it on the drawable lists (IDrawble/Sprite) // 2. hook it's DrawOrderChanged event IDrawable drawable = e.GameComponent as IDrawable; if (drawable != null) { insertSorted(drawable); drawable.DrawOrderChanged += new EventHandler <EventArgs>(childDrawOrderChanged); } // raise the Added event: if (ComponentAdded != null) { ComponentAdded(this, e); } }