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("<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;
|
|||
|
|
}
|
|||
|
|
}
|