Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }

        _slotRoot = transform.Find("SlotGroup");
        _slots    = new List <CSlotController>();

        for (int i = 0; i < _slotRoot.childCount; i++)
        {
            Debug.Log("get item");
            var slot = _slotRoot.GetChild(i).GetComponent <CSlotController>();
            slot.SetItem(CItemDropTable.instance.DropRandomItem(CCreateMap.instance.GetStageNumber()));

            _slots.Add(slot);
        }

        _positionX = 0;
        _positionY = 0;
        _lastSlot  = 0;
        _arrow     = EArrow._right;

        _notEnoughGoldPopUp            = GameObject.Find("NotEnoughGoldPopUp").transform.Find("Canvas").gameObject;
        _confirmPurchaseIntentionPopup = GameObject.Find("ConfirmPurchaseIntentionPopUp");
        _confirmPurchaseIntentionPopup.SetActive(false);

        _player     = CController.instance.player;
        _playerPara = _player.GetComponent <CPlayerPara>();

        //debug용 추후 삭제
        _playerPara.Inventory.Gold += 500;

        ShowInventoryGold();
    }
Пример #2
0
    private void ChangeSlot()
    {
        if (CheckSoldOut())
        {
            return;                                            //상점 품절 체크
        }
        if (_confirmPurchaseIntentionPopup.activeSelf == true) //구매 재확인 팝업 켜져있을경우
        {
            if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow))
            {
                Image yesButton = _confirmPurchaseIntentionPopup.transform.GetChild(0).Find("Yes").GetComponent <Image>();
                Image noButton  = _confirmPurchaseIntentionPopup.transform.GetChild(0).Find("No").GetComponent <Image>();

                if (yesButton.enabled == true)
                {
                    yesButton.enabled = false;
                    noButton.enabled  = true;
                }
                else
                {
                    yesButton.enabled = true;
                    noButton.enabled  = false;
                }
            }
            return;
        }

        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            if (_positionX > 0)
            {
                _positionX--;
            }
            else
            {
                _positionX = CConstants.SLOT_COLOUMN - 1;
            }

            _arrow = EArrow._left;

            _currentSlot = _positionX + _positionY * CConstants.SLOT_COLOUMN;
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            if (_positionX < CConstants.SLOT_COLOUMN - 1)
            {
                _positionX++;
            }
            else
            {
                _positionX = 0;
            }

            _arrow = EArrow._right;

            _currentSlot = _positionX + _positionY * CConstants.SLOT_COLOUMN;
        }

        if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow))
        {
            _positionY = (_positionY == 0 ? 1 : 0);

            _arrow = EArrow._up;

            _currentSlot = _positionX + _positionY * CConstants.SLOT_COLOUMN;
        }

        if (_slots[_currentSlot].transform.Find("Item").gameObject.activeSelf == false) //상점에 존재하는 상품이 아닌경우 커서 위치 바꿔야함
        {
            switch (_arrow)
            {
            case EArrow._left:
                while (_slots[_currentSlot].transform.Find("Item").gameObject.activeSelf == false)
                {
                    if (_positionX <= 0)
                    {
                        _positionX += CConstants.SLOT_COLOUMN - 1;
                    }
                    else
                    {
                        _positionX--;
                    }

                    _currentSlot = _positionX + _positionY * CConstants.SLOT_COLOUMN;
                }
                break;

            case EArrow._right:
                while (_slots[_currentSlot].transform.Find("Item").gameObject.activeSelf == false)
                {
                    if (_positionX >= CConstants.SLOT_COLOUMN - 1)
                    {
                        _positionX -= CConstants.SLOT_COLOUMN - 1;
                    }
                    else
                    {
                        _positionX++;
                    }

                    _currentSlot = _positionX + _positionY * CConstants.SLOT_COLOUMN;
                }
                break;

            case EArrow._up:
                while (_slots[_currentSlot].transform.Find("Item").gameObject.activeSelf == false)
                {
                    _positionY = (_positionY == 0 ? 1 : 0);

                    _currentSlot = _positionX + _positionY * CConstants.SLOT_COLOUMN;
                }
                break;
            }
        }

        _slots[_lastSlot].transform.Find("Image").gameObject.SetActive(false);
        _slots[_currentSlot].transform.Find("Image").gameObject.SetActive(true);
        _lastSlot = _currentSlot;
    }