/// <summary> /// Manually add (and activate) the passed Tile to the TilePool. This does not modify /// <see cref="t"/>. To automatically create a Tile according to /// <see cref="TerraConfig"/> call <see cref="CreateTileAt"/> instead. /// </summary> /// <param name="t">Tile to add</param> public void AddTile(Tile t) { if (t != null) { Cache.AddActiveTile(t); } else { Debug.LogWarning("Trying to add Tile that is null."); } }
/// <summary> /// Updates tiles that are surrounding the tracked GameObject /// asynchronously /// </summary> public IEnumerator UpdateTiles() { List <Vector2> nearbyPositions = GetTilePositionsFromRadius(); List <Vector2> newPositions = Cache.GetNewTilePositions(nearbyPositions); //Remove old positions for (int i = 0; i < Cache.ActiveTiles.Count; i++) { bool found = false; foreach (Vector2 nearby in nearbyPositions) { if (Cache.ActiveTiles[i].Position == nearby) //Position found, ignore { found = true; break; } } if (!found) { Cache.CacheTile(Cache.ActiveTiles[i]); Cache.ActiveTiles.RemoveAt(i); i--; } } //Add new positions foreach (Vector2 pos in newPositions) { TerrainTile cached = Cache.GetCachedTileAtPosition(pos); //Attempt to pull from cache, generate if not available if (cached != null) { Cache.AddActiveTile(cached); } else { yield return(AddTileAsync(pos)); } } }