2025-06-14 13:46:24 +08:00
|
|
|
|
using HxGame;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2025-06-15 20:14:45 +08:00
|
|
|
|
using System.Runtime.Remoting.Metadata.W3cXsd2001;
|
2025-06-14 13:46:24 +08:00
|
|
|
|
using System.Xml;
|
2025-06-15 20:14:45 +08:00
|
|
|
|
using System.Xml.Linq;
|
2025-06-14 13:46:24 +08:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
2025-06-15 20:14:45 +08:00
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
using UnityEngine.Rendering;
|
|
|
|
|
|
using UnityEngine.UI;
|
2025-06-14 13:46:24 +08:00
|
|
|
|
using static MapManager;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class MapManager : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool LoadObsXml()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_curOpenMapId < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ<C8B4>ͼ");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-15 20:14:45 +08:00
|
|
|
|
string path = string.Empty;
|
|
|
|
|
|
|
2025-06-14 13:46:24 +08:00
|
|
|
|
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(';');
|
2025-06-15 20:14:45 +08:00
|
|
|
|
if (values.Length != cellCount)
|
2025-06-14 13:46:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cellsNode = new CellNode[cellCount];
|
2025-06-15 20:14:45 +08:00
|
|
|
|
for (int i = 0; i < cellCount; i++)
|
2025-06-14 13:46:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2025-06-15 20:14:45 +08:00
|
|
|
|
public void LoadMapSprite()
|
|
|
|
|
|
{
|
|
|
|
|
|
//map<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|
|
|
|
|
GameObject map = new GameObject("map");
|
|
|
|
|
|
int mapRownum = 11;
|
|
|
|
|
|
int mapColumn = 14;
|
|
|
|
|
|
//ƽ<><C6BD>;
|
|
|
|
|
|
float jpgscenew = 512f / 100;
|
|
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < mapRownum; row++)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int col = 0; col < mapColumn; col++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>v1000_r1_c1.jpg
|
|
|
|
|
|
string filename = $"v{1000}_r{row + 1}_c{col + 1}";
|
|
|
|
|
|
string spPath = PathUtil.GetMapTexure(1000, filename, "jpg");
|
|
|
|
|
|
GameObject obj = new GameObject(filename);
|
|
|
|
|
|
obj.transform.SetParent(map.transform);
|
|
|
|
|
|
SpriteRenderer sr = obj.AddComponent<SpriteRenderer>();
|
|
|
|
|
|
float x = col * jpgscenew;
|
|
|
|
|
|
float y = (mapRownum - row - 1) * jpgscenew;
|
|
|
|
|
|
obj.transform.position = new Vector2(x, y);
|
|
|
|
|
|
StartCoroutine(LoadSpriteT(spPath, obj,sr));
|
|
|
|
|
|
// ֱ<><D6B1>ʹ<EFBFBD><CAB9>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Sprite
|
|
|
|
|
|
//sr.sprite = Sprite.Create(asset, new Rect(0, 0, asset.width, asset.height), Vector2.zero, 100f);
|
|
|
|
|
|
//float x = col * jpgscenew;
|
|
|
|
|
|
//float y = (mapRownum - row - 1) * jpgscenew;
|
|
|
|
|
|
//obj.transform.position = new Vector2(x, y);
|
|
|
|
|
|
//Debug.Log($"Tile {filename} placed at ({x}, {y})");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
|
|
|
|
|
|
MapManager.Instance.GenerateMap(jpgscenew * mapColumn, jpgscenew * mapRownum, 0.48f, 0.32f);
|
|
|
|
|
|
}
|
|
|
|
|
|
IEnumerator LoadSpriteT(string spName, GameObject go, SpriteRenderer sprite)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(spName))
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return req.SendWebRequest();
|
|
|
|
|
|
if (req.result == UnityWebRequest.Result.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
Texture2D tt = DownloadHandlerTexture.GetContent(req);
|
|
|
|
|
|
if (tt == null)
|
|
|
|
|
|
yield break;
|
|
|
|
|
|
sprite.sprite = Sprite.Create(tt, new Rect(0, 0, tt.width, tt.height), Vector2.zero, 100f);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UIWindow.Instance.ShowMessage(req.error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-14 13:46:24 +08:00
|
|
|
|
}
|