Beispiel #1
0
    public void UpdateInventory()
    {
        for (int i = 0; i < inventoryPanel.transform.childCount; i++)
        {
            InventButton _invButton = inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent <InventButton>();


            if (_invButton != null)
            {
                //if(listGameItem[i] == null)
                //{
                //    //Сброс значений всех пустых ячеек
                //    if (_invButton != null) _invButton._gameItemRef = null;
                //    inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent<Image>().sprite = _invButton.emptyButtonSprite;
                //    inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent<Image>().color = _invButton.emptyButtonColor;
                //    _invButton.transform.GetChild(0).GetChild(0).GetComponent<Text>().text = "";
                //    continue;
                //}

                if (i > listGameItem.Count - 1)
                {
                    if (_invButton != null)
                    {
                        _invButton._gameItemRef = null;
                    }
                    inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().sprite = _invButton.emptyButtonSprite;
                    inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().color  = _invButton.emptyButtonColor;
                    _invButton.transform.GetChild(0).GetChild(0).GetComponent <Text>().text        = "";
                    continue;
                }
                else
                {
                    //Установить  картинку объекта
                    inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().sprite = listGameItem[i]._itemSprite;
                    _invButton._gameItemRef = listGameItem[i]; //Установка связи между ячейкой и предметом
                    _invButton.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = "";
                    if (_invButton._gameItemRef._oneOffItem)   //Показать количество для одноразовых предметов
                    {
                        if (oneOffItemsCount.ContainsKey(_invButton._gameItemRef._itemID))
                        {
                            _invButton._gameItemRef._count = oneOffItemsCount[_invButton._gameItemRef._itemID];//Увеличим количество
                            if (_invButton._gameItemRef._count > 0)
                            {
                                _invButton.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = _invButton._gameItemRef._count.ToString();
                            }
                        }
                    }
                }
            }

            //Делаем максимальную прозрачность ячейки
            Color buffColor = inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().color;
            Color newColor  = new Color(buffColor.r, buffColor.g, buffColor.b, 255);
            inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent <Image>().color = newColor;
        }
    }
Beispiel #2
0
    public void PressCellButton(GameObject _object)
    {
        //Обработка нажатия на ячейке в инвентаре
        //Здесь необходимо обрабатывать нажатие в зависимости от типа объекта(зелье,оружие и тд)
        InventButton _invButton = _object.transform.GetChild(0).GetComponent <InventButton>();

        if (_invButton._gameItemRef == null)
        {
            return;
        }

        UseItemFromInventory(_invButton._gameItemRef);
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        invAnimator = inventoryPanelWindow.GetComponent <Animator>();
        inventoryPanelWindow.SetActive(false);
        ToolTipWindow.SetActive(false);
        listGameItem     = new List <GameItem>();
        oneOffItemsCount = new Dictionary <string, int>();

        for (int i = 0; i < inventoryPanel.transform.childCount; i++)
        {
            InventButton _invButton = inventoryPanel.transform.GetChild(i).GetChild(0).GetComponent <InventButton>();
            if (_invButton != null)
            {
                _invButton.index = i;
                //GameItem _item = null;
                //listGameItem.Add(_item);
            }
        }
    }
Beispiel #4
0
    public void OnDrop(PointerEventData eventData)
    {
        Debug.Log("OnDrop");
        Debug.Log("OnDrop name =" + eventData.pointerDrag.name);

        //Добавляем предмет в QuickBar из инвентаря
        InventButton invButton = eventData.pointerDrag.GetComponent <InventButton>();

        if (invButton != null)
        {
            if (invButton._gameItemRef != null)
            {
                quickBar.AddGameItem(invButton._gameItemRef, index);
            }
        }

        //Перемещение из ячейки квик бара
        QuickBarCell qBcell = eventData.pointerDrag.GetComponent <QuickBarCell>();

        if (qBcell != null)
        {
            quickBar.ReplaceGameItem(index, qBcell.GetIndex());
        }
    }