public void RecreateCoordDataSet() { InitSceneSize(); var sceneName = SceneManager.GetActiveScene().name; m_CoordDataSet = new SceneCoordDataSet(sceneName, m_SceneLength, m_SceneWidth, m_TerrainBounds.min.x, m_TerrainBounds.min.z); Debug.Log($"重新生成,The count x is {m_CoordDataSet.CountX}, the count y is {m_CoordDataSet.CountY}"); for (int i = 0; i < m_CoordDataSet.CountX; i++) { for (int j = 0; j < m_CoordDataSet.CountY; j++) { var tempPos = m_CoordDataSet.CalcPos(i, j); var pos = new Vector3(tempPos.X, 900f, tempPos.Y); var bFlag = JudgeCoord(pos, 1000f); //格子的value==1表示可以画格子 var value = bFlag ? 1 : 0; m_CoordDataSet.SetPoint(i, j, value); } } Debug.Log($"重新生成结束,{m_CoordDataSet.GetCount()}个格子中,一共有多少格子有效:{m_CoordDataSet.GetValueSum()}"); SaveCoordDataSet(); }
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); } } } } }
private void DrawMovezones(Vector3 center, int range = -1) { if (range == -1) { range = m_MovezoneDrawRange; } ClearAllBlocks(); var tempXY = m_CoordDataSet.GetXYIndex(center.x, center.z); var centerX = (int)tempXY.X; var centerY = (int)tempXY.Y; for (int i = centerX - range; i < centerX + range; i++) { if (i < 0 || i >= m_CoordDataSet.CountX) { continue; } for (int j = centerY - range; j < centerY + range; j++) { if (j < 0 || j >= m_CoordDataSet.CountY) { continue; } var tempPos = m_CoordDataSet.CalcPos(i, j); var pos = new Vector3(tempPos.X, 10.0f, tempPos.Y); var ray = new Ray(pos, Vector3.down); RaycastHit hitInfo; //用射线穿透地表,求地上的那个点 if (Physics.Raycast(ray, out hitInfo, 100f, 1 << LayerMask.NameToLayer("Ground"))) { //无效格子不显示 if (m_CoordDataSet.GetCoordValue(i, j) == 1) { DrawBattleBlock(hitInfo.point, Color.green, i, j); } } } } }