예제 #1
0
 private void ValidateComponent(GameObjectComponent component)
 {
     if (!component.OwnsThis(owner))
     {
         throw GameObjectComponentException.OwnerException(component);
     }
 }
예제 #2
0
        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();
        }
예제 #3
0
파일: Results.cs 프로젝트: siquel/BeatEmUp
        public ComponentUpdateResults(GameObjectComponent creator, bool wasSuccessfulUpdate)
        {
            if (creator == null)
            {
                throw new ArgumentException("Creator cant be null.");
            }

            this.creator             = creator;
            this.wasSuccessfulUpdate = wasSuccessfulUpdate;
        }
예제 #4
0
        public bool RemoveComponent(GameObjectComponent component)
        {
            if (components.Contains(component))
            {
                sortedDrawableComponents.Remove(component);
                components.Remove(component);

                ComponentRemoved(this, new ComponentRemovedEventArgs(component));

                return(true);
            }

            return(false);
        }
예제 #5
0
        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);
        }
예제 #6
0
파일: Results.cs 프로젝트: siquel/BeatEmUp
 public bool CreatedThis(GameObjectComponent component)
 {
     return(ReferenceEquals(component, creator));
 }
예제 #7
0
 public bool ContainsComponent(GameObjectComponent component)
 {
     return(componentManager.Find <GameObjectComponent>(c => ReferenceEquals(c, component)) != null);
 }
예제 #8
0
 public bool RemoveComponent(GameObjectComponent component)
 {
     return(componentManager.RemoveComponent(component));
 }
예제 #9
0
 public void AddComponent(GameObjectComponent component)
 {
     componentManager.AddComponent(component);
 }
예제 #10
0
 public ComponentRemovedEventArgs(GameObjectComponent removedComponent)
     : base(removedComponent)
 {
 }
예제 #11
0
 public ComponentAddedEventArgs(GameObjectComponent addedComponent)
     : base(addedComponent)
 {
 }
예제 #12
0
 public GameObjectComponentEventArgs(GameObjectComponent component)
     : base()
 {
     this.component = component;
 }