82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using HxGame;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using static MapManager;
|
|
|
|
public partial class MapManager : MonoBehaviour
|
|
{
|
|
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;
|
|
}
|
|
}
|