Ejemplo n.º 1
0
        private void OnWorldContextUnregistered(object sender, WorldContextEventArgs e)
        {
            var worldContext  = e.WorldContext;
            var entityManager = worldContext.EntityManager;

            var loadedEntities = entityManager.Where(ent => _loadedEntities.Contains(ent));

            RemoveEntities(loadedEntities);

            entityManager.EntitySpawned -= OnEntitySpawned;
            entityManager.EntityRemoved -= OnEntityRemoved;
        }
Ejemplo n.º 2
0
        private void OnWorldContextRegistered(object sender, WorldContextEventArgs e)
        {
            var chunkManager = _world.ChunkManager;

            var worldContext  = e.WorldContext;
            var entityManager = worldContext.EntityManager;

            foreach (var entity in entityManager)
            {
                var chunkPosition = ChunkPosition.FromWorld(entity.Position);
                if (chunkManager.IsLoaded(chunkPosition))
                {
                    SpawnEntity(entity);
                }
            }

            entityManager.EntitySpawned += OnEntitySpawned;
            entityManager.EntityRemoved += OnEntityRemoved;
        }