//获取坐标对应的格子 public BattleBlockData GetLocationBattleBlock(Vector3 pos) { var tempXY = m_CoordDataSet.GetXYIndex(pos.x, pos.z); var centerX = (int)tempXY.X; var centerY = (int)tempXY.Y; return(GetBlockData(centerX, centerY)); }
public void DrawBlocks(Ray ray, bool isEditing = false) { RaycastHit hitInfo; if (!Physics.Raycast(ray, out hitInfo, 1000, 1 << LayerMask.NameToLayer("Ground"))) { return; } Debug.Log($"DrawBlocks 中心点 坐标 {hitInfo.point.x} {hitInfo.point.y} {hitInfo.point.z}"); ClearAllBlocks(); var tempXY = m_CoordDataSet.GetXYIndex(hitInfo.point.x, hitInfo.point.z); var centerX = (int)tempXY.X; var centerY = (int)tempXY.Y; for (int i = centerX - m_BlockCountX; i < centerX + m_BlockCountX; i++) { if (i < 0 || i >= m_CoordDataSet.CountX) { continue; } for (int j = centerY - m_BlockCountY; j < centerY + m_BlockCountY; j++) { if (j < 0 || j >= m_CoordDataSet.CountY) { continue; } var tempPos = m_CoordDataSet.CalcPos(i, j); var pos = new Vector3(tempPos.X, hitInfo.point.y, tempPos.Y); if (isEditing) { //编辑模式下,所有格子都显示 DrawBattleBlock(pos, Color.green, i, j); } else { //非编辑模式下,无效格子不显示 if (m_CoordDataSet.GetCoordValue(i, j) == 1) { DrawBattleBlock(pos, Color.green, i, j); } } } } }