namespace UnityEngine.Rendering
{
/// Utility for tiles layout
public static class TileLayoutUtils
{
/// Try decompose the givent rect into tiles given the parameter
/// The rect to split
/// The size of the tiles
/// Computed main area
/// Computed top row area
/// Computed right column area
/// Computed top right corner area
/// If true, the tiles decomposition is a success
public static bool TryLayoutByTiles(
RectInt src,
uint tileSize,
out RectInt main,
out RectInt topRow,
out RectInt rightCol,
out RectInt topRight)
{
if (src.width < tileSize || src.height < tileSize)
{
main = new RectInt(0, 0, 0, 0);
topRow = new RectInt(0, 0, 0, 0);
rightCol = new RectInt(0, 0, 0, 0);
topRight = new RectInt(0, 0, 0, 0);
return false;
}
int mainRows = src.height / (int)tileSize;
int mainCols = src.width / (int)tileSize;
int mainWidth = mainCols * (int)tileSize;
int mainHeight = mainRows * (int)tileSize;
main = new RectInt
{
x = src.x,
y = src.y,
width = mainWidth,
height = mainHeight,
};
topRow = new RectInt
{
x = src.x,
y = src.y + mainHeight,
width = mainWidth,
height = src.height - mainHeight
};
rightCol = new RectInt
{
x = src.x + mainWidth,
y = src.y,
width = src.width - mainWidth,
height = mainHeight
};
topRight = new RectInt
{
x = src.x + mainWidth,
y = src.y + mainHeight,
width = src.width - mainWidth,
height = src.height - mainHeight
};
return true;
}
/// Try decompose the givent rect into rows given the parameter
/// The rect to split
/// The size of the tiles
/// Computed main area
/// Computed other area
/// If true, the tiles decomposition is a success
public static bool TryLayoutByRow(
RectInt src,
uint tileSize,
out RectInt main,
out RectInt other)
{
if (src.height < tileSize)
{
main = new RectInt(0, 0, 0, 0);
other = new RectInt(0, 0, 0, 0);
return false;
}
int mainRows = src.height / (int)tileSize;
int mainHeight = mainRows * (int)tileSize;
main = new RectInt
{
x = src.x,
y = src.y,
width = src.width,
height = mainHeight,
};
other = new RectInt
{
x = src.x,
y = src.y + mainHeight,
width = src.width,
height = src.height - mainHeight
};
return true;
}
/// Try decompose the givent rect into columns given the parameter
/// The rect to split
/// The size of the tiles
/// Computed main area
/// Computed other area
/// If true, the tiles decomposition is a success
public static bool TryLayoutByCol(
RectInt src,
uint tileSize,
out RectInt main,
out RectInt other)
{
if (src.width < tileSize)
{
main = new RectInt(0, 0, 0, 0);
other = new RectInt(0, 0, 0, 0);
return false;
}
int mainCols = src.width / (int)tileSize;
int mainWidth = mainCols * (int)tileSize;
main = new RectInt
{
x = src.x,
y = src.y,
width = mainWidth,
height = src.height,
};
other = new RectInt
{
x = src.x + mainWidth,
y = src.y,
width = src.width - mainWidth,
height = src.height
};
return true;
}
}
}