public static MapChunk GetChunkAt(Vector3 position) { Vector2Int chunkPosition = _.CalculateChunk(position); string coordinate = ChunkRegistry.AsCoordinate(chunkPosition.x, chunkPosition.y); GameObject chunk = _.loadedChunks.SearchChunk($"{Constants.MAP_CHUNK_INSTANCE_NAME}{coordinate}"); if (chunk) { return(chunk.GetComponent <MapChunk>()); } return(null); }
private GameObject LoadChunk(Vector2Int pos) { GameObject chunk = registry.GetChunk(new Vector2Int(pos.x, pos.y)); if (!chunk) { return(null); } string coordinate = ChunkRegistry.AsCoordinate(pos.x, pos.y); GameObject currentChunk = Instantiate(chunk, Vector3.zero, Quaternion.identity); currentChunk.name = $"{Constants.MAP_CHUNK_INSTANCE_NAME}{coordinate}"; return(currentChunk); }