mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 06:57:12 +08:00
(client) feat:添加基地界面到游玩界面的过程,添加存档管理,技能树变得可用 (#58)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/58
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Data;
|
||||
using Managers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
namespace Map
|
||||
{
|
||||
@@ -11,7 +13,7 @@ namespace Map
|
||||
/// </summary>
|
||||
public class Dimension : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool defaultOpen = false;
|
||||
[SerializeField] private bool defaultOpen;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("此维度的唯一标识符。如果为空,将使用GameObject的名称。")]
|
||||
@@ -22,13 +24,14 @@ namespace Map
|
||||
public Vector3 cameraPosition = new(0, 0, -10);
|
||||
|
||||
public Entity.Entity focusEntity;
|
||||
|
||||
public string mapGeneratorId;
|
||||
|
||||
public DimensionDef dimensionDefinition;
|
||||
|
||||
public Vector2Int DimensionSize { get;private set; }
|
||||
|
||||
public event System.Action<Dimension> OnDimensionLoaded;
|
||||
|
||||
public Vector2Int DimensionSize { get; private set; }
|
||||
public TileBase airWall;
|
||||
|
||||
public event Action<Dimension> OnDimensionLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// 获取此维度的唯一标识符。
|
||||
/// </summary>
|
||||
@@ -38,7 +41,7 @@ namespace Map
|
||||
{
|
||||
if (string.IsNullOrEmpty(_dimensionId))
|
||||
{
|
||||
_dimensionId = gameObject.name; // 如果未设置,默认使用GameObject名称
|
||||
_dimensionId = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
return _dimensionId;
|
||||
@@ -54,12 +57,14 @@ namespace Map
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (!airWall)
|
||||
{
|
||||
airWall = Resources.Load<TileBase>("Tile/AirWall");
|
||||
}
|
||||
|
||||
// 1. 确保 DimensionId 已初始化,这会触发 DimensionId 属性的 getter 逻辑
|
||||
var id = DimensionId;
|
||||
// 2. 创建一个用于存放此维度下所有实体的根GameObject,方便管理
|
||||
var id = DimensionId; // 确保 DimensionId 已初始化
|
||||
var rootObj = new GameObject($"_Entities_{id}");
|
||||
rootObj.transform.SetParent(this.transform); // 将其作为Dimension对象的子对象
|
||||
rootObj.transform.SetParent(transform);
|
||||
DimensionRoot = rootObj.transform;
|
||||
|
||||
Program.Instance.RegisterDimension(this);
|
||||
@@ -69,32 +74,34 @@ namespace Map
|
||||
Program.Instance.SetFocusedDimension(_dimensionId);
|
||||
}
|
||||
|
||||
mapGeneratorId = Configs.ConfigManager.Instance.GetValue<string>(DimensionId);
|
||||
var mapGeneratorId = Configs.ConfigManager.Instance.GetValue<string>(DimensionId);
|
||||
if (!string.IsNullOrEmpty(mapGeneratorId))
|
||||
{
|
||||
dimensionDefinition=DefineManager.Instance.FindDefine<DimensionDef>(mapGeneratorId);
|
||||
dimensionDefinition = DefineManager.Instance.FindDefine<DimensionDef>(mapGeneratorId);
|
||||
if (dimensionDefinition != null)
|
||||
{
|
||||
_=ApplyDimensionDef(dimensionDefinition);
|
||||
_ = ApplyDimensionDef(dimensionDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// 当 Dimension 对象被销毁时(例如,场景卸载),从 Program 和 EntityManage 注销
|
||||
if (Program.Instance != null) // 检查单例是否仍然存在
|
||||
{
|
||||
Program.Instance.UnregisterDimension(this);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplyDimensionDef(DimensionDef def)
|
||||
/// <summary>
|
||||
/// 应用维度定义,生成地图并设置边界。
|
||||
/// </summary>
|
||||
/// <param name="def">要应用的维度定义。</param>
|
||||
public async Task ApplyDimensionDef(DimensionDef def)
|
||||
{
|
||||
var maxWidth = DimensionSize.x; // 初始化为当前的维度尺寸
|
||||
var maxHeight = DimensionSize.y; // 初始化为当前的维度尺寸
|
||||
landform.Clear();
|
||||
var maxWidth = DimensionSize.x;
|
||||
var maxHeight = DimensionSize.y;
|
||||
|
||||
if (def.mapGenerators != null)
|
||||
{
|
||||
@@ -107,18 +114,39 @@ namespace Map
|
||||
maxWidth = Mathf.Max(maxWidth, requiredSize.x);
|
||||
maxHeight = Mathf.Max(maxHeight, requiredSize.y);
|
||||
}
|
||||
|
||||
|
||||
DimensionSize = new Vector2Int(maxWidth, maxHeight);
|
||||
cameraPosition = new Vector3(DimensionSize.x / 2f, DimensionSize.y / 2f, -10)+transform.position;
|
||||
cameraPosition = new Vector3(DimensionSize.x / 2f, DimensionSize.y / 2f, -10) + transform.position;
|
||||
foreach (var defMapGenerator in def.mapGenerators)
|
||||
{
|
||||
await TileManager.Instance.ApplyMapGenerator(defMapGenerator.defName, landform);
|
||||
}
|
||||
}
|
||||
|
||||
OnDimensionLoaded.Invoke(this);
|
||||
}
|
||||
|
||||
}
|
||||
var size = landform.GetSize();
|
||||
var origin = landform.GetOrigin();
|
||||
var minX = origin.x;
|
||||
var minY = origin.y;
|
||||
var maxX = origin.x + size.x - 1;
|
||||
var maxY = origin.y + size.y - 1;
|
||||
const int borderWidth = 1;
|
||||
var airWallZ = origin.z;
|
||||
|
||||
}
|
||||
// 绘制上下边界
|
||||
for (var x = minX - borderWidth; x <= maxX + borderWidth; x++)
|
||||
{
|
||||
landform.SetBaseTile(airWall, new Vector3Int(x, maxY + borderWidth, airWallZ));
|
||||
landform.SetBaseTile(airWall, new Vector3Int(x, minY - borderWidth, airWallZ));
|
||||
}
|
||||
|
||||
// 绘制左右边界
|
||||
for (var y = minY - borderWidth + 1; y <= maxY + borderWidth - 1; y++)
|
||||
{
|
||||
landform.SetBaseTile(airWall, new Vector3Int(minX - borderWidth, y, airWallZ)); // 左侧
|
||||
landform.SetBaseTile(airWall, new Vector3Int(maxX + borderWidth, y, airWallZ)); // 右侧
|
||||
}
|
||||
|
||||
OnDimensionLoaded?.Invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user