(client) chore
This commit is contained in:
@ -85,6 +85,10 @@ namespace Managers
|
||||
return GetRelation(affiliation1.defName, affiliation2.defName);
|
||||
}
|
||||
|
||||
public Relation GetRelation(Entity.Entity entity1, Entity.Entity entity2)
|
||||
{
|
||||
return GetRelation(entity1.affiliation, entity2.affiliation);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取两个阵营名称之间的关系。
|
||||
/// </summary>
|
||||
|
@ -56,7 +56,7 @@ namespace Managers
|
||||
lock (_lock)
|
||||
{
|
||||
// 交换读写缓冲区
|
||||
T temp = _readBuffer;
|
||||
var temp = _readBuffer;
|
||||
_readBuffer = _writeBuffer;
|
||||
_writeBuffer = temp;
|
||||
}
|
||||
@ -133,7 +133,7 @@ namespace Managers
|
||||
/// <returns>缓冲区中的第一条消息,如果缓冲区为空则返回 null。</returns>
|
||||
public static string ReadMessage()
|
||||
{
|
||||
if (MessageQueue.TryDequeue(out string message))
|
||||
if (MessageQueue.TryDequeue(out var message))
|
||||
{
|
||||
// 释放一个缓冲区空间
|
||||
BufferSemaphore.Release();
|
||||
|
@ -335,7 +335,7 @@ namespace Managers
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Define> result = new List<Define>();
|
||||
var result = new List<Define>();
|
||||
|
||||
// 从命名定义中查询。
|
||||
if (defines.TryGetValue(defineType, out var namedDefinitions))
|
||||
@ -368,7 +368,7 @@ namespace Managers
|
||||
{
|
||||
var defineType = typeof(T).Name;
|
||||
|
||||
List<Define> allDefines = QueryDefinesByType(defineType)?.ToList();
|
||||
var allDefines = QueryDefinesByType(defineType)?.ToList();
|
||||
if (allDefines == null || allDefines.Count == 0)
|
||||
{
|
||||
return null;
|
||||
@ -413,7 +413,7 @@ namespace Managers
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Define> result = new List<Define>();
|
||||
var result = new List<Define>();
|
||||
|
||||
// 仅从命名定义中查询。
|
||||
if (defines.TryGetValue(defineType, out var namedDefinitions))
|
||||
@ -440,7 +440,7 @@ namespace Managers
|
||||
{
|
||||
var defineType = typeof(T).Name;
|
||||
|
||||
List<Define> allDefines = QueryNamedDefinesByType(defineType)?.ToList();
|
||||
var allDefines = QueryNamedDefinesByType(defineType)?.ToList();
|
||||
if (allDefines == null || allDefines.Count == 0)
|
||||
{
|
||||
return null;
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Base;
|
||||
using Data;
|
||||
using Entity;
|
||||
using Map;
|
||||
using Prefab;
|
||||
@ -39,13 +40,16 @@ namespace Managers
|
||||
|
||||
/// <summary> 角色实体的预制体。 </summary>
|
||||
public EntityPrefab characterPrefab;
|
||||
|
||||
/// <summary> 建筑实体的预制体。 </summary>
|
||||
public EntityPrefab buildingPrefab;
|
||||
|
||||
/// <summary> 子弹实体的预制体。 </summary>
|
||||
public EntityPrefab bulletPrefab;
|
||||
|
||||
/// <summary> 默认实体的预制体,用于生成失败时的回退。 </summary>
|
||||
public EntityPrefab defaultEntityPrefab;
|
||||
|
||||
|
||||
// 已移除:RegisterDimension 和 UnregisterDimension 方法的相关注释,因为这些方法已不存在且与逻辑无关。
|
||||
|
||||
/// <summary>
|
||||
@ -80,7 +84,7 @@ namespace Managers
|
||||
public void Tick()
|
||||
{
|
||||
// 获取当前管理器中所有活跃维度ID的副本,以安全地迭代和移除。
|
||||
List<string> activeDimensionIdsInManager = _dimensionFactionEntities.Keys.ToList();
|
||||
var activeDimensionIdsInManager = _dimensionFactionEntities.Keys.ToList();
|
||||
|
||||
foreach (var dimensionId in activeDimensionIdsInManager)
|
||||
{
|
||||
@ -88,7 +92,8 @@ namespace Managers
|
||||
var dimension = Program.Instance.GetDimension(dimensionId);
|
||||
if (dimension == null)
|
||||
{
|
||||
Debug.LogWarning($"实体管理器:跳过维度 '{dimensionId}' 的Tick处理,因为其维度对象在程序(Program)中已不再活跃(或从未注册)。正在清理相关内部数据。");
|
||||
Debug.LogWarning(
|
||||
$"实体管理器:跳过维度 '{dimensionId}' 的Tick处理,因为其维度对象在程序(Program)中已不再活跃(或从未注册)。正在清理相关内部数据。");
|
||||
// 如果 Program 不再有这个维度,说明它已经失效或被注销,EntityManage 需要清理自己的相关数据。
|
||||
_dimensionFactionEntities.Remove(dimensionId);
|
||||
_dimensionLayerCache.Remove(dimensionId);
|
||||
@ -96,7 +101,7 @@ namespace Managers
|
||||
RemovePendingAdditionsForDimension(dimensionId);
|
||||
continue; // 跳过处理这个不存在的维度
|
||||
}
|
||||
|
||||
|
||||
// 现在真正处理的是 _dimensionFactionEntities 中该维度ID对应的字典。
|
||||
var factionDict = _dimensionFactionEntities[dimensionId];
|
||||
|
||||
@ -149,7 +154,7 @@ namespace Managers
|
||||
_dimensionLayerCache.Remove(dimensionId); // 对应的层级缓存也可以清理。
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理待添加实体 (现在维度感知)。
|
||||
if (_pendingAdditions.Any())
|
||||
{
|
||||
@ -163,7 +168,8 @@ namespace Managers
|
||||
// 再次检查维度是否活跃(在 Program 中注册),防止在添加前维度被 Program 注销。
|
||||
if (Program.Instance.GetDimension(dimensionId) == null)
|
||||
{
|
||||
Debug.LogError($"实体管理器:尝试将实体 '{entityPrefab?.name ?? "null"}' 添加到在程序(Program)中未注册或不活跃的维度 '{dimensionId}'。该实体将被销毁。");
|
||||
Debug.LogError(
|
||||
$"实体管理器:尝试将实体 '{entityPrefab?.name ?? "null"}' 添加到在程序(Program)中未注册或不活跃的维度 '{dimensionId}'。该实体将被销毁。");
|
||||
if (entityPrefab != null && entityPrefab.gameObject != null) Destroy(entityPrefab.gameObject);
|
||||
_pendingAdditions.Remove(pending); // 立即从待添加列表中移除已处理的条目。
|
||||
continue;
|
||||
@ -215,6 +221,7 @@ namespace Managers
|
||||
remainingPendingAdditions.Add(pending);
|
||||
}
|
||||
}
|
||||
|
||||
_pendingAdditions = remainingPendingAdditions;
|
||||
}
|
||||
|
||||
@ -262,7 +269,7 @@ namespace Managers
|
||||
throw new InvalidOperationException(
|
||||
$"在 '{instantiatedEntity.name}' 上缺少 EntityPrefab 组件,无法完成实体初始化。");
|
||||
}
|
||||
|
||||
entityComponent.entity.currentDimensionId=dimensionId;
|
||||
entityComponent.Init(def);
|
||||
extraInit?.Invoke(entityComponent);
|
||||
|
||||
@ -296,11 +303,9 @@ namespace Managers
|
||||
{
|
||||
_dimensionLayerCache[dimensionId] = new Dictionary<string, Transform>();
|
||||
layerCacheForDimension = _dimensionLayerCache[dimensionId]; // 更新引用。
|
||||
Debug.LogWarning($"实体管理器:按需为维度 '{dimensionId}' 初始化层级缓存。");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"实体管理器:在层级缓存中未找到维度 '{dimensionId}',且在程序(Program)中也未注册。无法创建层级 '{layerName}'。");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -490,6 +495,208 @@ namespace Managers
|
||||
entityComponent.DefaultInit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定维度中,查找与源实体具有特定关系的最近实体。
|
||||
/// </summary>
|
||||
/// <param name="dimensionId">要搜索的维度ID。</param>
|
||||
/// <param name="sourceEntityPrefab">作为参照的源实体预制体。</param>
|
||||
/// <param name="targetRelationship">目标实体与源实体之间的期望关系(例如,Friendly, Hostile)。</param>
|
||||
/// <returns>找到的最近实体预制体,如果没有找到符合条件的实体则返回 null。</returns>
|
||||
public EntityPrefab FindNearestEntityByRelation(string dimensionId, EntityPrefab sourceEntityPrefab,
|
||||
Relation targetRelationship)
|
||||
{
|
||||
// 参数校验:确保输入参数有效,避免空引用异常。
|
||||
if (sourceEntityPrefab == null || sourceEntityPrefab.entity == null)
|
||||
{
|
||||
Debug.LogWarning("实体管理器:FindNearestEntityByRelation 方法中,源实体预制体或其内部实体为空。无法执行搜索。");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 维度数据存在性检查:验证目标维度是否在实体管理器的内部数据结构中被初始化和管理。
|
||||
if (!_dimensionFactionEntities.TryGetValue(dimensionId, out var factionDict))
|
||||
{
|
||||
Debug.LogWarning($"实体管理器:FindNearestEntityByRelation 方法中,维度 '{dimensionId}' 未被初始化或未在内部管理实体。");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 初始化追踪变量:设置初始值,用于在遍历过程中追踪最近的实体及其距离。
|
||||
// 使用平方距离 (SqrMagnitude) 可以避免在每次距离计算时进行昂贵的开方运算,从而提高性能。
|
||||
EntityPrefab nearestTarget = null;
|
||||
var minDistanceSqr = float.MaxValue;
|
||||
var sourcePos = sourceEntityPrefab.transform.position;
|
||||
|
||||
// 关系管理器实例检查:确保 AffiliationManager 可用,它是判断实体关系的核心组件。
|
||||
var affiliationManager = AffiliationManager.Instance;
|
||||
if (affiliationManager == null)
|
||||
{
|
||||
Debug.LogError("实体管理器:FindNearestEntityByRelation 方法中,AffiliationManager 实例为空。无法确定实体关系。");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 遍历所有派系和实体:_dimensionFactionEntities 按维度和派系组织,需要遍历所有派系才能找到维度内的所有实体。
|
||||
foreach (var factionEntities in factionDict.Values) // factionDict.Values 是 LinkedList<EntityPrefab> 的集合
|
||||
{
|
||||
foreach (var currentEntityPrefab in factionEntities)
|
||||
{
|
||||
// 实体有效性及排除源实体自身:
|
||||
// 1. 排除无效或已死亡的实体,确保只处理活跃的实体。
|
||||
// 2. 在寻找“最近”实体时,通常指的是 *除了自身以外* 的实体。
|
||||
// 如果需要包含自身(例如,当 targetRelationship 是 AffiliationManager.Relation.Self 时),
|
||||
// 可以根据具体需求调整此逻辑,但默认行为是排除自身。
|
||||
if (currentEntityPrefab == null || currentEntityPrefab.entity == null ||
|
||||
currentEntityPrefab.entity.IsDead || currentEntityPrefab == sourceEntityPrefab)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 关系判断:使用 AffiliationManager 提供的接口判断源实体与当前遍历实体之间的关系。
|
||||
var currentRelation =
|
||||
affiliationManager.GetRelation(sourceEntityPrefab.entity, currentEntityPrefab.entity);
|
||||
if (currentRelation == targetRelationship)
|
||||
{
|
||||
// 距离计算与最近实体更新:
|
||||
// 1. 计算与源实体的距离(使用平方距离优化)。
|
||||
// 2. 如果当前实体更近,则更新 nearestTarget 和 minDistanceSqr。
|
||||
var distanceSqr = Vector3.SqrMagnitude(currentEntityPrefab.transform.position - sourcePos);
|
||||
if (distanceSqr < minDistanceSqr)
|
||||
{
|
||||
minDistanceSqr = distanceSqr;
|
||||
nearestTarget = currentEntityPrefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nearestTarget; // 返回找到的最近实体
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定维度中,判断是否存在任何与源实体敌对的活跃实体。
|
||||
/// </summary>
|
||||
/// <param name="dimensionId">要搜索的维度ID。</param>
|
||||
/// <param name="sourceEntityPrefab">作为参照的源实体预制体。</param>
|
||||
/// <returns>如果存在敌对实体则返回 true,否则返回 false。</returns>
|
||||
public bool ExistsHostile(string dimensionId, EntityPrefab sourceEntityPrefab)
|
||||
{
|
||||
// 参数校验:确保输入参数有效,避免空引用异常。
|
||||
if (sourceEntityPrefab == null || sourceEntityPrefab.entity == null)
|
||||
{
|
||||
Debug.LogWarning("实体管理器:ExistsHostile 方法中,源实体预制体或其内部实体为空。无法执行搜索。");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 维度数据存在性检查:验证目标维度是否在实体管理器的内部数据结构中被初始化和管理。
|
||||
if (!_dimensionFactionEntities.TryGetValue(dimensionId, out var factionDict))
|
||||
{
|
||||
Debug.LogWarning($"实体管理器:ExistsHostile 方法中,维度 '{dimensionId}' 未被初始化或未在内部管理实体。");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 关系管理器实例检查:确保 AffiliationManager 可用,它是判断实体关系的核心组件。
|
||||
var affiliationManager = AffiliationManager.Instance;
|
||||
if (affiliationManager == null)
|
||||
{
|
||||
Debug.LogError("实体管理器:ExistsHostile 方法中,AffiliationManager 实例为空。无法确定实体关系。");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 遍历所有实体:遍历维度内的所有派系,再遍历每个派系下的所有实体。
|
||||
foreach (var factionEntities in factionDict.Values)
|
||||
{
|
||||
foreach (var currentEntityPrefab in factionEntities)
|
||||
{
|
||||
// 实体有效性及排除源实体自身:
|
||||
// 1. 排除无效或已死亡的实体。
|
||||
// 2. 排除源实体自身,避免自身判断为敌对。
|
||||
if (currentEntityPrefab == null || currentEntityPrefab.entity == null ||
|
||||
currentEntityPrefab.entity.IsDead || currentEntityPrefab == sourceEntityPrefab)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 关系判断:判断当前实体与源实体是否为“敌对”关系。
|
||||
if (affiliationManager.GetRelation(sourceEntityPrefab.entity, currentEntityPrefab.entity) ==
|
||||
Data.Relation.Hostile)
|
||||
{
|
||||
return true; // 找到第一个敌对实体即返回 true,提高效率。
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false; // 遍历完所有实体都未找到敌对实体。
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定维度中,判断源实体视野范围内是否存在任何与源实体敌对的活跃实体。
|
||||
/// </summary>
|
||||
/// <param name="dimensionId">要搜索的维度ID。</param>
|
||||
/// <param name="sourceEntityPrefab">作为参照的源实体预制体。</param>
|
||||
/// <param name="sightRange">视野范围,实体间的距离小于等于此值视为在视野内。</param>
|
||||
/// <returns>如果视野范围内存在敌对实体则返回 true,否则返回 false。</returns>
|
||||
public bool ExistsHostileInSightRange(string dimensionId, EntityPrefab sourceEntityPrefab, float sightRange)
|
||||
{
|
||||
// 参数校验:确保输入参数有效,避免空引用异常及不合理的范围值。
|
||||
if (sourceEntityPrefab == null || sourceEntityPrefab.entity == null)
|
||||
{
|
||||
Debug.LogWarning("实体管理器:ExistsHostileInSightRange 方法中,源实体预制体或其内部实体为空。无法执行搜索。");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sightRange <= 0)
|
||||
{
|
||||
Debug.LogWarning($"实体管理器:ExistsHostileInSightRange 方法中,视野范围必须为正值。接收到的值为: {sightRange}。");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 维度数据存在性检查:验证目标维度是否在实体管理器的内部数据结构中被初始化和管理。
|
||||
if (!_dimensionFactionEntities.TryGetValue(dimensionId, out var factionDict))
|
||||
{
|
||||
Debug.LogWarning($"实体管理器:ExistsHostileInSightRange 方法中,维度 '{dimensionId}' 未被初始化或未在内部管理实体。");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 关系管理器实例检查:确保 AffiliationManager 可用,它是判断实体关系的核心组件。
|
||||
var affiliationManager = AffiliationManager.Instance;
|
||||
if (affiliationManager == null)
|
||||
{
|
||||
Debug.LogError("实体管理器:ExistsHostileInSightRange 方法中,AffiliationManager 实例为空。无法确定实体关系。");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 预计算平方距离:避免在循环内部重复计算平方根,提高性能。
|
||||
var sightRangeSqr = sightRange * sightRange;
|
||||
var sourcePos = sourceEntityPrefab.transform.position;
|
||||
// 遍历所有实体:遍历维度内的所有派系,再遍历每个派系下的所有实体。
|
||||
foreach (var factionEntities in factionDict.Values)
|
||||
{
|
||||
foreach (var currentEntityPrefab in factionEntities)
|
||||
{
|
||||
// 实体有效性及排除源实体自身:
|
||||
// 1. 排除无效或已死亡的实体。
|
||||
// 2. 排除源实体自身。
|
||||
if (currentEntityPrefab == null || currentEntityPrefab.entity == null ||
|
||||
currentEntityPrefab.entity.IsDead || currentEntityPrefab == sourceEntityPrefab)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 关系判断:判断当前实体与源实体是否为“敌对”关系。
|
||||
if (affiliationManager.GetRelation(sourceEntityPrefab.entity, currentEntityPrefab.entity) ==
|
||||
Data.Relation.Hostile)
|
||||
{
|
||||
// 距离判断:如果关系敌对,进一步判断其是否在视野范围内。
|
||||
var distanceSqr = Vector3.SqrMagnitude(currentEntityPrefab.transform.position - sourcePos);
|
||||
if (distanceSqr <= sightRangeSqr)
|
||||
{
|
||||
return true; // 找到第一个视野范围内的敌对实体即返回 true。
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false; // 遍历完所有实体都未找到视野范围内的敌对实体。
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单例管理器启动时调用,订阅场景加载事件。
|
||||
/// </summary>
|
||||
@ -513,8 +720,8 @@ namespace Managers
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
_dimensionFactionEntities.Clear(); // 清理所有旧场景的实体数据。
|
||||
_dimensionLayerCache.Clear(); // 清理所有旧场景的层级缓存。
|
||||
|
||||
_dimensionLayerCache.Clear(); // 清理所有旧场景的层级缓存。
|
||||
|
||||
// 场景加载时清理待添加列表中的所有实体,因为它们可能属于旧场景或未在任何维度中被处理。
|
||||
foreach (var pending in _pendingAdditions)
|
||||
{
|
||||
@ -523,14 +730,15 @@ namespace Managers
|
||||
Destroy(pending.Item3.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
_pendingAdditions.Clear(); // 清理待添加实体列表。
|
||||
|
||||
// 在新场景加载完成后,遍历 Program 中已注册的所有维度,并为每个维度初始化 EntityManage 的内部数据结构。
|
||||
// 此时 Program.Awake() 应该已经完成,所有 Dimension 组件的 Awake() 也已执行,Program.RegisteredDimensions 应该包含了当前场景的所有维度。
|
||||
foreach (var registeredDimensionEntry in Program.Instance.RegisteredDimensions)
|
||||
{
|
||||
string dimensionId = registeredDimensionEntry.Key;
|
||||
Dimension dimension = registeredDimensionEntry.Value;
|
||||
var dimensionId = registeredDimensionEntry.Key;
|
||||
var dimension = registeredDimensionEntry.Value;
|
||||
|
||||
if (dimension != null) // 确保维度实例本身不是null。
|
||||
{
|
||||
@ -541,7 +749,8 @@ namespace Managers
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"实体管理器:在场景加载初始化期间,Program 为ID '{dimensionId}' 注册了一个空的 Dimension 对象。这可能表明维度注册存在问题。");
|
||||
Debug.LogWarning(
|
||||
$"实体管理器:在场景加载初始化期间,Program 为ID '{dimensionId}' 注册了一个空的 Dimension 对象。这可能表明维度注册存在问题。");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -559,7 +768,8 @@ namespace Managers
|
||||
defaultEntityPrefab = pre.GetComponent<EntityPrefab>();
|
||||
if (defaultEntityPrefab == null)
|
||||
{
|
||||
Debug.LogError($"实体管理器:已加载 DefaultEntity 预制体,但它缺少来自 Resources/Default/DefaultEntity 的 EntityPrefab 组件。请确保它包含该组件。");
|
||||
Debug.LogError(
|
||||
$"实体管理器:已加载 DefaultEntity 预制体,但它缺少来自 Resources/Default/DefaultEntity 的 EntityPrefab 组件。请确保它包含该组件。");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -36,59 +36,27 @@ namespace Managers
|
||||
$"ItemResourceManager: Duplicate itemDef.defName found: {def.defName}. Skipping this item.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var itemIcon = Managers.PackagesImageManager.Instance.GetSprite(def.texture);
|
||||
if (!itemIcon)
|
||||
{
|
||||
Debug.LogWarning(
|
||||
$"ItemResourceManager: Failed to load sprite for texture '{def.texture}' for item '{def.defName}'. Icon will be null.");
|
||||
}
|
||||
|
||||
var itemName = string.IsNullOrEmpty(def.label) ? def.defName : def.label;
|
||||
if (string.IsNullOrEmpty(def.label))
|
||||
{
|
||||
Debug.LogWarning(
|
||||
$"ItemResourceManager: ItemDef '{def.defName}' has an empty label. Using defName as item name.");
|
||||
}
|
||||
|
||||
var itemDescription = def.description ?? string.Empty;
|
||||
|
||||
|
||||
Item.ItemResource itemResource;
|
||||
|
||||
if (def is WeaponDef currentWeaponDef)
|
||||
{
|
||||
itemResource = new Item.WeaponResource(
|
||||
def.defName, // 传递 defName
|
||||
itemName,
|
||||
itemDescription,
|
||||
itemIcon,
|
||||
currentWeaponDef.rarity,
|
||||
currentWeaponDef.maxStack,
|
||||
currentWeaponDef.ssEquippable,
|
||||
currentWeaponDef.attributes
|
||||
currentWeaponDef
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemResource = new Item.ItemResource(
|
||||
def.defName, // 传递 defName
|
||||
itemName,
|
||||
itemDescription,
|
||||
itemIcon,
|
||||
def.rarity,
|
||||
def.maxStack,
|
||||
def.ssEquippable
|
||||
def
|
||||
);
|
||||
}
|
||||
|
||||
_items.Add(def.defName, itemResource);
|
||||
|
||||
// 将物品添加到按显示名称查找的字典 (这里仍然使用 itemResource.Name,因为字典的目的是按显示名称查找)
|
||||
if (!_itemsByName.ContainsKey(itemResource.Name))
|
||||
{
|
||||
_itemsByName.Add(itemResource.Name, new List<Item.ItemResource>());
|
||||
}
|
||||
|
||||
_itemsByName[itemResource.Name].Add(itemResource);
|
||||
}
|
||||
}
|
||||
@ -97,8 +65,6 @@ namespace Managers
|
||||
{
|
||||
return _items.GetValueOrDefault(defName, null);
|
||||
}
|
||||
|
||||
// FindItemByName 和 FindAllItemsByName 保持不变,因为它们是按显示名称查找的
|
||||
public Item.ItemResource FindItemByName(string itemName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(itemName)) return null;
|
||||
|
@ -33,7 +33,6 @@ namespace Managers
|
||||
// 如果已经被初始化,则直接返回
|
||||
if (tileToTileBaseMapping.Count > 0)
|
||||
{
|
||||
Debug.Log($"<color=green>{StepDescription}</color> 已初始化。跳过。");
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user