//显示背包物品 void ShowKnapsackItemInfo() { if (m_BaseWndObject == null || m_BaseWndObject.activeSelf != true) { return; } ClearKnapsackGird(); int Idx = 0; if (PlayerRole.Instance.ItemManager.GetAllItemMap() == null) { //InitEmptyKnapsack(Idx, 14); return; } m_KnapList.Clear(); foreach (KeyValuePair <uint, tagItemInfo> map in PlayerRole.Instance.ItemManager.GetAllItemMap()) { if (FishConfig.Instance.m_ItemInfo.m_ItemMap.ContainsKey(map.Value.ItemID) == false) { continue; } tagItemConfig pItemConfig = FishConfig.Instance.m_ItemInfo.m_ItemMap[map.Value.ItemID]; if (pItemConfig.ItemTypeID == EItemType.IT_Cannon) { continue; } KnapsackItem knapsack = new KnapsackItem(); knapsack.Init(templateGoodItem); string IconName = ""; IconName = pItemConfig.ItemIcon; knapsack.SetItemInfo(map.Value.ItemID, PlayerRole.Instance.ItemManager.GetItemSum(map.Value.ItemID, false), IconName, map.Value.ItemOnlyID, pItemConfig.ItemTypeID); m_KnapList.Add(knapsack); } templateGoodItem.SetActive(false); //m_KnapList.Sort(CompareItemByID); RectTransform rectTransform = gridGoods.GetComponent <RectTransform>(); rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, m_KnapList.Count * 300 / 3); for (byte i = 0; i < m_KnapList.Count; ++i) { m_KnapList[i].m_BaseTrans.parent = gridGoods.transform; m_KnapList[i].ResetLoaclScale(); ++Idx; } if (Idx < 14) { InitEmptyKnapsack(Idx, 14); } else { if ((Idx % 7) != 0) { InitEmptyKnapsack(Idx, (Idx / 7 + 1) * 7); } } m_KnapList.Clear(); }
void InitEmptyKnapsack(int Idx, int MaxIdx) { for (int i = Idx; i < MaxIdx; ++i) { KnapsackItem knapsack = new KnapsackItem(); knapsack.Init(templateGoodItem); knapsack.m_BaseTrans.parent = gridGoods.transform; knapsack.ResetLoaclScale(); } }
static int CompareItemByID(KnapsackItem item1, KnapsackItem item2) { if (item1.ItemID < item2.ItemID) { return(-1); } else if (item1.ItemID > item2.ItemID) { return(1); } else { return(0); } }