This commit is contained in:
tangbin
2025-08-22 16:02:14 +08:00
parent 05abbd21ee
commit 2393d3f281
4 changed files with 733 additions and 185 deletions

View File

@@ -2,12 +2,13 @@ using Cysharp.Threading.Tasks;
using HxGame.Data;
using System.Collections;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Threading;
using UnityEngine;
using System.Linq;
public partial class MapManager : MonoBehaviour
{
@@ -21,7 +22,7 @@ public partial class MapManager : MonoBehaviour
public Transform mapTeleportArea;
public Transform mapReliveArea;
public Transform mapAudioTrigger;
public Dictionary<string, (int maxRow, int maxCol)> allMaps = new Dictionary<string, (int maxRow, int maxCol)>();
public Dictionary<string, (int maxRow, int maxCol,int maxNum)> allMaps = new Dictionary<string, (int maxRow, int maxCol, int maxNum)>();
/// <summary>
/// <20><>ǰ<EFBFBD><C7B0>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
@@ -44,6 +45,11 @@ public partial class MapManager : MonoBehaviour
public void SaveAtlasToFile()
{
if (MapManager.Instance.map == null)
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ򿪵<C8B4>ͼ");
return;
}
int atlasWidth = _curMapRegions.regionRowNum * (int)_curMapRegions.regionWidth;
int atlasHeight = _curMapRegions.regionColNum * (int)_curMapRegions.regionHeight;
if (atlasWidth < 8192)
@@ -148,7 +154,11 @@ public partial class MapManager : MonoBehaviour
}
public void LoadMapRegionSprites(int mapId)
{
if (!allMaps.TryGetValue(mapId.ToString(),out var mapInfo))
OldRegionSprites(mapId);
}
public void OldRegionSprites(int mapId)
{
if (!allMaps.TryGetValue(mapId.ToString(), out var mapInfo))
{
UIWindow.Instance.ShowMessage("<22><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD><DAA1><EFBFBD><EFBFBD><EFBFBD>");
return;
@@ -186,7 +196,7 @@ public partial class MapManager : MonoBehaviour
_curMapRegions.regions[row, col].indexY = col;
multithreadLoadTextrue(spPath, sr, _curMapRegions.regions[row, col]);
_curMapRegions.regions[row, col].regionName = filename;
}
}
}
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.VFX;
@@ -11,7 +12,7 @@ using static GridSelector;
public class UICellInfo : MonoBehaviour
{
public static UICellInfo Instance;
public Text txtMapWidth;
public InputField txtMapWidth;
public Text txtMapHeight;
public Text txtTotalCells;
public Text txtMoveCells;
@@ -31,6 +32,7 @@ public class UICellInfo : MonoBehaviour
{
Cleanup();
}
public int CustomMapWidth => int.Parse(txtMapWidth.text);
void Cleanup()
{
@@ -65,7 +67,7 @@ public class UICellInfo : MonoBehaviour
{
if (MapManager.Instance.map == null || MapManager.Instance.map.selector == null)
return;
if(MapManager.Instance._curMapRegions == null) return;
if (MapManager.Instance._curMapRegions == null) return;
txtMapWidth.text = MapManager.Instance._curMapRegions.regionRowNum.ToString();
txtMapHeight.text = MapManager.Instance._curMapRegions.regionColNum.ToString();
txtCellRows.text = MapManager.Instance.map.selector.horizontalNumber.ToString();
@@ -75,6 +77,17 @@ public class UICellInfo : MonoBehaviour
txtCellHeight.text = MapManager.heightPixel.ToString();
txtMoveCells.text = MapManager.Instance.map.selector.moveNum.ToString();
}
public void ShowMapWidthAndHeight(int mapId)
{
if (!MapManager.Instance.allMaps.TryGetValue(mapId.ToString(), out var mapInfo))
{
UIWindow.Instance.ShowMessage("<22><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD><DAA1><EFBFBD><EFBFBD><EFBFBD>");
return;
}
txtMapWidth.text = mapInfo.maxRow.ToString();
txtMapHeight.text = mapInfo.maxCol.ToString();
}
/// <summary>
/// <20><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
/// </summary>

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
@@ -19,8 +20,14 @@ public class UIMapPanel : MonoBehaviour
void Start()
{
_saving = false;
dropMap.onValueChanged.AddListener(delegate {
if (dropMap.options.Count > 0)
{
int mapId = Convert.ToInt32(dropMap.options[dropMap.value].text);
UICellInfo.Instance.ShowMapWidthAndHeight(mapId);
}
});
}
void OnDataLoaded()
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD>ͼ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
@@ -30,7 +37,7 @@ public class UIMapPanel : MonoBehaviour
Debug.LogError($"Maps directory not found: {mapsDirectory}");
return;
}
MapManager.Instance.allMaps.Clear();
string[] mapFolders = Directory.GetDirectories(mapsDirectory);
foreach (string folderPath in mapFolders)
{
@@ -62,23 +69,179 @@ public class UIMapPanel : MonoBehaviour
{
Debug.LogWarning($"Filename {fileName} does not match expected pattern: {pattern}");
}
}
if (maxRow > 0 && maxCol > 0)
{
MapManager.Instance.allMaps[mapId] = (maxCol, maxRow);
Debug.Log($"Map {mapId} loaded with max dimensions: {maxCol}x{maxRow}");
}
else
{
Debug.LogWarning($"No valid dimensions found for map {mapId}");
}
}
MapManager.Instance.allMaps[mapId] = (maxCol, maxRow, imageFiles.Length);
}
else
{
Debug.LogWarning($"Texture directory not found for map {mapId}: {textureDirectory}");
}
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC>ʽ<EFBFBD><CABD> map_x <20><> v{mapId}_rx_cx <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>
/// </summary>
public void ReNamePicFormat()
{
int mapId = Convert.ToInt32(dropMap.options[dropMap.value].text);
int width = UICellInfo.Instance.CustomMapWidth; // <20><>ͼ<EFBFBD><CDBC><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string mapsDirectory = Path.Combine(Application.dataPath, "GameAssets", "Maps", $"{mapId}", "Texture");
if (!Directory.Exists(mapsDirectory))
{
Debug.LogError($"Maps directory not found: {mapsDirectory}");
return;
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>jpg<70>ļ<EFBFBD>
string[] imageFiles = Directory.GetFiles(mapsDirectory, "*.jpg");
int totalFiles = imageFiles.Length;
if (totalFiles == 0)
{
UIWindow.Instance.ShowMessage($"No jpg files found in directory: {mapsDirectory}");
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
if (IsAlreadyRenamed(imageFiles, mapId))
{
UIWindow.Instance.ShowMessage($"<22>ļ<EFBFBD><C4BC><EFBFBD> {mapId} <20>Ѿ<EFBFBD><D1BE><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ϸ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (IsMixedFormat(imageFiles, mapId))
{
UIWindow.Instance.ShowMessage($"<22>ļ<EFBFBD><C4BC><EFBFBD> {mapId} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>");
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>map_<70><5F>ʽ<EFBFBD><CABD><EFBFBD>ļ<EFBFBD>
var mapFiles = imageFiles
.Where(file => Path.GetFileNameWithoutExtension(file).StartsWith("map_"))
.OrderBy(file =>
{
string fileName = Path.GetFileNameWithoutExtension(file);
if (int.TryParse(fileName.Substring(4), out int number))
{
return number;
}
return int.MaxValue;
})
.ToArray();
if (mapFiles.Length == 0)
{
UIWindow.Instance.ShowMessage($"û<><C3BB><EFBFBD>ҵ<EFBFBD>map_<70><5F>ʽ<EFBFBD><CABD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ʽ");
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int height = Mathf.CeilToInt((float)mapFiles.Length / width);
UIWindow.Instance.ShowMessage($"Renaming {mapFiles.Length} files with grid size: {width}x{height}");
int renamedCount = 0;
int errorCount = 0;
// ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int index = 0; index < mapFiles.Length; index++)
{
string oldFilePath = mapFiles[index];
string fileName = Path.GetFileNameWithoutExtension(oldFilePath);
string fileExtension = Path.GetExtension(oldFilePath);
try
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>1<EFBFBD><31>ʼ<EFBFBD><CABC>
int row = (index / width) + 1;
int col = (index % width) + 1;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>ͼID<49><44>
string newFileName = $"v{mapId}_r{row}_c{col}";
string newFilePath = Path.Combine(mapsDirectory, newFileName + fileExtension);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
File.Move(oldFilePath, newFilePath);
renamedCount++;
Debug.Log($"Renamed: {fileName} -> {newFileName}");
}
catch (Exception ex)
{
errorCount++;
Debug.LogError($"Error renaming file {fileName}: {ex.Message}");
}
}
Debug.Log($"Rename completed. Success: {renamedCount}, Errors: {errorCount}");
// ˢ<><CBA2>AssetDatabase
#if UNITY_EDITOR
UnityEditor.AssetDatabase.Refresh();
#endif
OnDataLoaded();
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
/// </summary>
private bool IsAlreadyRenamed(string[] imageFiles, int mapId)
{
// Ŀ<><C4BF><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>v{mapId}_r<5F><72><EFBFBD><EFBFBD>_c<5F><63><EFBFBD><EFBFBD>
string pattern = $"^v{mapId}_r\\d+_c\\d+$";
var regex = new System.Text.RegularExpressions.Regex(pattern);
foreach (string filePath in imageFiles)
{
string fileName = Path.GetFileNameWithoutExtension(filePath);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κη<CEBA>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
if (!regex.IsMatch(fileName) && !fileName.StartsWith("map_"))
{
return false;
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ļ<EFBFBD>
bool hasTargetFormat = imageFiles.Any(file =>
regex.IsMatch(Path.GetFileNameWithoutExtension(file)));
return hasTargetFormat;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ϸ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>map_<70><5F>ʽ<EFBFBD><CABD>
/// </summary>
private bool IsMixedFormat(string[] imageFiles, int mapId)
{
bool hasMapFormat = false;
bool hasTargetFormat = false;
string pattern = $"^v{mapId}_r\\d+_c\\d+$";
var regex = new System.Text.RegularExpressions.Regex(pattern);
foreach (string filePath in imageFiles)
{
string fileName = Path.GetFileNameWithoutExtension(filePath);
if (fileName.StartsWith("map_"))
{
hasMapFormat = true;
}
else if (regex.IsMatch(fileName))
{
hasTargetFormat = true;
}
// <20><><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><C7BB><EFBFBD>״̬
if (hasMapFormat && hasTargetFormat)
{
return true;
}
}
return false;
}
public void ExportMap()
{