Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void Init(InventoryModel.ItemModel item)
        {
            this.item = item;

            RefreshView();

            // add property changed handlers
            item.PropertyChanged += OnItemModelPropertyChanged;
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }