public XZGridCell(int xIndex, int zIndex, Vector3 min, Vector3 max, IXZGrid parentGrid) { _xIndex = xIndex; _zIndex = zIndex; _min = min; _max = max; _parentGrid = parentGrid; }
public static XZGridCell FromPoint(Vector3 point, float cellSizeX, float cellSizeZ, IXZGrid parentGrid) { Matrix4x4 gridWorldMtx = parentGrid.WorldMatrix; Vector3 gridModelPoint = gridWorldMtx.inverse.MultiplyPoint(point); int cellIndexX = Mathf.FloorToInt(gridModelPoint.x / cellSizeX); int cellIndexZ = Mathf.FloorToInt(gridModelPoint.z / cellSizeZ); Vector3 cellMin = Vector3.right * cellIndexX * cellSizeX + Vector3.forward * cellIndexZ * cellSizeZ; Vector3 cellMax = cellMin + Vector3.right * cellSizeX + Vector3.forward * cellSizeZ; cellMin = gridWorldMtx.MultiplyPoint(cellMin); cellMax = gridWorldMtx.MultiplyPoint(cellMax); return(new XZGridCell(cellIndexX, cellIndexZ, cellMin, cellMax, parentGrid)); }