コード例 #1
0
ファイル: InventoryPanel.cs プロジェクト: dmariaa/ESDM
        private void Start()
        {
            GlobalGameState.Instance.CurrentGameState.inventory.RegisterListener(this);

            GameObject prefab        = Resources.Load <GameObject>("Prefabs/InventorySlot");
            int        numberOfSlots = GlobalGameState.Instance.CurrentGameState.inventory.getLength();

            for (int i = 0; i < numberOfSlots; i++)
            {
                int row = i % 2;
                int col = i / 2;

                GameObject slot = Instantiate(prefab, transform);
                slot.name = String.Format("InventorySlot[{0}][{1}]", row, col);
                slot.SetActive(true);

                InventoryPanelSlot inventoryPanelSlot = slot.GetComponent <InventoryPanelSlot>();
                inventoryPanelSlot.gridPosition = new Vector2Int(row, col);
                slots.Add(inventoryPanelSlot);

                AbstractItem item = GlobalGameState.Instance.CurrentGameState.inventory.GetItem(i);
                if (item)
                {
                    slot.GetComponent <InventoryPanelSlot>().Item = item;
                }
            }

            _rectTransform = GetComponent <RectTransform>();
        }
コード例 #2
0
ファイル: InventoryPanel.cs プロジェクト: dmariaa/ESDM
        public void SelectSlot(InventoryPanelSlot slot)
        {
            if (slot == null)
            {
                return;
            }

            _selectedSlot?.SelectSlot(false);
            _selectedSlot = slot;
            _selectedSlot.SelectSlot(true);

            if (_selectedSlot.Item != null)
            {
                informationPanel?.GetComponent <ItemInformationPanel>().Show(_selectedSlot.Item);
            }
            else
            {
                informationPanel?.GetComponent <ItemInformationPanel>().Hide();
            }
        }
コード例 #3
0
ファイル: InventoryPanel.cs プロジェクト: dmariaa/ESDM
 public void InventorySlotClick(InventoryPanelSlot slot)
 {
     SelectSlot(slot);
     _selectedSlot = slot;
 }