public void RemoveEntityById(uint entityId, bool dispose = true) { VisualDynamicEntity entity; if (_dynamicEntitiesDico.TryGetValue(entityId, out entity)) { ModelAndInstances instances; if (!_models.TryGetValue(entity.VoxelEntity.ModelInstance.VoxelModel.Name, out instances)) { throw new InvalidOperationException("we have no such model"); } instances.Instances.Remove(entityId); VisualDynamicEntity visualEntity = _dynamicEntitiesDico[entityId]; DynamicEntities.Remove(_dynamicEntitiesDico[entityId]); _dynamicEntitiesDico.Remove(entityId); visualEntity.DynamicEntity.HealthStateChanged -= EntityHealthStateChanged; entity.DynamicEntity.HealthChanged -= entity_HealthChanged; visualEntity.DynamicEntity.AfflictionStateChanged -= EntityAfflictionStateChanged; if (dispose) { visualEntity.Dispose(); } OnEntityRemoved(new DynamicEntityEventArgs { Entity = visualEntity.DynamicEntity }); } }
public void RemoveEntity(ICharacterEntity entity) { if (_dynamicEntitiesDico.ContainsKey(entity.DynamicId)) { ModelAndInstances instances; if (!_models.TryGetValue(entity.ModelInstance.VoxelModel.Name, out instances)) { throw new InvalidOperationException("we have no such model"); } instances.Instances.Remove(entity.DynamicId); VisualDynamicEntity visualEntity = _dynamicEntitiesDico[entity.DynamicId]; DynamicEntities.Remove(visualEntity); _dynamicEntitiesDico.Remove(entity.DynamicId); entity.HealthStateChanged -= EntityHealthStateChanged; entity.HealthChanged -= entity_HealthChanged; entity.AfflictionStateChanged -= EntityAfflictionStateChanged; visualEntity.Dispose(); OnEntityRemoved(new DynamicEntityEventArgs { Entity = entity }); } }