/// <summary> /// Adds an entity to the corrisponding chunk /// </summary> /// <param name="entity">The entity to add to a chunk</param> public void AddEntity(ZettaEntity entity) { var chunkToAdd = GetOrCreateChunk(entity.CalculatedChunkPosition); chunkToAdd.Add(entity); // Load more chunks when the entity has been added LoadChunks(chunkToAdd.position, SettingsController.CHUNK_RENDER_DISTANCE); }
/// <summary> /// Changes an entity's chunk it is in /// </summary> /// <param name="entity">The entity to change chunk</param> /// <param name="toChunk">The chunk to change to</param> public void HopChunk(ZettaEntity entity, Vector2Int toChunk) { // Changing chunks var currentChunk = GetOrCreateChunk(entity.ChunkPosition); var nextChunk = GetOrCreateChunk(toChunk); currentChunk.Remove(entity); nextChunk.Add(entity); // Fire chunk changed event EntityChangedChunk?.Invoke(entity); // Unload the unused chunks int side = GetSide(currentChunk.position, toChunk); UnloadUnusedChunks(toChunk, SettingsController.CHUNK_RENDER_DISTANCE, side); // Load new chunks LoadChunks(toChunk, SettingsController.CHUNK_RENDER_DISTANCE); }
public void RemoveEntity(ZettaEntity entity) { var chunkToRemove = GetOrCreateChunk(entity.CalculatedChunkPosition); chunkToRemove.Remove(entity); }