private void ValidateComponent(GameObjectComponent component) { if (!component.OwnsThis(owner)) { throw GameObjectComponentException.OwnerException(component); } }
public void AddComponent(GameObjectComponent component) { if (component.IsUnique) { if (components.Find(c => c.GetType() == component.GetType()) != null) { throw new ArgumentException("Cant add another unique component."); } } if (components.Contains(component)) { return; } ValidateComponent(component); components.Add(component); ComponentAdded(this, new ComponentAddedEventArgs(component)); components.OrderAllItemsListBy(c => c.UpdateOrder); sortedDrawableComponents = components .Items() .OrderBy(c => c.DrawOrder) .ToList(); }
public ComponentUpdateResults(GameObjectComponent creator, bool wasSuccessfulUpdate) { if (creator == null) { throw new ArgumentException("Creator cant be null."); } this.creator = creator; this.wasSuccessfulUpdate = wasSuccessfulUpdate; }
public bool RemoveComponent(GameObjectComponent component) { if (components.Contains(component)) { sortedDrawableComponents.Remove(component); components.Remove(component); ComponentRemoved(this, new ComponentRemovedEventArgs(component)); return(true); } return(false); }
public IEnumerable <ComponentUpdateResults> Update(GameTime gameTime) { List <ComponentUpdateResults> results = new List <ComponentUpdateResults>(); for (int i = 0; i < components.Count; i++) { if (components[i].Destroyed) { ComponentRemoved(this, new ComponentRemovedEventArgs(components[i])); components.Remove(components[i]); continue; } ComponentUpdateResults result = components[i].Update(gameTime, results); if (ComponentUpdateResults.IsEmpty(result)) { continue; } results.Add(result); } for (int i = 0; i < results.Count; i++) { GameObjectComponent component = components.Find(c => results[i].CreatedThis(c)); if (results[i].BlockNextUpdate) { component.SkipUpdate(); } } return(results); }
public bool CreatedThis(GameObjectComponent component) { return(ReferenceEquals(component, creator)); }
public bool ContainsComponent(GameObjectComponent component) { return(componentManager.Find <GameObjectComponent>(c => ReferenceEquals(c, component)) != null); }
public bool RemoveComponent(GameObjectComponent component) { return(componentManager.RemoveComponent(component)); }
public void AddComponent(GameObjectComponent component) { componentManager.AddComponent(component); }
public ComponentRemovedEventArgs(GameObjectComponent removedComponent) : base(removedComponent) { }
public ComponentAddedEventArgs(GameObjectComponent addedComponent) : base(addedComponent) { }
public GameObjectComponentEventArgs(GameObjectComponent component) : base() { this.component = component; }