//------------------------------------------------------------------------------------------------------------------------ // DrawItems() //------------------------------------------------------------------------------------------------------------------------ private void DrawItems() { List <Item> items = shop.GetItems(); for (int index = 0; index < items.Count; index++) { Item item = items[index]; int iconX = GetColumnByIndex(index) * Spacing + Margin; int iconY = GetRowByIndex(index) * Spacing + Margin; if (item == shop.GetSelectedItem()) { DrawItem(item, iconX, iconY, true); } else { DrawItem(item, iconX, iconY, false); } } }
//------------------------------------------------------------------------------------------------------------------------ // AddItemToView() //------------------------------------------------------------------------------------------------------------------------ //Adds a new icon. An icon is a prefab Button with some additional scripts to link it to the store Item private void AddItemToView(Item item) { GameObject newItemIcon = GameObject.Instantiate(itemPrefab); newItemIcon.transform.SetParent(itemLayoutGroup.transform); newItemIcon.transform.localScale = Vector3.one;//The scale would automatically change in Unity so we set it back to Vector3.one. ItemContainer itemContainer = newItemIcon.GetComponent <ItemContainer>(); Debug.Assert(itemContainer != null); bool isSelected = (item == shopModel.GetSelectedItem()); itemContainer.Initialize(item, isSelected); //Click behaviour for the button is done here. It seemed more convenient to do this inline than in the editor. Button itemButton = itemContainer.GetComponent <Button>(); itemButton.onClick.AddListener( delegate { shopController.SelectItem(item); RepopulateItemIconView(); //we need an Event system instead of this } ); }
public int GetItemPrice() { return(_shopModel.GetSelectedItem().price); }