/// <summary>
    /// loads new tiles upon zoom
    /// </summary>
    internal IEnumerator LoadNewTiles()
    {
        var centerTile = CustomMap.Instance.CenterTileId;

        yield return(null);

        Vector4 rangeToLoad = _preLoadedRange;

        rangeToLoad /= 2; // just load half of it
        for (int x = (int)(centerTile.X - rangeToLoad.x); x <= (centerTile.X + rangeToLoad.z); x++)
        {
            for (int y = (int)(centerTile.Y - rangeToLoad.y); y <= (centerTile.Y + rangeToLoad.w); y++)
            {
                AddTile(new UnwrappedTileId(_map.Zoom, x, y));
                yield return(null); // stop here and resume at next frame
            }
        }

        if (AtStart)
        {
            GameObject.Find("Toolbar").SetActive(false);
            // this is just a hack. Toolbar element cannot be disabled in Editor before Play
            // since it has many singleton classes attached that needs to be initialized
            // so we allow it to be active but immediately set active to false at start

            InteractibleMap.Instance.PlacementStart(); // allows the user to place the map
        }
        else
        {
            OnAllTilesAdded.Invoke();
        }
    }
 public void LoadBuildingsAfterMapPlaced()   // this is only at the start
 {
     if (AtStart)
     {
         OnAllTilesAdded.Invoke();
         AtStart = false;
     }
 }
    /// <summary>
    /// attempts to load all the tiles that should be visible. If a tile already exists
    /// then it is skipped
    /// </summary>
    /// <returns></returns>
    private IEnumerator addVisibleTiles()
    {
        var centerTileId = CustomMap.Instance.CenterTileId;

        for (int i = centerTileId.X - visibleRange; i <= centerTileId.X + visibleRange; i++)
        {
            for (int j = centerTileId.Y - visibleRange; j <= centerTileId.Y + visibleRange; j++)
            {
                UnwrappedTileId tileToAdd = new UnwrappedTileId(CustomMap.Instance.Zoom, i, j);
                if (InstantiatedTiles.ContainsKey(tileToAdd))
                {
                    continue;
                }
                AddTile(tileToAdd);
                yield return(null);
            }
        }
        OnAllTilesAdded.Invoke();
    }