From 22a2ce0ea68d731ecb9a29782a8b4db088e6ee49 Mon Sep 17 00:00:00 2001 From: tangbin <769851359@qq.com> Date: Mon, 23 Jun 2025 00:30:11 +0800 Subject: [PATCH] =?UTF-8?q?row=20col=20=E5=80=92=E8=BD=AC=E4=B9=8B?= =?UTF-8?q?=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/GameAssets/Maps/1000/XML/Obs.bytes | Bin 105620 -> 105620 bytes Assets/Scripts/Map/GridSelector.cs | 4 + Assets/Scripts/Map/MapManager.Cell.cs | 244 ++-------------------- Assets/Scripts/Map/MapManager.Region.cs | 67 ------ Assets/Scripts/UI/UICellEditor.cs | 44 +--- Assets/Scripts/UI/UICellInfo.cs | 40 ---- 6 files changed, 21 insertions(+), 378 deletions(-) diff --git a/Assets/GameAssets/Maps/1000/XML/Obs.bytes b/Assets/GameAssets/Maps/1000/XML/Obs.bytes index b44ee20bec5e6a0f57252676e107a4f392464369..c6d435d113c168501a5b30b40ff8dbc0205393cf 100644 GIT binary patch delta 201 wcmbQTlWodQwhbHhOutjjC@|fjj*$gHYzJ~}m lassoPos = new List(); private LineRenderer lassoLine; + public CellType getCellType(int index) + { + return (CellType)dataArray[index].barrier; + } public CellType CellType { set; get; } public void OnMapCreated(Map map) { diff --git a/Assets/Scripts/Map/MapManager.Cell.cs b/Assets/Scripts/Map/MapManager.Cell.cs index ad32a4f..722911f 100644 --- a/Assets/Scripts/Map/MapManager.Cell.cs +++ b/Assets/Scripts/Map/MapManager.Cell.cs @@ -747,237 +747,6 @@ public partial class MapManager : MonoBehaviour return cell.cellType; } - - private void ShowCellType(GameObject go, CellType type) - { - if ((type & CellType.Safe) == CellType.Safe) - { - var materials = new Material[2]; - materials[1] = _cellDefaultMat; - go.GetComponent().materials = materials; - } - - if ((type & CellType.Move) == CellType.Move) - { - go.GetComponent().material = _cellMoveMat; - } - - if ((type & CellType.Obstacle) == CellType.Obstacle) - { - go.GetComponent().material = _cellObsMat; - } - - if ((type & CellType.Hide) == CellType.Hide) - { - go.GetComponent().material = _cellHideMat; - } - - //if ((type & CellType.None) == CellType.None) - if (type == CellType.None) - { - go.GetComponent().material = _cellDefaultMat; - } - } - - public void CalculationCells(int cellWidth, int cellHeight, int mapWidth, int mapHeight) - { - //RemoveAllCells(); - - _cellWidth = cellWidth; - _cellHeight = cellHeight; - this.mapWidth = mapWidth; - this.mapHeight = mapHeight; - - _cellRows = mapHeight / _cellHeight; //行 == 高 - _cellCols = mapWidth / _cellWidth; //列 == 宽 - - cellsNode = new CellNode[_cellRows*_cellCols]; - int index = 0; - - for(int y=0; y < _cellRows; y++) - { - for(int x=0; x < _cellCols; x++) - { - index = y * _cellCols + x; - - cellsNode[index] = new CellNode(x, y, index, CellType.Obstacle); - } - } - - } - - //根据layer分类添加 - public void AddLayerCell(GameObject go, CellType layer) - { - List cells = null; - - if (((CellType)layer & CellType.Move) == CellType.Move) - { - cells = _layCellsMap[CellType.Move]; - cells.Add(go); - } - - if (((CellType)layer & CellType.Obstacle) == CellType.Obstacle) - { - cells = _layCellsMap[CellType.Obstacle]; - cells.Add(go); - } - - if (((CellType)layer & CellType.Hide) == CellType.Hide) - { - cells = _layCellsMap[CellType.Hide]; - cells.Add(go); - } - - if (((CellType)layer & CellType.Safe) == CellType.Safe) - { - cells = _layCellsMap[CellType.Safe]; - cells.Add(go); - } - - if (((CellType)layer & CellType.Stall) == CellType.Stall) - { - cells = _layCellsMap[CellType.Stall]; - cells.Add(go); - } - - if (((CellType)layer & CellType.Audio) == CellType.Audio) - { - cells = _layCellsMap[CellType.Audio]; - cells.Add(go); - } - - if (((CellType)layer & CellType.Trigger) == CellType.Trigger) - { - cells = _layCellsMap[CellType.Trigger]; - cells.Add(go); - } - - if (((CellType)layer & CellType.Monster) == CellType.Monster) - { - cells = _layCellsMap[CellType.Monster]; - cells.Add(go); - } - } - - public void HideCellsExcludeLayers(int layers) - { - if (layers == 0) - return; - - if(layers < (int)CellType.Stall) - { - bool safeNoHide = ((CellType)layers & CellType.Safe) == CellType.Safe; - - foreach (var layerCells in _layCellsMap) - { - safeNoHide = (layerCells.Key & CellType.Safe) == CellType.Safe; - if (((int)layerCells.Key & layers) != (int)layerCells.Key) - { - HideCellsWithLayer(layerCells.Key, layers, safeNoHide); - } - } - - HideSpecialPoint(EditCellType.SellArea); - HideSpecialPoint(EditCellType.AudioTrigger); - HideSpecialPoint(EditCellType.TriggerCell); - HideSpecialPoint(EditCellType.ReliveCell); - HideSpecialPoint(EditCellType.FuBenArea); - HideSpecialPoint(EditCellType.MonsterArea); - HideSpecialPoint(EditCellType.JuBaoArea); - } - else - { - //先隐藏所有格子 - HideCells(); - - if(((CellType)layers & CellType.Stall) == CellType.Stall) - { - ShowSpecialPoint(EditCellType.SellArea); - } - - if (((CellType)layers & CellType.Audio) == CellType.Audio) - { - ShowSpecialPoint(EditCellType.AudioTrigger); - } - - if (((CellType)layers & CellType.Trigger) == CellType.Trigger) - { - ShowSpecialPoint(EditCellType.TriggerCell); - } - - if (((CellType)layers & CellType.Monster) == CellType.Monster) - { - ShowSpecialPoint(EditCellType.MonsterArea); - } - } - - } - - public void HideCellsWithLayer(CellType hideLayer, int showLayers, bool safeNoHide) - { - var cells = _layCellsMap[hideLayer]; - foreach(var cell in cells) - { - CellType ct = GetCellType(cell.name); - //如果隐藏格子类型属于安全区 - if(safeNoHide) - { - //如果有显示格子类型的值,不隐藏 - if (((int)ct & (int)showLayers) == showLayers) - continue; - } - else - { - //如果隐藏格子类型不属于安全区,但是,显示格子类型又是安全区 - if (((int)ct & (int)showLayers) == showLayers) - continue; - } - // - // continue; - - cell.SetActive(false); - } - - } - - public void RemoveLayerCellInLayCellsMap(GameObject go) - { - List removeGos = new List(); - foreach(var cells in _layCellsMap.Values) - { - GameObject f = cells.Find(cell => cell.name == go.name); - if (f == null) - continue; - - removeGos.Add(f); - } - - for(int i=0; i().materials.Length == 2) - cell.GetComponent().materials = new Material[1]; - - CellType ct = GetCellType(cell.name); - CellType new_ct = (ct ^= CellType.Safe); - SetCellType(cell.name, new_ct); - ShowCellType(cell, new_ct); - } - - cells.Clear(); - } public bool isDragging = false; public Vector3 downPos; public SceneArea currentComponent; @@ -1025,4 +794,17 @@ public partial class MapManager : MonoBehaviour currentComponent = null; } } + + public void ResetCell() + { + if (MapManager.Instance.map == null) return; + int cellTotal = MapManager.Instance.map.selector.horizontalNumber * MapManager.Instance.map.selector.verticalNumber; + cellsNode = new CellNode[cellTotal]; + for (int row = 0; row < MapManager.Instance.map.selector.horizontalNumber; row++) + for (int col = 0; col < MapManager.Instance.map.selector.verticalNumber; col++) + { + int index = row * MapManager.Instance.map.selector.verticalNumber + col; + cellsNode[index] = new CellNode(row,col,index, MapManager.Instance.map.selector.getCellType(index)); + } + } } diff --git a/Assets/Scripts/Map/MapManager.Region.cs b/Assets/Scripts/Map/MapManager.Region.cs index 110496a..46c313f 100644 --- a/Assets/Scripts/Map/MapManager.Region.cs +++ b/Assets/Scripts/Map/MapManager.Region.cs @@ -36,73 +36,6 @@ public partial class MapManager : MonoBehaviour /// 当前地图区域 /// public MapRegions _curMapRegions; - public bool LoadObsXml() - { - if (_curOpenMapId < 0) - { - UIWindow.Instance.ShowMessage("请先打开地图"); - return false; - } - - string path = string.Empty; - - path = PathUtil.GetXmlPath(_curOpenMapId, "Obs"); - - if (!File.Exists(path)) - { - UIWindow.Instance.ShowMessage("没有找到网格文件, 将重新计算格子"); - return false; - } - - XmlDocument xmlDocument = new XmlDocument(); - xmlDocument.Load(path); - - XmlNode xmlRoot = xmlDocument.SelectSingleNode("Item"); - - string ID = xmlRoot.Attributes.GetNamedItem("ID").Value; - mapWidth = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("MapWidth").Value); - mapHeight = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("MapHeight").Value); - - int cellCount = 0; - - _cellWidth = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("CellWidth").Value); - _cellHeight = Convert.ToInt32(xmlRoot.Attributes.GetNamedItem("CellHeight").Value); - _cellRows = mapHeight / _cellHeight; - _cellCols = mapWidth / _cellWidth; - cellCount = _cellRows * _cellCols; - - - string strData = xmlRoot.Attributes.GetNamedItem("Value").Value; - - //0,0,1,0;0,1,1,1;0,2,1,2; - string[] values = strData.Split(';'); - if (values.Length != cellCount) - { - UIWindow.Instance.ShowMessage("网格数据错误"); - return false; - } - - cellsNode = new CellNode[cellCount]; - for (int i = 0; i < cellCount; i++) - { - string[] strCell = values[i].Split(','); - - if (strCell.Length != 3) - continue; - - int y = Convert.ToInt32(strCell[0]); - int x = Convert.ToInt32(strCell[1]); - int type = Convert.ToInt32(strCell[2]); - - //有些格子之前有点问题 - CellType celltype = (CellType)type; - if ((celltype & CellType.HadRole) > 0) - celltype ^= CellType.HadRole; - - cellsNode[i] = new CellNode(x, y, i, celltype); - } - return true; - } /// /// 保存地图配置 /// diff --git a/Assets/Scripts/UI/UICellEditor.cs b/Assets/Scripts/UI/UICellEditor.cs index 0d3fc0c..32d77f7 100644 --- a/Assets/Scripts/UI/UICellEditor.cs +++ b/Assets/Scripts/UI/UICellEditor.cs @@ -60,6 +60,10 @@ public class UICellEditor : MonoBehaviour AddInputNameClickEvent(txtStartPos); AddInputNameClickEvent(txtEndPos); } + private void OnEnable() + { + MapManager.Instance.ResetCell(); + } private void AddInputNameClickEvent(InputField input) //可以在Awake中调用 { @@ -205,16 +209,6 @@ public class UICellEditor : MonoBehaviour //图层编辑 public void OnShowLayerToggleChange() { - CellType[] layers = (CellType[])Enum.GetValues(typeof(CellType)); - _layers = 0; - for (int i= showgLayers.Length - 1; i>=0; i--) - { - if (showgLayers[i].isOn) - _layers |= (int)layers[i]; - } - - MapManager.Instance.ShowCells(); - MapManager.Instance.HideCellsExcludeLayers(_layers); } //编辑特效 @@ -222,36 +216,6 @@ public class UICellEditor : MonoBehaviour { MapManager.Instance.HideCells(); } - public void EditorAreaToggleChange(Toggle t) - { - if (t.isOn) - { - switch (t.name) - { - case "MoveToggle": - editorGrid = CellType.Move; - break; - case "BlockToggle": - editorGrid = CellType.Obstacle; - break; - case "HideToggle": - editorGrid = CellType.Hide; - break; - case "SafeToggle": - editorGrid = CellType.Safe; - break; - case "StallToggle": - editorGrid = CellType.Stall; - break; - } - MapManager.Instance.map?.selector.RefreshPlaneRender(); - } - if (editorAreaToggle.ActiveToggles().Count() == 0) - { - Debug.Log("没有选中编辑区域"); - editorGrid = CellType.None; - } - } /// /// 清除所选区域 diff --git a/Assets/Scripts/UI/UICellInfo.cs b/Assets/Scripts/UI/UICellInfo.cs index 1572a55..554e2d1 100644 --- a/Assets/Scripts/UI/UICellInfo.cs +++ b/Assets/Scripts/UI/UICellInfo.cs @@ -72,44 +72,4 @@ public class UICellInfo : MonoBehaviour txtCellHeight.text = MapManager.heightPixel.ToString(); txtMoveCells.text = MapManager.Instance.map.selector.moveNum.ToString(); } - - public void CalculationCells() - { - if (!bMapOpened) - return; - - if (string.IsNullOrEmpty(txtMapWidth.text) - || string.IsNullOrEmpty(txtMapWidth.text) - || string.IsNullOrEmpty(txtCellHeight.text) - || string.IsNullOrEmpty(txtCellHeight.text)) - { - UIWindow.Instance.ShowMessage("请输入有效数字"); - return; - } - - int mapWidth = Convert.ToInt32(txtMapWidth.text); - int mapHeight = Convert.ToInt32(txtMapHeight.text); - int cellWidth = Convert.ToInt32(txtCellWidth.text); - int cellHeight = Convert.ToInt32(txtCellHeight.text); - - if (mapWidth <= 0 || mapHeight <= 0 || cellWidth <= 0 || cellHeight <= 0) - { - UIWindow.Instance.ShowMessage("请输入大于0的数值"); - return; - } - - CalculationCells(mapWidth, mapHeight, cellWidth, cellHeight); - } - - public void CalculationCells(int mapWidth, int mapHeight, int cellWidth, int cellHeight) - { - int row = mapHeight / cellHeight; - int col = mapWidth / cellWidth; - - txtCellRows.text = row.ToString(); - txtCellCols.text = col.ToString(); - txtTotalCells.text = (row * col).ToString(); - - MapManager.Instance.CalculationCells(cellWidth, cellHeight, mapWidth, mapHeight); - } }