public static void RemoveEntities(this IEntityCollectionManager entityCollectionManager, IEnumerable <IEntity> entities)
 {
     foreach (var entity in entities)
     {
         RemoveEntity(entityCollectionManager, entity);
     }
 }
 public static void RemoveEntities(this IEntityCollectionManager entityCollectionManager, params IEntity[] entities)
 {
     for (var i = 0; i < entities.Length; i++)
     {
         RemoveEntity(entityCollectionManager, entities[i]);
     }
 }
 public GameBoardViewResolver(IEventSystem eventSystem, IEntityCollectionManager collectionManager,
                              IUnityInstantiator instantiator, FloorTiles floorTiles, OuterWallTiles outerWallTiles)
     : base(eventSystem, collectionManager, instantiator)
 {
     _floorTiles     = floorTiles;
     _outerWallTiles = outerWallTiles;
 }
        public void GlobalSetup()
        {
            var componentTypeAssigner = new DefaultComponentTypeAssigner();
            var allComponents         = componentTypeAssigner.GenerateComponentLookups();
            var componentLookup       = new ComponentTypeLookup(allComponents);

            _availableComponents = allComponents.Keys
                                   .Select(x => Activator.CreateInstance(x) as IComponent)
                                   .ToArray();

            var componentDatabase   = new ComponentDatabase(componentLookup);
            var componentRepository = new ComponentRepository(componentLookup, componentDatabase);

            var entityFactory          = new DefaultEntityFactory(new IdPool(), componentRepository);
            var poolFactory            = new DefaultEntityCollectionFactory(entityFactory);
            var observableGroupFactory = new DefaultObservableObservableGroupFactory();

            _entityCollectionManager = new EntityCollectionManager(poolFactory, observableGroupFactory, componentLookup);

            _availableComponents = _groupFactory.GetComponentTypes
                                   .Select(x => Activator.CreateInstance(x) as IComponent)
                                   .ToArray();

            _testGroups = _groupFactory.CreateTestGroups().ToArray();

            foreach (var group in _testGroups)
            {
                _entityCollectionManager.GetObservableGroup(group);
            }

            _defaultEntityCollection = _entityCollectionManager.GetCollection();
        }
Example #5
0
        public static void RemoveEntities(this IEntityCollectionManager entityCollectionManager,
                                          Func <IEntity, bool> predicate)
        {
            var matchingEntities = entityCollectionManager.Collections.SelectMany(x => x).Where(predicate).ToArray();

            RemoveEntities(entityCollectionManager, matchingEntities);
        }
Example #6
0
        public SceneManager(IEntityCollectionManager collectionManager, UIManager uiManager)
        {
            sceneEntities = new Dictionary <string, IEntity>();
            scenes        = new List <string>();

            var defaultCollection = collectionManager.GetCollection();

            SceneLoadedAsObservable().Subscribe(arg =>
            {
                scenes.Add(arg.Scene.name);
                var entity         = defaultCollection.CreateEntity();
                var sceneComponent = new SceneComponent {
                    Scene = arg.Scene
                };
                entity.AddComponents(sceneComponent);
                sceneEntities.Add(new KeyValuePair <string, IEntity>(arg.Scene.name, entity));
            }).AddTo(disposables);

            SceneUnloadedAsObservable().Subscribe(scene =>
            {
                if (sceneEntities.ContainsKey(scene.name))
                {
                    scenes.Remove(scene.name);
                    defaultCollection.RemoveEntity(sceneEntities[scene.name].Id);
                    sceneEntities.Remove(scene.name);
                    uiManager.CurrentScreen.Value = null;
                }
            }).AddTo(disposables);
        }
Example #7
0
 public ReactToDataSystemHandler(IEntityCollectionManager entityCollectionManager)
 {
     EntityCollectionManager = entityCollectionManager;
     SystemSubscriptions     = new Dictionary <ISystem, IDisposable>();
     EntitySubscriptions     = new Dictionary <ISystem, IDictionary <int, IDisposable> >();
     processEntityMethod     = GetType().GetMethod(nameof(ProcessEntity));
 }
 public ReactToDataSystemHandler(IEntityCollectionManager entityCollectionManager)
 {
     EntityCollectionManager = entityCollectionManager;
     _systemSubscriptions    = new Dictionary <ISystem, IDisposable>();
     _entitySubscriptions    = new Dictionary <ISystem, IDictionary <Guid, IDisposable> >();
     _processEntityMethod    = GetType().GetMethod("ProcessEntity");
 }
Example #9
0
 public UIManager(IEntityCollectionManager collectionManager, IEventSystem eventSystem)
 {
     CurrentScreen      = new ReactiveProperty <IEntity>();
     defaultConllection = collectionManager.GetCollection();
     this.eventSystem   = eventSystem;
     uiGroup            = collectionManager.GetObservableGroup(new Group(typeof(UIComponent)));
 }
 public static void RemoveEntitiesContaining(this IEntityCollectionManager entityCollectionManager, params Type[] components)
 {
     foreach (var pool in entityCollectionManager.Collections)
     {
         pool.RemoveEntitiesContaining(components);
     }
 }
 public BulletViewResolver(IEventSystem eventSystem,
                           IEntityCollectionManager collectionManager,
                           IUnityInstantiator instantiator,
                           GameObject bulletPrefab) : base(eventSystem, collectionManager, instantiator)
 {
     _bulletPrefab = bulletPrefab;
 }
Example #12
0
 public static void RemoveEntities(this IEntityCollectionManager entityCollectionManager,
                                   params IEntity[] entities)
 {
     foreach (var entity in entities)
     {
         RemoveEntity(entityCollectionManager, entity);
     }
 }
        public DespawnAllBulletsEventSystem(IEventSystem eventSystem,
                                            IEntityCollectionManager entityCollectionManager) : base(eventSystem)
        {
            _entityCollectionManager = entityCollectionManager;

            _group           = new Group(typeof(BulletComponent), typeof(ViewComponent));
            _observableGroup = entityCollectionManager.GetObservableGroup(_group);
        }
Example #14
0
 public SpriteBatchSystemHandler(IEntityCollectionManager entityCollectionManager, IEcsRxGraphicsDevice graphicsDevice, IRenderTarget2dRegistry renderTarget2dRegistry, IGameScheduler scheduler)
 {
     EntityCollectionManager = entityCollectionManager;
     _systemSubscriptions    = new Dictionary <ISystem, IDisposable>();
     _graphicsDevice         = graphicsDevice;
     _gameScheduler          = scheduler;
     _renderTarget2dRegistry = renderTarget2dRegistry;
 }
Example #15
0
        private SystemExecutor CreateExecutor(IEntityCollectionManager entityCollectionManager)
        {
            var reactsToEntityHandler = new ReactToEntitySystemHandler(entityCollectionManager);
            var reactsToGroupHandler  = new ReactToGroupSystemHandler(entityCollectionManager);
            var reactsToDataHandler   = new ReactToDataSystemHandler(entityCollectionManager);
            var manualSystemHandler   = new ManualSystemHandler(entityCollectionManager);
            var setupHandler          = new SetupSystemHandler(entityCollectionManager);

            var conventionalSystems = new List <IConventionalSystemHandler>
            {
                setupHandler,
                reactsToEntityHandler,
                reactsToGroupHandler,
                reactsToDataHandler,
                manualSystemHandler
            };

            return(new SystemExecutor(conventionalSystems));
        }
Example #16
0
        protected EcsRxApplication()
        {
            // For sending events around
            EventSystem = new EventSystem(new MessageBroker());

            // For mapping component types to underlying indexes
            var componentTypeAssigner = new DefaultComponentTypeAssigner();
            var allComponents         = componentTypeAssigner.GenerateComponentLookups();

            var componentLookup = new ComponentTypeLookup(allComponents);
            // For interacting with the component databases
            var componentDatabase   = new ComponentDatabase(componentLookup);
            var componentRepository = new ComponentRepository(componentLookup, componentDatabase);

            // For creating entities, collections, observable groups and managing Ids
            var entityFactory           = new DefaultEntityFactory(new IdPool(), componentRepository);
            var entityCollectionFactory = new DefaultEntityCollectionFactory(entityFactory);
            var observableGroupFactory  = new DefaultObservableObservableGroupFactory();

            EntityCollectionManager = new EntityCollectionManager(entityCollectionFactory, observableGroupFactory, componentLookup);

            // All system handlers for the system types you want to support
            var reactsToEntityHandler = new ReactToEntitySystemHandler(EntityCollectionManager);
            var reactsToGroupHandler  = new ReactToGroupSystemHandler(EntityCollectionManager);
            var reactsToDataHandler   = new ReactToDataSystemHandler(EntityCollectionManager);
            var manualSystemHandler   = new ManualSystemHandler(EntityCollectionManager);
            var setupHandler          = new SetupSystemHandler(EntityCollectionManager);
            var teardownHandler       = new TeardownSystemHandler(EntityCollectionManager);

            var conventionalSystems = new List <IConventionalSystemHandler>
            {
                setupHandler,
                teardownHandler,
                reactsToEntityHandler,
                reactsToGroupHandler,
                reactsToDataHandler,
                manualSystemHandler
            };

            // The main executor which manages how systems are given information
            SystemExecutor = new SystemExecutor(conventionalSystems);
        }
        public void GlobalSetup()
        {
            _eventSystem = new EventSystem(new MessageBroker());

            var entityFactory        = new DefaultEntityFactory(_eventSystem);
            var poolFactory          = new DefaultEntityCollectionFactory(entityFactory, _eventSystem);
            var groupAccessorFactory = new DefaultObservableObservableGroupFactory(_eventSystem);

            _entityCollectionManager = new EntityCollectionManager(_eventSystem, poolFactory, groupAccessorFactory);

            _availableComponents = _groupFactory.GetComponentTypes
                                   .Select(x => Activator.CreateInstance(x) as IComponent)
                                   .ToArray();

            _testGroups = _groupFactory.CreateTestGroups().ToArray();

            foreach (var group in _testGroups)
            {
                _entityCollectionManager.CreateObservableGroup(group);
            }

            _defaultEntityCollection = _entityCollectionManager.GetCollection();
        }
Example #18
0
 public DefaultViewResolver(IEntityCollectionManager collectionManager, IEventSystem eventSystem, IUnityInstantiator instantiator)
     : base(collectionManager, eventSystem, instantiator)
 {
 }
Example #19
0
 public FoodPickupSystem(IEventSystem eventSystem, IEntityCollectionManager entityCollectionManager) : base(eventSystem)
 {
     _entityCollectionManager = entityCollectionManager;
 }
Example #20
0
 public SpawnerSystem(IEntityCollectionManager collectionManager)
 {
     DefaultCollection = collectionManager.GetCollection();
 }
Example #21
0
 public ReactToEntitySystemHandler(IEntityCollectionManager entityCollectionManager)
 {
     EntityCollectionManager = entityCollectionManager;
     _systemSubscriptions    = new Dictionary <ISystem, IDisposable>();
     _entitySubscriptions    = new Dictionary <ISystem, IDictionary <int, IDisposable> >();
 }
Example #22
0
 public AudioManager(IEntityCollectionManager collectionManager)
 {
     defaultCollection = collectionManager.GetCollection();
 }
 public static IEntity GetEntity(this IEntityCollectionManager entityCollectionManager, int id)
 {
     return(entityCollectionManager.Collections
            .Select(collection => collection.GetEntity(id))
            .FirstOrDefault(possibleEntity => possibleEntity != null));
 }
 public ShootBulletEventSystem(IEntityCollectionManager entityCollectionManager, IEventSystem eventSystem) :
     base(eventSystem)
 {
     _defaultCollection = entityCollectionManager.GetCollection();
 }
 protected DynamicViewResolverSystem(IEventSystem eventSystem, IEntityCollectionManager collectionManager, IUnityInstantiator instantiator)
 {
     EventSystem       = eventSystem;
     CollectionManager = collectionManager;
     Instantiator      = instantiator;
 }
        public static void RemoveEntity(this IEntityCollectionManager entityCollectionManager, IEntity entity)
        {
            var containingPool = entityCollectionManager.GetCollectionFor(entity);

            containingPool.RemoveEntity(entity.Id);
        }
Example #27
0
 public AssetBundlePrefabViewResolverSystem(IEntityCollectionManager collectionManager, IUnityInstantiator instantiator, IResourceLoader resourceLoader) : base(collectionManager, instantiator)
 {
     this.resourceLoader = resourceLoader;
 }
 public static IEntityCollection GetCollectionFor(this IEntityCollectionManager entityCollectionManager, IEntity entity)
 {
     return(entityCollectionManager.Collections.SingleOrDefault(x => x.ContainsEntity(entity.Id)));
 }
 public WallViewResolver(IEventSystem eventSystem, IEntityCollectionManager collectionManager, IUnityInstantiator instantiator, WallTiles wallTiles)
     : base(eventSystem, collectionManager, instantiator)
 {
     _wallTiles = wallTiles;
 }
 /// <inheritdoc />
 public PickedFoodCanvasViewResolvers(PrefabCollection prefabs, IUnityInstantiator instantiator, IEntityCollectionManager collectionManager, IEventSystem eventSystem) : base(instantiator, collectionManager, eventSystem)
 {
     PrefabTemplate = prefabs[PrefabEnum.PickedFoodCanvas];
     _parent        = new GameObject($"{PrefabTemplate.name}Pool");
 }