void AddItemView(InventoryModel.ItemModel item) { // create view var view = Instantiate <GameObject>(viewPrefab); // attach to container view.transform.SetParent(container, false); view.transform.SetAsLastSibling(); // activate view if (!view.activeSelf) { view.SetActive(true); } // initialize control var control = view.GetComponent <ItemControl>(); control.Init(item); // add button listener control.clickButton.onClick.AddListener(() => SelectItem(item)); // add to dictionary controlDictionary.Add(item, control); }
public void AddItem() { // create item model var name = string.Format("{0:D02}", itemIndex++); var item = new InventoryModel.ItemModel(0, name, defaultAmount); // call wrapper method inventory.AddItem(item); }
public void Init(InventoryModel.ItemModel item) { this.item = item; RefreshView(); // add property changed handlers item.PropertyChanged += OnItemModelPropertyChanged; }
void RemoveItemView(InventoryModel.ItemModel item) { // get control var control = controlDictionary[item]; // remove button listener control.clickButton.onClick.RemoveAllListeners(); // destroy view Destroy(control.gameObject); // remove from dictionary controlDictionary.Remove(item); }
public void SelectItem(InventoryModel.ItemModel item) { Debug.LogFormat("SelectItem, item={0}", (item != null) ? item.Name : "null"); selectedItem = item; // disable all foreach (var kvp in controlDictionary) { var control = kvp.Value; control.Selected = false; } if (selectedItem != null) { var selectedControl = controlDictionary[item]; selectedControl.Selected = true; } // update UI useItemButton.interactable = (selectedItem != null); }