(client) chore:UI
This commit is contained in:
@ -4272,6 +4272,7 @@ MonoBehaviour:
|
||||
globalVolume: {fileID: 2316664195302985391}
|
||||
developerMode: {fileID: 1748158905204360579}
|
||||
friendlyFire: {fileID: 1204233337456510451}
|
||||
showMiniMap: {fileID: 2665600169125004565}
|
||||
windowMode: {fileID: 2798388203338564097}
|
||||
windowResolution: {fileID: 8445153130951204632}
|
||||
progressStepDuration: {fileID: 7303802091805124928}
|
||||
|
@ -912,7 +912,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &629678390
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -2493,6 +2493,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: feb227be5c204aaea27e09f754dc05b8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
background: {fileID: 1866986817}
|
||||
texture: {fileID: 476295826}
|
||||
--- !u!1 &1890891270
|
||||
GameObject:
|
||||
|
@ -17,29 +17,19 @@ namespace Entity
|
||||
/// 当前选中的背包槽位索引。
|
||||
/// 当此值被设置时,如果与旧值不同,将触发 OnCurrentSelectedChanged 事件。
|
||||
/// </summary>
|
||||
public int currentSelected
|
||||
public int CurrentSelected
|
||||
{
|
||||
get => _currentSelected;
|
||||
set
|
||||
{
|
||||
var maxIndex = Inventory != null && Inventory.Capacity > 0 ? Inventory.Capacity - 1 : 0;
|
||||
var clampedValue = Mathf.Clamp(value, 0, maxIndex);
|
||||
|
||||
if (_currentSelected != clampedValue)
|
||||
{
|
||||
_currentSelected = clampedValue;
|
||||
OnCurrentSelectedChanged?.Invoke(_currentSelected); // 触发事件
|
||||
}
|
||||
_currentSelected = clampedValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Inventory Inventory { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当当前选中的槽位索引改变时触发的事件。
|
||||
/// 参数:新的选中索引。
|
||||
/// </summary>
|
||||
public event Action<int> OnCurrentSelectedChanged;
|
||||
|
||||
|
||||
public override void Init(EntityDef entityDef)
|
||||
{
|
||||
@ -51,7 +41,7 @@ namespace Entity
|
||||
// 使用属性来设置,确保触发事件和范围检查。
|
||||
// 如果Inventory.Capacity为0,则currentSelected会被钳制到0。
|
||||
// 如果Inventory.Capacity为3,currentSelected=0是有效值。
|
||||
currentSelected = 0;
|
||||
CurrentSelected = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,7 +93,7 @@ namespace Entity
|
||||
|
||||
public override WeaponResource GetCurrentWeapon()
|
||||
{
|
||||
var currentSelectItem = Inventory.GetSlot(currentSelected);
|
||||
var currentSelectItem = Inventory.GetSlot(CurrentSelected);
|
||||
return (WeaponResource)currentSelectItem.Item;
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +158,8 @@ namespace Entity
|
||||
}
|
||||
public InventorySlot GetSlot(int i)
|
||||
{
|
||||
i = Mathf.Clamp(i, 0, Capacity - 1);
|
||||
if (i < 0 || i >= OccupiedSlotsCount)
|
||||
return null;
|
||||
return _slots[i];
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,9 @@ namespace Entity
|
||||
{
|
||||
var entity = other.GetComponent<Character>();
|
||||
if (entity == null) return;
|
||||
if (entity.TryPickupItem(itemResource, 1) == 0)
|
||||
if (entity.TryPickupItem(itemResource, 1) <= 0)
|
||||
{
|
||||
Debug.Log("Kill");
|
||||
Kill();
|
||||
}
|
||||
}
|
||||
|
@ -468,11 +468,27 @@ namespace Managers
|
||||
GenerateDefaultEntity(dimensionId, pos);
|
||||
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 pickup = result.GetComponent<Pickup>();
|
||||
result.transform.SetParent(parentLayer);
|
||||
pickup.Init(itemDef);
|
||||
|
||||
if (result == null) GenerateDefaultEntity(dimensionId, pos);
|
||||
_pendingAdditions.Add(Tuple.Create(dimensionId, "default", result));
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 在指定维度和位置生成一个默认实体(通常作为回退选项)。
|
||||
|
@ -28,9 +28,6 @@ namespace Map
|
||||
if (string.IsNullOrEmpty(_dimensionId))
|
||||
{
|
||||
_dimensionId = gameObject.name; // 如果未设置,默认使用GameObject名称
|
||||
Debug.LogWarning(
|
||||
$"Dimension ID not explicitly set for {gameObject.name}. Using GameObject name as ID: {_dimensionId}",
|
||||
this);
|
||||
}
|
||||
|
||||
return _dimensionId;
|
||||
|
@ -6,6 +6,7 @@ namespace Map
|
||||
{
|
||||
public class MiniMap : MonoBehaviour,ITickUI
|
||||
{
|
||||
public Image background;
|
||||
public RawImage texture;
|
||||
private bool _show = true;
|
||||
|
||||
@ -16,6 +17,7 @@ namespace Map
|
||||
{
|
||||
_show = Setting.Instance.CurrentSettings.showMiniMap;
|
||||
texture.gameObject.SetActive(_show);
|
||||
background.enabled = _show;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ namespace UI
|
||||
private void Start()
|
||||
{
|
||||
Program.Instance.OnFocusedEntityChanged += UpdateFocusedEntity;
|
||||
uiParent.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -117,6 +118,7 @@ namespace UI
|
||||
itemUI.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
uiParent.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -128,9 +130,7 @@ namespace UI
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前关注角色库存中的所有物品槽位。
|
||||
var slots = focusedEntity.Inventory.GetSlots();
|
||||
int requiredUIs = slots.Count; // 需要显示和激活的 ItemUI 数量。
|
||||
int requiredUIs = focusedEntity.Inventory.Capacity;
|
||||
int currentUIPoolSize = itemUIPool.Count; // 当前对象池中 ItemUI 实例的总数。
|
||||
|
||||
// 遍历所有必要的物品槽位,复用对象池中的 ItemUI,或在不足时创建新的 ItemUI。
|
||||
@ -143,14 +143,16 @@ namespace UI
|
||||
}
|
||||
else
|
||||
{
|
||||
itemUI = Instantiate(itemUIPrefab, uiParent.transform);
|
||||
var itemObj=Instantiate(itemUIPrefab.gameObject, uiParent.transform);
|
||||
itemUI = itemObj.GetComponent<ItemUI>();
|
||||
itemUIPool.Add(itemUI);
|
||||
currentUIPoolSize++; // 更新池的大小计数。
|
||||
}
|
||||
|
||||
// 确保 ItemUI GameObject 处于激活状态,并使用当前物品槽位的数据进行初始化。
|
||||
itemUI.gameObject.SetActive(true);
|
||||
itemUI.Init(slots[i], i);
|
||||
itemUI.Init(focusedEntity.Inventory.GetSlot(i), i);
|
||||
itemUI.Select = false;
|
||||
}
|
||||
|
||||
// 如果库存槽位数量减少,禁用对象池中多余的 ItemUI 实例。
|
||||
@ -161,6 +163,7 @@ namespace UI
|
||||
itemUIPool[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
uiParent.SetActive(true);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user