This commit is contained in:
2025-06-16 00:15:41 +08:00
parent bcfa5ce1ec
commit 6d79a5baa1
16 changed files with 246 additions and 3838 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
@@ -9,11 +10,9 @@ using UnityEngine.UI;
///<2F><><EFBFBD>ܣ<EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>򿪵<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>رյ<D8B1>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public class UIMapPanel : MonoBehaviour
{
public List<string> allMaps = new List<string>();
public Dropdown dropMap;
private int _curOpenMapId;
private bool _saving;
public int CurOpenMapId => _curOpenMapId;
// Start is called before the first frame update
@@ -21,50 +20,85 @@ public class UIMapPanel : MonoBehaviour
{
_saving = false;
_curOpenMapId = -1;
UIWindow.Instance.uiCreateMap.onCreatedMapCallback += OnCreatedMap;
}
void OnDataLoaded()
{
string[] AllFilePath = Directory.GetDirectories(Application.dataPath + "/GameAssets/Maps");
for (int i = 0; i < AllFilePath.Length; i++)
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD>ͼ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
string mapsDirectory = Path.Combine(Application.dataPath, "GameAssets", "Maps");
if (!Directory.Exists(mapsDirectory))
{
string[] pathSplit = AllFilePath[i].Split('/');
string[] pathSplit2 = pathSplit[pathSplit.Length - 1].Split('\\');
allMaps.Add(pathSplit2[pathSplit2.Length - 1]);
Debug.LogError($"Maps directory not found: {mapsDirectory}");
return;
}
string[] mapFolders = Directory.GetDirectories(mapsDirectory);
foreach (string folderPath in mapFolders)
{
string[] pathSplit = folderPath.Split(Path.DirectorySeparatorChar);
string mapId = pathSplit[pathSplit.Length - 1]; // <20><><EFBFBD><EFBFBD> "v1000"
string textureDirectory = Path.Combine(folderPath, "Texture");
if (Directory.Exists(textureDirectory))
{
string[] imageFiles = Directory.GetFiles(textureDirectory, "*.jpg");
int maxRow = 0;
int maxCol = 0;
string pattern = $@"{mapId}_r(\d+)_c(\d+)"; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>ƥ<EFBFBD><C6A5> v1000_rXX_cYY
Regex regex = new Regex(pattern);
foreach (string filePath in imageFiles)
{
string fileName = Path.GetFileNameWithoutExtension(filePath); // <20><><EFBFBD><EFBFBD> "v1000_r11_c14"
Match match = regex.Match(fileName);
if (match.Success)
{
if (int.TryParse(match.Groups[1].Value, out int row) && int.TryParse(match.Groups[2].Value, out int col))
{
maxRow = Mathf.Max(maxRow, row);
maxCol = Mathf.Max(maxCol, col);
}
}
else
{
Debug.LogWarning($"Filename {fileName} does not match expected pattern: {pattern}");
}
}
if (maxRow > 0 && maxCol > 0)
{
MapManager.Instance.allMaps[mapId] = (maxRow, maxCol);
Debug.Log($"Map {mapId} loaded with max dimensions: {maxRow}x{maxCol}");
}
else
{
Debug.LogWarning($"No valid dimensions found for map {mapId}");
}
}
else
{
Debug.LogWarning($"Texture directory not found for map {mapId}: {textureDirectory}");
}
}
}
public void ScanMap()
{
allMaps.Clear();
{
MapManager.Instance.allMaps.Clear();
OnDataLoaded();
dropMap.options.Clear();
for (int i=0; i<allMaps.Count; i++)
{
foreach (var map in MapManager.Instance.allMaps)
{
Dropdown.OptionData od = new Dropdown.OptionData();
od.text = allMaps[i];
od.text = map.Key;
dropMap.options.Add(od);
}
dropMap.value = 1;
dropMap.value = 0; //Ϊ<><CEAA>Ĭ<EFBFBD><C4AC>ѡ<EFBFBD>е<EFBFBD>һ<EFBFBD><D2BB>
}
private void OnCreatedMap(int mapId, int mapWidth, int mapHeight)
{
ScanMap();
allMaps.Add(mapId.ToString());
Dropdown.OptionData od = new Dropdown.OptionData();
od.text = mapId.ToString();
dropMap.options.Add(od);
dropMap.value = dropMap.options.Count - 1;
}
public void OpenMap()
{
if(dropMap.options.Count == 0)
@@ -82,18 +116,18 @@ public class UIMapPanel : MonoBehaviour
int mapId = 0;
mapId = Convert.ToInt32(dropMap.options[dropMap.value].text);
UIWindow.Instance.uiCreateMap.LoadMapRegions(mapId);
UIWindow.Instance.uiCellInfo.LoadCells();
UIWindow.Instance.uiCellInfo.ShowCells();
UIWindow.Instance.uiEditMapConfig.LoadMapConfig(mapId);
UIWindow.Instance.uiMonstersPanel.LoadMonsterConfig(mapId);
UIWindow.Instance.uiNpcsPanel.LoadNpcsConfig(mapId);
UIWindow.Instance.uiTriggersPanel.LoadTriggersConfig(mapId);
UIWindow.Instance.uiFuBensPanel.LoadFuBenConfig(mapId);
UIWindow.Instance.uiJuBaosPanel.LoadJuBaoConfig(mapId);
//UIWindow.Instance.uiCreateMap.LoadMapRegions(mapId);
//UIWindow.Instance.uiCellInfo.LoadCells();
//UIWindow.Instance.uiCellInfo.ShowCells();
//UIWindow.Instance.uiEditMapConfig.LoadMapConfig(mapId);
//UIWindow.Instance.uiMonstersPanel.LoadMonsterConfig(mapId);
//UIWindow.Instance.uiNpcsPanel.LoadNpcsConfig(mapId);
//UIWindow.Instance.uiTriggersPanel.LoadTriggersConfig(mapId);
//UIWindow.Instance.uiFuBensPanel.LoadFuBenConfig(mapId);
//UIWindow.Instance.uiJuBaosPanel.LoadJuBaoConfig(mapId);
_curOpenMapId = mapId;
//MapManager.Instance.LoadMapSprite();
MapManager.Instance.LoadMapRegions(_curOpenMapId);
}
public void CloseMap()
@@ -105,7 +139,7 @@ public class UIMapPanel : MonoBehaviour
public bool HasMap(string mapId)
{
return allMaps.Find(s => s == mapId) != null;
return MapManager.Instance.allMaps.ContainsKey(mapId);
}
public void ResetMap()
@@ -145,7 +179,7 @@ public class UIMapPanel : MonoBehaviour
{
_saving = true;
Debug.Log("<22><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
UIWindow.Instance.uiCreateMap.SaveRegions();
//UIWindow.Instance.uiCreateMap.SaveRegions();
UIWindow.Instance.uiCellEditor.SaveCells();
UIWindow.Instance.uiEditMapConfig.SaveMapConfig();
UIWindow.Instance.uiMonstersPanel.SaveMonsterConfig();