public void PreviewPlacement(GridPlacement placementData, Vector3 worldPos) { if (placementData.PreviewPlacement) { placementData.CreateNewPreview(); } placementData.PreviewPlacement.transform.position = transform.position + WorldToChunkGrid(worldPos.x, worldPos.y).GetLocalPosition() + new Vector3(0.5f, 0.5f); placementData.EnablePreview(); }
public void PlaceObject(GridPlacement placementData, Vector3 worldPos) { int size = placementData.SelectedFactory.GridSize; if (size == 1) { AddObject(WorldToChunkGrid(worldPos.x, worldPos.y), placementData.Direction, placementData.SelectedFactory); } else if (size == 3) { Position basePos = WorldToChunkGrid(worldPos.x, worldPos.y); Direction dir = placementData.Direction; GridObject north; Position pos = basePos.GetRelativePosition(0, 2); if (pos.Y > Height && NorthNeighbor != null) { pos = pos.GetRelativePosition(0, -Height); north = NorthNeighbor._grid.ContainsKey(pos) ? NorthNeighbor._grid[pos] : null; } else { north = _grid.ContainsKey(pos) ? _grid[pos] : null; } pos = basePos.GetRelativePosition(2, 0); GridObject east = _grid.ContainsKey(pos) ? _grid[pos] : null; pos = basePos.GetRelativePosition(0, -2); GridObject south = _grid.ContainsKey(pos) ? _grid[pos] : null; pos = basePos.GetRelativePosition(-2, 0); GridObject west = _grid.ContainsKey(pos) ? _grid[pos] : null; AddObject(basePos, dir, placementData.SelectedFactory, true, new FactoryNeighbors(north, east, south, west, dir)); FactoryObject factoryObject = _grid[basePos].FactoryObject; AddObject(basePos.GetRelativePosition(0, 1), dir, factoryObject, false); AddObject(basePos.GetRelativePosition(1, 1), dir, null, false); AddObject(basePos.GetRelativePosition(1, 0), dir, factoryObject, false); AddObject(basePos.GetRelativePosition(1, -1), dir, null, false); AddObject(basePos.GetRelativePosition(0, -1), dir, factoryObject, false); AddObject(basePos.GetRelativePosition(-1, -1), dir, null, false); AddObject(basePos.GetRelativePosition(-1, 0), dir, factoryObject, false); AddObject(basePos.GetRelativePosition(-1, 1), dir, null, false); //List<GridObject> northNeighbors = new List<GridObject> {_grid[basePos.GetRelativePosition(-1, 2)], _grid[basePos.GetRelativePosition(0, 2)], _grid[basePos.GetRelativePosition(1, 2)]}; //List<GridObject> eastNeighbors = new List<GridObject> {_grid[basePos.GetRelativePosition(2, -1)], _grid[basePos.GetRelativePosition(2, 0)], _grid[basePos.GetRelativePosition(2, 1)]}; //List<GridObject> southNeighbors = new List<GridObject> {_grid[basePos.GetRelativePosition(-1, -2)], _grid[basePos.GetRelativePosition(0, -2)], _grid[basePos.GetRelativePosition(1, -2)]}; //List<GridObject> westNeighbors = new List<GridObject> {_grid[basePos.GetRelativePosition(-2, -1)], _grid[basePos.GetRelativePosition(-2, 0)], _grid[basePos.GetRelativePosition(-2, 1)]}; } }