private void Awake() { var shelfs = new List <Shelf>(shelfParent.GetComponentsInChildren <Shelf>()); shelfs.Sort((x, y) => x.productName.CompareTo(y.productName)); //Sort list alphabetical //For every shelf add a button in the list planner foreach (var shelf in shelfs) { var item = Instantiate(itemPrefab); item.transform.SetParent(shopViewPortContent); item.Setup(this, shelf, item.transform.GetSiblingIndex()); } shoppingList = new List <ShopAsset>(); //Add the entrypoint and checkout to the shopping list as not clickable buttons entrypointBtn = Instantiate(itemPrefab); entrypointBtn.transform.SetParent(listViewPortContent); entrypointBtn.Setup(this, GetEntrypoint(), -1); entrypointBtn.buttonComponent.interactable = false; checkoutBtn = Instantiate(itemPrefab); checkoutBtn.transform.SetParent(listViewPortContent); checkoutBtn.Setup(this, ChooseRandomCheckout(), -1); checkoutBtn.buttonComponent.interactable = false;; }
private void generateSellButton(Item item) { GameObject newButton = (GameObject)GameObject.Instantiate(prefab); newButton.transform.SetParent(contentPanel); ItemButton sellButton = newButton.GetComponent <ItemButton>(); sellButton.Setup(item, this); }
private void AddButtons() { for (int i = 0; i < itemList.Count; i++) { Item item = itemList[i]; GameObject newButton = buttonObjectPool.GetObject(); newButton.transform.SetParent(contentPanel); ItemButton itemButton = newButton.GetComponent <ItemButton>(); itemButton.Setup(item, this); } }
private void generateCraftButton(Item item, Building building) { if (item.buildingLvl <= building.level) { GameObject newButton = (GameObject)GameObject.Instantiate(prefab); newButton.transform.SetParent(contentPanel); ItemButton craftButton = newButton.GetComponent <ItemButton>(); craftButton.Setup(item, this); } }
/** * Go through the items list and see how many items are there * Add item buttons as needed for each item * Call the setup funtion in ItemButton */ private void AddItemButtons() { for (int i = 0; i < Storage.Instance.unlockedItems.Count; i++) { // new item = the item at the current index in unlockedItems Item item = Storage.Instance.unlockedItems[i]; // get an object from the pool and store the reference in the new button GameObject newItemButton = itemButtonObjectPool.GetObject(); // set the parent of the new button to the content panel newItemButton.transform.SetParent(contentPanel, false); newItemButton.transform.localScale = new Vector3(1, 1, 1); // Get a reference to the item button script ItemButton itemButton = newItemButton.GetComponent <ItemButton>(); // pass item and a reference to this crafting list itemButton.Setup(item, this); } }
//взять кнопку из пула и просетапить ее полученным аргументом itemToSetupWith public void TakeOneButtonFromPoolAndSetupWith(Item itemToSetupWith) { GameObject returningGameObject = buttonObjectPool.GetObject(this.transform); ItemButton buttonUnderConstruction = returningGameObject.GetComponent <ItemButton> (); buttonUnderConstruction.Setup(itemToSetupWith); // фиксим якоря и оффсеты при возвращении из пула RectTransform buttonRectTransform = buttonUnderConstruction.GetComponent <RectTransform>(); buttonRectTransform.anchorMax = new Vector2(1, 1); buttonRectTransform.anchorMin = new Vector2(0, 0); buttonRectTransform.offsetMin = new Vector2(buttonRectTransform.offsetMin.x, 0); buttonRectTransform.offsetMax = new Vector2(buttonRectTransform.offsetMax.x, 0); buttonRectTransform.offsetMin = new Vector2(buttonRectTransform.offsetMin.y, 0); buttonRectTransform.offsetMax = new Vector2(buttonRectTransform.offsetMax.y, 0); }
private void ChangeCheckout(int index) { checkoutBtn.Setup(this, checkouts[index], -1); }