(client) chore:UI

This commit is contained in:
m0_75251201
2025-08-27 14:45:12 +08:00
parent 0c99e2beee
commit 63efa89ac1
10 changed files with 126 additions and 60 deletions

View File

@ -4272,6 +4272,7 @@ MonoBehaviour:
globalVolume: {fileID: 2316664195302985391} globalVolume: {fileID: 2316664195302985391}
developerMode: {fileID: 1748158905204360579} developerMode: {fileID: 1748158905204360579}
friendlyFire: {fileID: 1204233337456510451} friendlyFire: {fileID: 1204233337456510451}
showMiniMap: {fileID: 2665600169125004565}
windowMode: {fileID: 2798388203338564097} windowMode: {fileID: 2798388203338564097}
windowResolution: {fileID: 8445153130951204632} windowResolution: {fileID: 8445153130951204632}
progressStepDuration: {fileID: 7303802091805124928} progressStepDuration: {fileID: 7303802091805124928}

View File

@ -912,7 +912,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &629678390 --- !u!224 &629678390
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2493,6 +2493,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: feb227be5c204aaea27e09f754dc05b8, type: 3} m_Script: {fileID: 11500000, guid: feb227be5c204aaea27e09f754dc05b8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
background: {fileID: 1866986817}
texture: {fileID: 476295826} texture: {fileID: 476295826}
--- !u!1 &1890891270 --- !u!1 &1890891270
GameObject: GameObject:

View File

@ -17,29 +17,19 @@ namespace Entity
/// 当前选中的背包槽位索引。 /// 当前选中的背包槽位索引。
/// 当此值被设置时,如果与旧值不同,将触发 OnCurrentSelectedChanged 事件。 /// 当此值被设置时,如果与旧值不同,将触发 OnCurrentSelectedChanged 事件。
/// </summary> /// </summary>
public int currentSelected public int CurrentSelected
{ {
get => _currentSelected; get => _currentSelected;
set set
{ {
var maxIndex = Inventory != null && Inventory.Capacity > 0 ? Inventory.Capacity - 1 : 0; var maxIndex = Inventory != null && Inventory.Capacity > 0 ? Inventory.Capacity - 1 : 0;
var clampedValue = Mathf.Clamp(value, 0, maxIndex); var clampedValue = Mathf.Clamp(value, 0, maxIndex);
_currentSelected = clampedValue;
if (_currentSelected != clampedValue)
{
_currentSelected = clampedValue;
OnCurrentSelectedChanged?.Invoke(_currentSelected); // 触发事件
}
} }
} }
public Inventory Inventory { get; private set; } public Inventory Inventory { get; private set; }
/// <summary>
/// 当当前选中的槽位索引改变时触发的事件。
/// 参数:新的选中索引。
/// </summary>
public event Action<int> OnCurrentSelectedChanged;
public override void Init(EntityDef entityDef) public override void Init(EntityDef entityDef)
{ {
@ -51,7 +41,7 @@ namespace Entity
// 使用属性来设置,确保触发事件和范围检查。 // 使用属性来设置,确保触发事件和范围检查。
// 如果Inventory.Capacity为0则currentSelected会被钳制到0。 // 如果Inventory.Capacity为0则currentSelected会被钳制到0。
// 如果Inventory.Capacity为3currentSelected=0是有效值。 // 如果Inventory.Capacity为3currentSelected=0是有效值。
currentSelected = 0; CurrentSelected = 0;
} }
/// <summary> /// <summary>
@ -103,7 +93,7 @@ namespace Entity
public override WeaponResource GetCurrentWeapon() public override WeaponResource GetCurrentWeapon()
{ {
var currentSelectItem = Inventory.GetSlot(currentSelected); var currentSelectItem = Inventory.GetSlot(CurrentSelected);
return (WeaponResource)currentSelectItem.Item; return (WeaponResource)currentSelectItem.Item;
} }
} }

View File

@ -158,7 +158,8 @@ namespace Entity
} }
public InventorySlot GetSlot(int i) public InventorySlot GetSlot(int i)
{ {
i = Mathf.Clamp(i, 0, Capacity - 1); if (i < 0 || i >= OccupiedSlotsCount)
return null;
return _slots[i]; return _slots[i];
} }

View File

@ -61,8 +61,9 @@ namespace Entity
{ {
var entity = other.GetComponent<Character>(); var entity = other.GetComponent<Character>();
if (entity == null) return; if (entity == null) return;
if (entity.TryPickupItem(itemResource, 1) == 0) if (entity.TryPickupItem(itemResource, 1) <= 0)
{ {
Debug.Log("Kill");
Kill(); Kill();
} }
} }

View File

@ -468,11 +468,27 @@ namespace Managers
GenerateDefaultEntity(dimensionId, pos); GenerateDefaultEntity(dimensionId, pos);
return; return;
} }
var dimension = Program.Instance.GetDimension(dimensionId);
if (dimension == null)
{
Debug.LogError($"实体管理器:无法生成实体:维度 '{dimensionId}' 在程序Program中不活跃或未注册。");
return;
}
// 获取或创建实体所属的层级Transform并确保其在维度根下。
var parentLayer = EnsureLayerExists(dimensionId, "DefaultEntityLevel");
if (parentLayer == null)
{
Debug.LogError($"实体管理器:无法在维度 '{dimensionId}' 中获取或创建实体的父层。");
return;
}
var result=Instantiate(pickupPrefab, pos, Quaternion.identity); var result=Instantiate(pickupPrefab, pos, Quaternion.identity);
var pickup = result.GetComponent<Pickup>(); var pickup = result.GetComponent<Pickup>();
result.transform.SetParent(parentLayer);
pickup.Init(itemDef); pickup.Init(itemDef);
if (result == null) GenerateDefaultEntity(dimensionId, pos); if (result == null) GenerateDefaultEntity(dimensionId, pos);
_pendingAdditions.Add(Tuple.Create(dimensionId, "default", result));
} }
/// <summary> /// <summary>
/// 在指定维度和位置生成一个默认实体(通常作为回退选项)。 /// 在指定维度和位置生成一个默认实体(通常作为回退选项)。

View File

@ -28,9 +28,6 @@ namespace Map
if (string.IsNullOrEmpty(_dimensionId)) if (string.IsNullOrEmpty(_dimensionId))
{ {
_dimensionId = gameObject.name; // 如果未设置默认使用GameObject名称 _dimensionId = gameObject.name; // 如果未设置默认使用GameObject名称
Debug.LogWarning(
$"Dimension ID not explicitly set for {gameObject.name}. Using GameObject name as ID: {_dimensionId}",
this);
} }
return _dimensionId; return _dimensionId;

View File

@ -6,6 +6,7 @@ namespace Map
{ {
public class MiniMap : MonoBehaviour,ITickUI public class MiniMap : MonoBehaviour,ITickUI
{ {
public Image background;
public RawImage texture; public RawImage texture;
private bool _show = true; private bool _show = true;
@ -16,6 +17,7 @@ namespace Map
{ {
_show = Setting.Instance.CurrentSettings.showMiniMap; _show = Setting.Instance.CurrentSettings.showMiniMap;
texture.gameObject.SetActive(_show); texture.gameObject.SetActive(_show);
background.enabled = _show;
} }
} }
} }

View File

@ -38,6 +38,7 @@ namespace UI
private void Start() private void Start()
{ {
Program.Instance.OnFocusedEntityChanged += UpdateFocusedEntity; Program.Instance.OnFocusedEntityChanged += UpdateFocusedEntity;
uiParent.SetActive(false);
} }
/// <summary> /// <summary>
@ -117,6 +118,7 @@ namespace UI
itemUI.gameObject.SetActive(false); itemUI.gameObject.SetActive(false);
} }
} }
uiParent.SetActive(false);
return; return;
} }
@ -128,9 +130,7 @@ namespace UI
return; return;
} }
// 获取当前关注角色库存中的所有物品槽位。 int requiredUIs = focusedEntity.Inventory.Capacity;
var slots = focusedEntity.Inventory.GetSlots();
int requiredUIs = slots.Count; // 需要显示和激活的 ItemUI 数量。
int currentUIPoolSize = itemUIPool.Count; // 当前对象池中 ItemUI 实例的总数。 int currentUIPoolSize = itemUIPool.Count; // 当前对象池中 ItemUI 实例的总数。
// 遍历所有必要的物品槽位,复用对象池中的 ItemUI或在不足时创建新的 ItemUI。 // 遍历所有必要的物品槽位,复用对象池中的 ItemUI或在不足时创建新的 ItemUI。
@ -143,14 +143,16 @@ namespace UI
} }
else else
{ {
itemUI = Instantiate(itemUIPrefab, uiParent.transform); var itemObj=Instantiate(itemUIPrefab.gameObject, uiParent.transform);
itemUI = itemObj.GetComponent<ItemUI>();
itemUIPool.Add(itemUI); itemUIPool.Add(itemUI);
currentUIPoolSize++; // 更新池的大小计数。 currentUIPoolSize++; // 更新池的大小计数。
} }
// 确保 ItemUI GameObject 处于激活状态,并使用当前物品槽位的数据进行初始化。 // 确保 ItemUI GameObject 处于激活状态,并使用当前物品槽位的数据进行初始化。
itemUI.gameObject.SetActive(true); itemUI.gameObject.SetActive(true);
itemUI.Init(slots[i], i); itemUI.Init(focusedEntity.Inventory.GetSlot(i), i);
itemUI.Select = false;
} }
// 如果库存槽位数量减少,禁用对象池中多余的 ItemUI 实例。 // 如果库存槽位数量减少,禁用对象池中多余的 ItemUI 实例。
@ -161,6 +163,7 @@ namespace UI
itemUIPool[i].gameObject.SetActive(false); itemUIPool[i].gameObject.SetActive(false);
} }
} }
uiParent.SetActive(true);
} }
public void Tick() public void Tick()

File diff suppressed because one or more lines are too long