コード例 #1
0
 /// <summary>
 /// Removes all IComponents from the managers, that belong to a specific entity
 /// This method is called when an entity is destroyed
 /// </summary>
 /// <param name="entityID">UID of the entity owner of the components</param>
 public void RemoveComponents(int entityID)
 {
     ComponentManager manager;
     IComponent component;
     //Checks all managers to see where the entity has components associated 
     for (int i = 0; i < managersLists.Count; i++)
     {
         manager = managersLists[i];
         for (int j = 0; j < manager.components.Count; j++)
         {
             component = manager.components[j];
             if (component.Owner.UID == entityID)
             {
                 //Check if component is drawable -> unregister it
                 IVisible drawable = component as IVisible;
                 if (drawable != null)
                 {
                     renderer.UnregisterDrawble(drawable);
                 }
                 //Check if component is collidable -> unregister it
                 ICollidable collidable = component as ICollidable;
                 if (collidable != null)
                 {
                     collisionManager.UnregisterCollidable(collidable);
                 }
                 //When a component associated with the entity is found remove it from the manager
                 manager.components.Remove(component);
             }
         }               
     }
 }