private void PaintCell(Vector3Int position, Tilemap tilemap, BrushCell cell) { if (cell.tile != null) { SetTilemapCell(tilemap, position, cell.tile, cell.matrix, cell.color); } }
private void PaintCell(GridLayout grid, Vector3Int position, BrushCell cell) { if (cell.gridTile != null) { GridManager.Instance.InstantiateGridTile(cell.gridTile, position.ToVector2IntXY(), cell.height, cell.offset, cell.orientation); } }
private void PaintCell(GridLayout grid, Vector3Int position, BrushCell cell) { if (cell.gridObject != null) { GridManager.Instance.InstantiateGridObject(cell.gridObject, position.ToVector2IntXY(), cell.orientation); } }
public override void MoveEnd(GridLayout gridLayout, GameObject brushTarget, BoundsInt position) { if (brushTarget == null || gridLayout == null) { return; } // Do not allow editing palettes if (brushTarget.layer == 31) { return; } // Settings for the loop var relativePos = position.min - m_MoveStartPos; var startX = relativePos.x > 0 ? position.size.x - 1 : 0; var endX = relativePos.x > 0 ? 0 : position.size.x - 1; var actionX = relativePos.x > 0 ? -1 : 1; var startY = relativePos.y > 0 ? position.size.y - 1 : 0; var endY = relativePos.y > 0 ? 0 : position.size.y - 1; var actionY = relativePos.y > 0 ? -1 : 1; var x = startX; var y = startY; //Debug.Log("startX: " + startX.ToString() + " endX: " + endX.ToString() + " actionX: " + actionX.ToString()); //Debug.Log("startY: " + startY.ToString() + " endY: " + endY.ToString() + " actionY: " + actionY.ToString()); // Loop through positions within the bounds based on the direction while (true) { while (true) { var local = new Vector3Int(x, y, 0); var location = local + position.position; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; if (cell != null && cell.gridTile != null) { GridManager.Instance.MoveTileToPosition(cell.gridTile, location.ToVector2IntXY(), cell.offset); } if (x == endX) { break; } x += actionX; } if (y == endY) { break; } y += actionY; x = startX; } ResetPick(); }
public void SetCellFromEditor(Vector3Int brushPosition, GridObject gridObject, Orientations orientation) { Reset(); SetGridObject(brushPosition, gridObject); SetOrientation(brushPosition, orientation); m_EditorCell = new BrushCell(); m_EditorCell.gridObject = gridObject; m_EditorCell.orientation = orientation; }
private void SizeUpdated() { m_Cells = new BrushCell[m_Size.x * m_Size.y * m_Size.z]; BoundsInt bounds = new BoundsInt(Vector3Int.zero, m_Size); foreach (Vector3Int pos in bounds.allPositionsWithin) { m_Cells[GetCellIndex(pos)] = new BrushCell(); } }
/// <summary> /// Box fills GameObjects into given bounds within the selected layers. /// The GameObjectBrush overrides this to provide GameObject box-filling functionality. /// </summary> /// <param name="gridLayout">Grid to box fill data to.</param> /// <param name="brushTarget">Target of the box fill operation. By default the currently selected GameObject.</param> /// <param name="position">The bounds to box fill data into.</param> public override void BoxFill(GridLayout gridLayout, GameObject brushTarget, BoundsInt position) { GetGrid(ref gridLayout, ref brushTarget); foreach (Vector3Int location in position.allPositionsWithin) { Vector3Int local = location - position.min; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; PaintCell(gridLayout, location, brushTarget != null ? brushTarget.transform : null, cell); } }
internal void SizeUpdated(bool keepContents = false) { Array.Resize(ref m_Cells, sizeCount); BoundsInt bounds = new BoundsInt(Vector3Int.zero, m_Size); foreach (Vector3Int pos in bounds.allPositionsWithin) { if (keepContents || m_Cells[GetCellIndex(pos)] == null) { m_Cells[GetCellIndex(pos)] = new BrushCell(); } } }
private void SizeUpdated() { var cellSize = m_Size.x * m_Size.y * m_Size.z; m_Cells = new BrushCell[cellSize]; m_TileChangeDataList = new List <TileChangeData>(cellSize); BoundsInt bounds = new BoundsInt(Vector3Int.zero, m_Size); foreach (Vector3Int pos in bounds.allPositionsWithin) { m_Cells[GetCellIndex(pos)] = new BrushCell(); } }
/// <summary>Box fills tiles and GameObjects into given bounds within the selected layers.</summary> /// <param name="gridLayout">Grid to box fill data to.</param> /// <param name="brushTarget">Target of the box fill operation. By default the currently selected GameObject.</param> /// <param name="position">The bounds to box fill data into.</param> public override void BoxFill(GridLayout gridLayout, GameObject brushTarget, BoundsInt position) { if (brushTarget == null) { return; } Tilemap map = brushTarget.GetComponent <Tilemap>(); if (map == null) { return; } int count = 0; var listSize = position.size.x * position.size.y * position.size.z; if (m_TileChangeDataList == null || m_TileChangeDataList.Capacity != listSize) { m_TileChangeDataList = new List <TileChangeData>(listSize); } m_TileChangeDataList.Clear(); foreach (Vector3Int location in position.allPositionsWithin) { Vector3Int local = location - position.min; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; if (cell.tile == null) { continue; } var tcd = new TileChangeData { position = location, tile = cell.tile, transform = cell.matrix, color = cell.color }; m_TileChangeDataList.Add(tcd); count++; } // Duplicate empty slots in the list, as ExtractArrayFromListT returns full list if (0 < count && count < listSize) { var tcd = m_TileChangeDataList[count - 1]; for (int i = count; i < listSize; ++i) { m_TileChangeDataList.Add(tcd); } } var tileChangeData = NoAllocHelpers.ExtractArrayFromListT(m_TileChangeDataList); map.SetTiles(tileChangeData, false); }
public void SetCellFromEditor(Vector3Int brushPosition, GridTile gridTile, int height, Vector3 offSet, Quaternion orientation) { Reset(); SetGridTile(brushPosition, gridTile); SetHeight(brushPosition, height); SetOffset(brushPosition, offSet); SetOrientation(brushPosition, orientation); m_EditorCell = new BrushCell(); m_EditorCell.gridTile = gridTile; m_EditorCell.height = height; m_EditorCell.offset = offSet; m_EditorCell.orientation = orientation; }
public override void BoxFill(GridLayout gridLayout, GameObject brushTarget, BoundsInt position) { if (brushTarget == null) { return; } Tilemap map = brushTarget.GetComponent <Tilemap>(); foreach (Vector3Int location in position.allPositionsWithin) { Vector3Int local = location - position.min; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; PaintCell(location, map, cell); } }
/// <summary> /// Box fills GameObjects into given bounds within the selected layers. /// The GameObjectBrush overrides this to provide GameObject box-filling functionality. /// </summary> /// <param name="gridLayout">Grid to box fill data to.</param> /// <param name="brushTarget">Target of the box fill operation. By default the currently selected GameObject.</param> /// <param name="position">The bounds to box fill data into.</param> public override void BoxFill(GridLayout gridLayout, GameObject brushTarget, BoundsInt position) { if (brushTarget == hiddenGrid) { brushTarget = null; } // Do not allow editing palettes else if (brushTarget != null && brushTarget.layer == 31) { return; } foreach (Vector3Int location in position.allPositionsWithin) { Vector3Int local = location - position.min; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; PaintCell(gridLayout, location, brushTarget != null ? brushTarget.transform : null, cell); } }
/// <summary>Box fills tiles and GameObjects into given bounds within the selected layers.</summary> /// <param name="gridLayout">Grid to box fill data to.</param> /// <param name="brushTarget">Target of the box fill operation. By default the currently selected GameObject.</param> /// <param name="position">The bounds to box fill data into.</param> public override void BoxFill(GridLayout gridLayout, GameObject brushTarget, BoundsInt position) { if (brushTarget == null) { return; } Tilemap map = brushTarget.GetComponent <Tilemap>(); if (map == null) { return; } locations.Clear(); tiles.Clear(); foreach (Vector3Int location in position.allPositionsWithin) { Vector3Int local = location - position.min; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; if (cell.tile == null) { continue; } locations.Add(location); tiles.Add(cell.tile); } map.SetTiles((Vector3Int[])locations.ToArray(typeof(Vector3Int)), (TileBase[])tiles.ToArray(typeof(TileBase))); foreach (Vector3Int location in position.allPositionsWithin) { Vector3Int local = location - position.min; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; if (cell.tile == null) { continue; } map.SetTransformMatrix(location, cell.matrix); map.SetColor(location, cell.color); } }
public override void BoxFill(GridLayout gridLayout, UnityEngine.GameObject brushTarget, BoundsInt position) { // Do not allow editing palettes if (brushTarget.layer == 31) { return; } if (brushTarget == null) { return; } foreach (Vector3Int location in position.allPositionsWithin) { Vector3Int local = location - position.min; BrushCell cell = m_Cells[GetCellIndexWrapAround(local.x, local.y, local.z)]; PaintCell(gridLayout, location, brushTarget.transform, cell); } }
private void PaintCell(GridLayout grid, Vector3Int position, Transform parent, BrushCell cell) { if (cell.gameObject != null) { SetSceneCell(grid, parent, position, cell.gameObject, cell.offset, cell.scale, cell.orientation, m_Anchor); } }
public void ClearCellFromEditor() { ResetPick(); m_EditorCell = null; }
private void PaintCell(GridLayout grid, Vector3Int position, Transform parent, BrushCell cell) { if (cell.gameObject == null) { return; } var existingGO = GetObjectInCell(grid, parent, position); if (existingGO == null) { SetSceneCell(grid, parent, position, cell.gameObject, cell.offset, cell.scale, cell.orientation, m_Anchor); } }