private void ReconstructionItemPanel(Database.db_item.Type type) { itemPanelHolder.GetComponentInChildren <ScrollRect>().verticalNormalizedPosition = 0; if (!itemPanelHolder.gameObject.activeSelf) { itemPanelHolder.gameObject.SetActive(true); } for (int i = 0; i < itemPanelButtonList.Count; i++) { DestroyImmediate(itemPanelButtonList[i].gameObject); } itemPanelButtonList.Clear(); for (int i = 0; i < itemsToShow.Count; i++) { if (itemsToShow[i].type != type) { continue; } int index = itemPanelButtonList.Count; Database.db_item tempItem = itemsToShow[i]; Transform tempButton = Instantiate(buttonPrefab); tempButton.SetParent(itemPanel); tempButton.GetComponent <Button>().onClick.AddListener(() => ItemClickButton(tempItem, index)); tempButton.GetComponentInChildren <Text>().text = itemsToShow[i].name; tempButton.gameObject.SetActive(true); itemPanelButtonList.Add(tempButton); } }
private void ReconstructionCategoryPanel() { itemsToShow.Clear(); categoryPanelHolder.GetComponentInChildren <ScrollRect>().verticalNormalizedPosition = 1f; for (int i = 0; i < categoryPanelButtonList.Count; i++) { DestroyImmediate(categoryPanelButtonList[i].gameObject); } categoryPanelButtonList.Clear(); List <Database.db_item.Type> types = new List <Database.db_item.Type>(); List <NetworkItem> tempItems = Game.GetPlayer().GetItems(); for (int i = 0; i < tempItems.Count; i++) { int index = Database.GetDBItemList().FindIndex(x => x.id == tempItems[i].id); if (index == -1) { Debug.LogError("Inventory request for itemId '" + tempItems[i] + "' but this itemId is not in local database!"); continue; } itemsToShow.Add(Database.GetDBItemList()[index]); } //itemsToShow = Database.GetDBItemList().FindAll(x => Array.IndexOf(GetItemIDs(), x.id) != -1); for (int i = 0; i < itemsToShow.Count; i++) { if (types.Contains(itemsToShow[i].type)) { continue; } types.Add(itemsToShow[i].type); int index = categoryPanelButtonList.Count; Database.db_item.Type tempType = itemsToShow[i].type; Transform tempButton = Instantiate(buttonPrefab); tempButton.SetParent(categoryPanel); tempButton.GetComponent <Button>().onClick.AddListener(() => CategoryItemClickButton(tempType, index)); tempButton.GetComponentInChildren <Text>().text = itemsToShow[i].type.ToString(); tempButton.gameObject.SetActive(true); categoryPanelButtonList.Add(tempButton); } }
public void CategoryItemClickButton(Database.db_item.Type type, int index) { categoryPanelHolder.GetComponentInChildren <ScrollRect>().verticalNormalizedPosition = 1f - (index / ((float)categoryPanelButtonList.Count - 1)); ReconstructionItemPanel(type); }