row col 倒转之前

This commit is contained in:
2025-06-23 00:30:11 +08:00
parent 29c11f3642
commit 22a2ce0ea6
6 changed files with 21 additions and 378 deletions

View File

@@ -37,6 +37,10 @@ public class GridSelector : MonoBehaviour
private List<Vector2> lassoPos = new List<Vector2>();
private LineRenderer lassoLine;
public CellType getCellType(int index)
{
return (CellType)dataArray[index].barrier;
}
public CellType CellType { set; get; }
public void OnMapCreated(Map map)
{

View File

@@ -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<MeshRenderer>().materials = materials;
}
if ((type & CellType.Move) == CellType.Move)
{
go.GetComponent<MeshRenderer>().material = _cellMoveMat;
}
if ((type & CellType.Obstacle) == CellType.Obstacle)
{
go.GetComponent<MeshRenderer>().material = _cellObsMat;
}
if ((type & CellType.Hide) == CellType.Hide)
{
go.GetComponent<MeshRenderer>().material = _cellHideMat;
}
//if ((type & CellType.None) == CellType.None)
if (type == CellType.None)
{
go.GetComponent<MeshRenderer>().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; //<2F><> == <20><>
_cellCols = mapWidth / _cellWidth; //<2F><> == <20><>
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);
}
}
}
//<2F><><EFBFBD><EFBFBD>layer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void AddLayerCell(GameObject go, CellType layer)
{
List<GameObject> 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
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD>
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);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD>ȫ<EFBFBD><C8AB>
if(safeNoHide)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (((int)ct & (int)showLayers) == showLayers)
continue;
}
else
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD>ڰ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ȫ<EFBFBD><C8AB>
if (((int)ct & (int)showLayers) == showLayers)
continue;
}
//
// continue;
cell.SetActive(false);
}
}
public void RemoveLayerCellInLayCellsMap(GameObject go)
{
List<GameObject> removeGos = new List<GameObject>();
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<removeGos.Count; i++)
{
}
}
public void CleanSafe()
{
var cells = _layCellsMap[CellType.Safe];
if (cells == null)
return;
foreach(var cell in cells)
{
if (cell.GetComponent<MeshRenderer>().materials.Length == 2)
cell.GetComponent<MeshRenderer>().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));
}
}
}

View File

@@ -36,73 +36,6 @@ public partial class MapManager : MonoBehaviour
/// <20><>ǰ<EFBFBD><C7B0>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
/// </summary>
public MapRegions _curMapRegions;
public bool LoadObsXml()
{
if (_curOpenMapId < 0)
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ򿪵<C8B4>ͼ");
return false;
}
string path = string.Empty;
path = PathUtil.GetXmlPath(_curOpenMapId, "Obs");
if (!File.Exists(path))
{
UIWindow.Instance.ShowMessage(<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>");
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]);
//<2F><>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD>֮ǰ<D6AE>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
CellType celltype = (CellType)type;
if ((celltype & CellType.HadRole) > 0)
celltype ^= CellType.HadRole;
cellsNode[i] = new CellNode(x, y, i, celltype);
}
return true;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
/// </summary>

View File

@@ -60,6 +60,10 @@ public class UICellEditor : MonoBehaviour
AddInputNameClickEvent(txtStartPos);
AddInputNameClickEvent(txtEndPos);
}
private void OnEnable()
{
MapManager.Instance.ResetCell();
}
private void AddInputNameClickEvent(InputField input) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Awake<6B>е<EFBFBD><D0B5><EFBFBD>
{
@@ -205,16 +209,6 @@ public class UICellEditor : MonoBehaviour
//ͼ<><CDBC><EFBFBD>
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);
}
//<2F><EFBFBD><E0BCAD>Ч
@@ -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(<><C3BB>ѡ<EFBFBD>б<D0B1><E0BCAD><EFBFBD><EFBFBD>");
editorGrid = CellType.None;
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>

View File

@@ -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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>");
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>ֵ");
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);
}
}