(client) feat:实现热重载,实现多维度,实现武器,实现掉落物,实现状态UI,实现攻击AI (#44)

Co-authored-by: zzdxxz <2079238449@qq.com>
Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
2025-08-27 19:56:49 +08:00
committed by TheRedApricot
parent d91210a6ff
commit 8456b6c162
132 changed files with 18568 additions and 2534 deletions

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Data;
@ -9,23 +10,27 @@ namespace Map
{
public class DoubleMap : MonoBehaviour
{
public List<List<int>> mapData = new List<List<int>>();
public List<List<int>> mapData = new();
public Tilemap textureLevel;
public Vector2Int dataOffset = Vector2Int.zero; // 数据起始点偏移变量
// public Vector2Int dataOffset = Vector2Int.zero; // 数据起始点偏移变量 - 已删除
// 初始化地图数据大小
public void InitializeData(int width, int height, int defaultValue = 0)
{
mapData.Clear();
for (int x = 0; x < width; x++)
for (var x = 0; x < width; x++)
{
List<int> column = new List<int>();
for (int y = 0; y < height; y++)
var column = new List<int>();
for (var y = 0; y < height; y++)
{
column.Add(defaultValue);
}
mapData.Add(column);
}
}
// 设置指定数据坐标的瓦片值并刷新相关瓦片
public void SetTile(int dataX, int dataY, int value)
{
@ -59,7 +64,7 @@ namespace Map
public void RefreshTile(int dataX, int dataY)
{
// 计算该数据点影响的四个瓦片位置(该点作为四个角)
Vector2Int[] affectedTiles = new Vector2Int[]
var affectedTiles = new Vector2Int[]
{
new Vector2Int(dataX - 1, dataY - 1), // 作为右下角
new Vector2Int(dataX - 1, dataY), // 作为右上角
@ -79,15 +84,15 @@ namespace Map
if (mapData.Count == 0 || mapData[0].Count == 0) return;
// 计算瓦片地图的有效范围(考虑偏移)
int startX = dataOffset.x;
int startY = dataOffset.y;
int endX = startX + mapData.Count - 1;
int endY = startY + mapData[0].Count - 1;
var startX = 0; // dataOffset.x 已删除
var startY = 0; // dataOffset.y 已删除
var endX = startX + mapData.Count - 1;
var endY = startY + mapData[0].Count - 1;
// 遍历所有瓦片位置
for (int x = startX; x <= endX; x++)
for (var x = startX; x <= endX; x++)
{
for (int y = startY; y <= endY; y++)
for (var y = startY; y <= endY; y++)
{
UpdateTileAtTilemapPosition(x, y);
}
@ -98,30 +103,30 @@ namespace Map
private void UpdateTileAtTilemapPosition(int tileX, int tileY)
{
// 计算对应的数据坐标(考虑偏移)
int dataX = tileX - dataOffset.x;
int dataY = tileY - dataOffset.y;
var dataX = tileX; // - dataOffset.x 已删除
var dataY = tileY; // - dataOffset.y 已删除
// 获取四个角的数据坐标
int topLeftX = dataX;
int topLeftY = dataY;
int topRightX = dataX + 1;
int topRightY = dataY;
int bottomLeftX = dataX;
int bottomLeftY = dataY + 1;
int bottomRightX = dataX + 1;
int bottomRightY = dataY + 1;
var topLeftX = dataX;
var topLeftY = dataY + 1;
var topRightX = dataX + 1;
var topRightY = dataY + 1;
var bottomLeftX = dataX;
var bottomLeftY = dataY;
var bottomRightX = dataX + 1;
var bottomRightY = dataY;
// 检查边界并获取值
int topLeft = GetDataValue(topLeftX, topLeftY);
int topRight = GetDataValue(topRightX, topRightY);
int bottomLeft = GetDataValue(bottomLeftX, bottomLeftY);
int bottomRight = GetDataValue(bottomRightX, bottomRightY);
var topLeft = GetDataValue(topLeftX, topLeftY);
var topRight = GetDataValue(topRightX, topRightY);
var bottomLeft = GetDataValue(bottomLeftX, bottomLeftY);
var bottomRight = GetDataValue(bottomRightX, bottomRightY);
// 获取对应的瓦片
TileBase tile = GetTileFromManager(topLeft, topRight, bottomLeft, bottomRight);
var tile = GetTileFromManager(topLeft, topRight, bottomLeft, bottomRight);
// 设置到瓦片地图
Vector3Int position = new Vector3Int(tileX, tileY, 0);
var position = new Vector3Int(tileX, tileY, 0);
textureLevel.SetTile(position, tile);
}
@ -136,7 +141,7 @@ namespace Map
// 从TileManager获取对应瓦片
private TileBase GetTileFromManager(int topLeft, int topRight, int bottomLeft, int bottomRight)
{
TileManager manager = TileManager.Instance;
var manager = TileManager.Instance;
if (manager == null)
{
Debug.LogError("TileManager实例未找到");
@ -145,13 +150,13 @@ namespace Map
// 尝试获取组合键对应的瓦片
var key = (topLeft, topRight, bottomLeft, bottomRight);
if (manager.tileToTileBaseMapping.TryGetValue(key, out TileBase tile))
if (manager.tileToTileBaseMapping.TryGetValue(key, out var tile))
{
return tile;
}
// 备用方案:尝试获取默认瓦片
if (manager.tileBaseMapping.TryGetValue("Default", out TileBase defaultTile))
if (manager.tileBaseMapping.TryGetValue("Default", out var defaultTile))
{
return defaultTile;
}
@ -159,5 +164,16 @@ namespace Map
Debug.LogError($"未找到对应瓦片: {key}");
return null;
}
public Vector2Int GetSize()
{
if (!mapData.Any() || mapData[0].Count == 0)
{
return new Vector2Int(0, 0);
}
return new Vector2Int(mapData.Count, mapData[0].Count);
}
}
}