43 this.cellMargins = useMargins;
44 this.verticalOrigin = useVertOrigin;
50 public Cell this[
int idx] {
63 var centerFromOrigin =
new Vector3(
64 col * cellWidth + (cellWidth / 2f),
65 row * cellHeight + (cellHeight / 2f),
68 new Vector3(1f, -1f, 1f) : Vector3.one);
75 center = origin + centerFromOrigin,
76 radii =
new Vector2(cellWidth / 2f, cellHeight / 2f)
83 if (idx0 == idx1) {
return this[idx0]; }
85 int row0 = getRow(idx0), row1 = getRow(idx1);
86 if (row0 > row1) { Utils.Swap(ref row0, ref row1); }
87 var rowStart = getRow(idx0);
88 var numMergedRows = 1 + (row1 - row0);
90 int col0 = getCol(idx0), col1 = getCol(idx1);
91 if (col0 > col1) { Utils.Swap(ref col0, ref col1); }
92 var colStart = getCol(idx0);
93 var numMergedCols = 1 + (col1 - col0);
97 var mergedCellWidth = cellWidth * numMergedCols;
98 var mergedCellHeight = cellHeight * numMergedRows;
102 var centerFromOrigin =
new Vector3(
103 colStart * cellWidth + (mergedCellWidth / 2f),
104 rowStart * cellHeight + (mergedCellHeight / 2f),
107 new Vector3(1f, -1f, 1f) : Vector3.one);
112 index = (colStart + this.numCols * rowStart),
115 center = origin + centerFromOrigin,
116 radii =
new Vector2(mergedCellWidth / 2f, mergedCellHeight / 2f)
121 private int getRow(
int idx) {
return idx /
numCols; }
122 private int getCol(
int idx) {
return idx %
numCols; }
123 private int getIndex(
int row,
int col) {
return row *
numCols + col; }
179 int idx0 = subGridBegin, idx1 = subGridEnd;
180 int row0 =
grid.getRow(idx0), row1 =
grid.getRow(idx1);
181 if (row0 > row1) { Utils.Swap(ref row0, ref row1); }
182 int col0 =
grid.getCol(idx0), col1 =
grid.getCol(idx1);
183 if (col0 > col1) { Utils.Swap(ref col0, ref col1); }
186 _lastIndex = Mathf.Max(subGridBegin, subGridEnd);
187 idx =
grid.getIndex(row0, col0) - 1;
203 else {
return true; }
UnityEngine.Rect UnityRect
CellEnumerator(LeapGrid grid)
CellEnumerator GetEnumerator()
CellEnumerator(LeapGrid grid, int subGridBegin, int subGridEnd)
Initializes a CellEnumerator that enumerates cells within the rectangular subgrid defined by cell ind...
LocalRect rect
Shorthand for cell.innerRect.
CellEnumerator GetEnumerator()
Cell GetMerged(int idx0, int idx1)
LeapGrid(UnityRect rect, int numRows=1, int numCols=1, Margins? cellMargins=null, VerticalOrigin? verticalOrigin=null, bool rowMajor=false)
CellEnumerator EnumerateCells(int subGridBegin, int subGridEnd)
Returns a CellEnumerator that enumerates cells within the rectangular subgrid defined by cell indices...
VerticalOrigin verticalOrigin
LeapGrid(LocalRect rect, int numRows=1, int numCols=1, Margins? cellMargins=null, VerticalOrigin? verticalOrigin=null, bool rowMajor=false)
static Margins All(float margin)