Exemplo n.º 1
0
        public IMapGrid CreateGrid(MapId currentMapID, GridId?gridID = null, ushort chunkSize = 16, float snapSize = 1)
        {
            var map = _maps[currentMapID];

            GridId actualID;

            if (gridID != null)
            {
                actualID = gridID.Value;
            }
            else
            {
                actualID = new GridId(HighestGridID.Value + 1);
            }

            if (GridExists(actualID))
            {
                throw new InvalidOperationException($"A map with ID {actualID} already exists");
            }

            if (HighestGridID.Value < actualID.Value)
            {
                HighestGridID = actualID;
            }

            var grid = new MapGrid(this, actualID, chunkSize, snapSize, currentMapID);

            _grids.Add(actualID, grid);
            map.AddGrid(grid);
            OnGridCreated?.Invoke(actualID);
            return(grid);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create the grid.
 /// </summary>
 /// <param name="width">Width in cells.</param>
 /// <param name="height">Height in cells.</param>
 /// <param name="cellSize">Cell size.</param>
 /// <param name="originPosition">Grid origin position.</param>
 /// <param name="updateAlways">Call the event <see cref="OnTileChanged"/> at each tile change.</param>
 /// <param name="nullTileValue">Value to return if a cell is not valid.</param>
 /// <param name="tileConstructor">Function to call when creating a tile.</param>
 /// <returns>False if a value is not valid. True otherwise.</returns>
 public bool CreateGridXY(int width, int height, int cellSize, Vector3 originPosition, bool updateAlways, T nullTileValue, Func <GridXY <T>, int, int, T> tileConstructor)
 {
     if (!CreateGridXY(width, height, cellSize, originPosition, updateAlways, nullTileValue))
     {
         return(false);
     }
     SetAllTiles(tileConstructor);
     OnGridCreated?.Invoke(this, new GridCreationEventArgs {
         width = width, height = height
     });
     return(true);
 }
Exemplo n.º 3
0
    /// <summary>
    /// Create the grid.
    /// </summary>
    /// <param name="width">Width in cells.</param>
    /// <param name="height">Height in cells.</param>
    /// <param name="cellSize">Cell size.</param>
    /// <param name="originPosition">Grid origin position.</param>
    /// <param name="updateAlways">Call the event <see cref="OnTileChanged"/> at each tile change.</param>
    /// <param name="nullTileValue">Value to return if a cell is not valid.</param>
    /// <param name="initializeValue">Value to initialize all the tiles.</param>
    /// <returns>False if a value is not valid. True otherwise.</returns>
    public bool CreateGridXY(int width, int height, int cellSize, Vector3 originPosition, bool updateAlways, T nullTileValue, T initializeValue)
    {
        if (!CreateGridXY(width, height, cellSize, originPosition, updateAlways, nullTileValue))
        {
            return(false);
        }

        SetAllTiles(initializeValue);
        OnGridCreated?.Invoke(this, new GridCreationEventArgs {
            width = width, height = height, cellSize = cellSize
        });
        return(true);
    }
Exemplo n.º 4
0
 public void RaiseOnGridCreated(MapId mapId, GridId gridId)
 {
     OnGridCreated?.Invoke(mapId, gridId);
 }