浏览代码

Added TileLayout utilities

/main
Frédéric Vauchelles 7 年前
当前提交
04e13257
共有 4 个文件被更改,包括 169 次插入0 次删除
  1. 20
      ScriptableRenderPipeline/Core/CoreRP/RectInt.cs
  2. 11
      ScriptableRenderPipeline/Core/CoreRP/RectInt.cs.meta
  3. 127
      ScriptableRenderPipeline/Core/CoreRP/TileLayoutUtils.cs
  4. 11
      ScriptableRenderPipeline/Core/CoreRP/TileLayoutUtils.cs.meta

20
ScriptableRenderPipeline/Core/CoreRP/RectInt.cs


namespace UnityEngine.Experimental.Rendering
{
public struct RectInt
{
public static readonly RectInt zero = new RectInt(0, 0, 0, 0);
public int x;
public int y;
public int width;
public int height;
public RectInt(int x, int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}
}

11
ScriptableRenderPipeline/Core/CoreRP/RectInt.cs.meta


fileFormatVersion: 2
guid: c8e81b226dbe13441ab23fbc3719f78c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

127
ScriptableRenderPipeline/Core/CoreRP/TileLayoutUtils.cs


namespace UnityEngine.Experimental.Rendering
{
public static class TileLayoutUtils
{
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 = RectInt.zero;
topRow = RectInt.zero;
rightCol = RectInt.zero;
topRight = RectInt.zero;
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;
}
public static bool TryLayoutByRow(
RectInt src,
uint tileSize,
out RectInt main,
out RectInt other)
{
if (src.height < tileSize)
{
main = RectInt.zero;
other = RectInt.zero;
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;
}
public static bool TryLayoutByCol(
RectInt src,
uint tileSize,
out RectInt main,
out RectInt other)
{
if (src.width < tileSize)
{
main = RectInt.zero;
other = RectInt.zero;
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;
}
}
}

11
ScriptableRenderPipeline/Core/CoreRP/TileLayoutUtils.cs.meta


fileFormatVersion: 2
guid: 39aaac96b648c194298b5441a11fd53a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存