Пример #1
0
 public void AttachComponent(Component component, bool updateIfExist = false, bool active = true)
 {
     component.Active = active;
     int pos = components.GetTypeIndex(0, componentCount - 1, component.GetType());
     if (pos == -1)
     {
         if (Added)
         {
             if (!addedComponents.ContainsInRange(0, addedComponentCount - 1, component))
             {
                 IDictionaryExtension.AddToArray(ref addedComponents, addedComponentCount++, component);
                 ComponentModified = true;
             }
         }
         else
         {
             IDictionaryExtension.AddToArray(ref components, componentCount++, component);
             component.Entity = this;
             component.OnAdded();
         }
     }
     else if (updateIfExist)
     {
         components[pos] = component;
         component.OnAdded();
     }
 }
Пример #2
0
 public void DeattachComponent(Component component)
 {
     for (int i = 0; i < componentCount; i++)
     {
         if (components[i].GetType() == component.GetType())
         {
             if (Added)
             {
                 if (!removedComponents.ContainsInRange(0, removedComponentCount - 1, component))
                 {
                     IDictionaryExtension.AddToArray(ref removedComponents, removedComponentCount++, component);
                     ComponentModified = true;
                 }
             }
             else
             {
                 component.OnRemoved();
                 components.RemoveAt(i, --componentCount);
                 component.Entity = null;
             }
             return;
         }
     }
 }