(client) chore:UI
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user