Fix unexpect item order in each tab of mall

This commit is contained in:
HungDK
2025-11-10 10:52:05 +07:00
parent 6b2737f779
commit 32d0aeff3a
@@ -144,9 +144,11 @@ public class ShopUIManager : MonoBehaviour
List<GShopItem> categoryItems = GetItemsForCategory(currentCategory);
// Create item panels using pooling
int siblingIndexCounter = 0;
foreach (GShopItem item in categoryItems)
{
CreateItemPanelFromPool(item);
CreateItemPanelFromPool(item, siblingIndexCounter);
siblingIndexCounter++;
}
}
@@ -183,7 +185,7 @@ public class ShopUIManager : MonoBehaviour
}
}
void CreateItemPanelFromPool(GShopItem item)
void CreateItemPanelFromPool(GShopItem item, int targetSiblingIndex)
{
GameObject itemPanel = null;
@@ -204,8 +206,10 @@ public class ShopUIManager : MonoBehaviour
if (itemPanel != null && itemContainer != null)
{
// Set parent and position
itemPanel.transform.SetParent(itemContainer);
itemPanel.transform.SetParent(itemContainer, false);
itemPanel.transform.localScale = Vector3.one;
// Ensure deterministic ordering regardless of pool retrieval order
itemPanel.transform.SetSiblingIndex(targetSiblingIndex);
// Setup the panel
ShopItemPanel itemPanelScript = itemPanel.GetComponent<ShopItemPanel>();