public override void Rotate(RotationDirection direction, UnityEngine.Grid.CellLayout layout) { Vector3Int oldSize = m_Size; BrushCell[] oldCells = m_Cells.Clone() as BrushCell[]; size = new Vector3Int(oldSize.y, oldSize.x, oldSize.z); BoundsInt oldBounds = new BoundsInt(Vector3Int.zero, oldSize); foreach (Vector3Int oldPos in oldBounds.allPositionsWithin) { int newX = direction == RotationDirection.Clockwise ? oldSize.y - oldPos.y - 1 : oldPos.y; int newY = direction == RotationDirection.Clockwise ? oldPos.x : oldSize.x - oldPos.x - 1; int toIndex = GetCellIndex(newX, newY, oldPos.z); int fromIndex = GetCellIndex(oldPos.x, oldPos.y, oldPos.z, oldSize.x, oldSize.y, oldSize.z); m_Cells[toIndex] = oldCells[fromIndex]; } int newPivotX = direction == RotationDirection.Clockwise ? oldSize.y - pivot.y - 1 : pivot.y; int newPivotY = direction == RotationDirection.Clockwise ? pivot.x : oldSize.x - pivot.x - 1; pivot = new Vector3Int(newPivotX, newPivotY, pivot.z); Matrix4x4 rotation = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, direction == RotationDirection.Clockwise ? 90f : -90f), Vector3.one); Quaternion orientation = Quaternion.Euler(0f, 0f, direction == RotationDirection.Clockwise ? 90f : -90f); foreach (BrushCell cell in m_Cells) { cell.offset = rotation * cell.offset; cell.orientation = cell.orientation * orientation; } }
public override void Flip(FlipAxis flip, UnityEngine.Grid.CellLayout layout) { if (flip == FlipAxis.X) { FlipX(); } else { FlipY(); } }