From 05abbd21ee63c72a78a9c1def35d1766b07a4d0d Mon Sep 17 00:00:00 2001 From: tangbin <11111111> Date: Thu, 31 Jul 2025 10:52:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=AD=90=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Map/GridSelector.cs | 2 +- Assets/Scripts/UI/UICellInfo.cs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Map/GridSelector.cs b/Assets/Scripts/Map/GridSelector.cs index 9be4268..859932d 100644 --- a/Assets/Scripts/Map/GridSelector.cs +++ b/Assets/Scripts/Map/GridSelector.cs @@ -120,7 +120,7 @@ public class GridSelector : MonoBehaviour inputbuffer.Release(); } } - private int GetIndexByXY(int x, int y) { + public int GetIndexByXY(int x, int y) { int index = x + y * horizontalNumber; return index; } diff --git a/Assets/Scripts/UI/UICellInfo.cs b/Assets/Scripts/UI/UICellInfo.cs index f030817..5a127df 100644 --- a/Assets/Scripts/UI/UICellInfo.cs +++ b/Assets/Scripts/UI/UICellInfo.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.VFX; +using static GridSelector; ///格子信息 - 绿色块 ///功能:加载格子数据,重新计算格子,显示格子,隐藏格子 @@ -87,11 +88,35 @@ public class UICellInfo : MonoBehaviour /// public void ReCalculateCell() { + int oldhorizontalNumber = MapManager.Instance.map?.selector?.horizontalNumber ?? 0; + int oldverticalNumber = MapManager.Instance.map?.selector?.verticalNumber ?? 0; + var oldRendData = MapManager.Instance.map?.selector?.GetGridData(); int width = int.Parse(txtCellRows.text); int height = int.Parse(txtCellCols.text); float cellW = int.Parse(txtCellWidth.text) / 100.0f; float cellH = int.Parse(txtCellHeight.text) / 100.0f; MapManager.Instance.GenerateMap(MapManager.Instance._curOpenMapId,width * cellW, height * cellH, cellW, cellH); + var newRendData = MapManager.Instance.map?.selector?.GetGridData(); + for (int i = 0; i < MapManager.Instance.map?.selector.horizontalNumber; i++) + { + for (int j = 0; j < MapManager.Instance.map?.selector.verticalNumber; j++) + { + if (i < oldhorizontalNumber && j < oldverticalNumber) + { + int oldindex = i + j * oldhorizontalNumber; + //取出老的数据 + int index = MapManager.Instance.map.selector.GetIndexByXY(i, j); + newRendData[index] = oldRendData[oldindex]; + } + else {//新格子 + int index = MapManager.Instance.map.selector.GetIndexByXY(i, j); + newRendData[index] = new RenderData(); + newRendData[index].barrier = (int)CellType.Obstacle; + + } + } + } + MapManager.Instance.map.selector.RefreshPlaneRender(); ShowMapCellInfo(); } public void Update()