Beispiel #1
0
        public ComponentSystem(EntityPool entities, params Type [] types)
        {
            if (types.Any(t => !t.IsComponent()))
            {
                throw new Exception("Type passed is not of type Component.");
            }

            compatibleTypes = new List <Type> ();
            compatibleTypes.AddRange(types);

            entities.OnEntityAdded   += EntitiesChanged;
            entities.OnEntityRemoved += EntitiesChanged;

            entities.OnEntityComponentAdded   += EntitiesChanged;
            entities.OnEntityComponentRemoved += EntitiesChanged;

            Entities = new List <Entity> ();
            Entities.AddRange(GetCompatibleEntities(entities));

            MGame.CurrentScene.Systems.Add(this);
        }
Beispiel #2
0
 public Entity(string name)
 {
     Name      = name;
     OwnerPool = MGame.CurrentScene.Entities;
     MGame.CurrentScene.RegisterEntity(this);
 }
Beispiel #3
0
 /// <summary>
 /// When entities get changed refresh the entities list again.
 /// </summary>
 protected virtual void EntitiesChanged(EntityPool entities, Entity entity)
 {
     Entities.Clear();
     Entities.AddRange(GetCompatibleEntities(entities));
 }