Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //if a new button is highlighted, play the move cursor sound
        if (prevSelectedButton != EventSystem.current.currentSelectedGameObject)
        {
            SoundManager.instance.MoveCursor();
            prevSelectedButton = EventSystem.current.currentSelectedGameObject;
        }

        //check scene state
        //depending on the state, if a new button is selected, call a method which will update text fields, move UI elements, etc
        if (choosingUnit && EventSystem.current.currentSelectedGameObject != currentSelectedUnit && EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.transform.parent != proceedContainer.transform)
        {
            currentSelectedUnit = EventSystem.current.currentSelectedGameObject;
            UnitOnSelect();
        }
        if (choosingItem && EventSystem.current.currentSelectedGameObject != currentSelectedItem && EventSystem.current.currentSelectedGameObject != null)
        {
            currentSelectedItem = EventSystem.current.currentSelectedGameObject;
            ItemOnSelect();
        }
        if (choosingTargetUnit && EventSystem.current.currentSelectedGameObject != currentSelectedTargetUnit && EventSystem.current.currentSelectedGameObject != null)
        {
            currentSelectedTargetUnit = EventSystem.current.currentSelectedGameObject;
            TargetUnitOnSelect();
        }
        if (choosingTargetItem && EventSystem.current.currentSelectedGameObject != currentSelectedTargetItem && EventSystem.current.currentSelectedGameObject != null)
        {
            currentSelectedTargetItem = EventSystem.current.currentSelectedGameObject;
            TargetItemOnSelect();
        }
        if (choosingSlot && EventSystem.current.currentSelectedGameObject != currentSelectedEquip && EventSystem.current.currentSelectedGameObject != null)
        {
            currentSelectedEquip = EventSystem.current.currentSelectedGameObject;
            EquipOnSelect();
        }
        if (choosingEquip && EventSystem.current.currentSelectedGameObject != currentSelectedTargetEquip && EventSystem.current.currentSelectedGameObject != null)
        {
            currentSelectedTargetEquip = EventSystem.current.currentSelectedGameObject;
            TargetEquipOnSelect();
        }

        //behavior for cancel input in different states
        //mostly involves setting state flags and activating and deactivating different UI windows
        if (Input.GetButtonDown("Cancel"))
        {
            if (!choosingUnit)
            {
                SoundManager.instance.MenuCancel();
            }
            if (buttonContainerOpen)
            {
                buttonContainerOpen = false;
                choosingUnit        = true;
                infoContainer.SetActive(true);
                proceedContainer.SetActive(true);
                buttonContainer.SetActive(false);
                ReengageUnitButtons(UnitHandle);
            }
            else if (choosingItem)
            {
                choosingItem        = false;
                buttonContainerOpen = true;
                itemContainer.SetActive(false);
                buttonContainer.SetActive(true);
                swapItemsButton.Select();
                prevSelectedButton = swapItemsButton.gameObject;
            }
            else if (choosingTargetUnit)
            {
                choosingTargetUnit = false;
                choosingItem       = true;
                DisengageButtons(unitButtonList);
                ReengageItemButtons(itemButtonList);
                itemButtonList[itemListIndex].Select();
                prevSelectedButton = itemButtonList[itemListIndex].gameObject;
                targetItemContainer.SetActive(false);
                rightSheet.SetActive(false);
                currentSelectedItem = null;
            }
            else if (choosingTargetItem)
            {
                choosingTargetItem = false;
                choosingTargetUnit = true;
                ReengageUnitButtons(TargetUnitHandle);
                DisengageButtons(targetItemButtonList);

                unitButtonList[partyUnitIndex].interactable = false;
                unitButtonList[targetUnitIndex].Select();
                prevSelectedButton = unitButtonList[targetUnitIndex].gameObject;
                targetItemToolTip.SetActive(false);
                currentSelectedTargetItem = null;
            }
            else if (proceedBool)
            {
                CancelHandle();
            }
            else if (quitBool)
            {
                QuitCancelHandle();
            }
            else if (choosingSlot)
            {
                choosingSlot        = false;
                buttonContainerOpen = true;
                equipContainer.SetActive(false);
                buttonContainer.SetActive(true);
                equipButton.Select();
                prevSelectedButton = equipButton.gameObject;
            }
            else if (choosingEquip)
            {
                currentUnitScript.Unequip(gameManager.equipDict[currentUnitScript.equipmentList[currentSelectedEquip.transform.GetSiblingIndex()]].GetComponent <EquipmentScript>(), currentSelectedEquip.transform.GetSiblingIndex());
                currentUnitScript.Equip(preEquip, currentSelectedEquip.transform.GetSiblingIndex());
                choosingEquip = false;
                choosingSlot  = true;
                //rather than delete buttons, they are set inactive and can be activated and populated when needed later
                for (int i = 1; i < equipmentListContainer.transform.GetChild(0).childCount; i++)
                {
                    equipmentListContainer.transform.GetChild(0).GetChild(i).gameObject.SetActive(false);
                }

                rightSheet.SetActive(false);
                infoContainer.SetActive(false);
                equipmentListContainer.SetActive(false);
                equipmentScrollbar.SetActive(false);
                targetEquipToolTip.SetActive(false);
                equipContainer.SetActive(true);
                currentSelectedEquip.GetComponent <Button>().Select();
                prevSelectedButton         = currentSelectedEquip;
                currentSelectedEquip       = null;
                currentSelectedTargetEquip = null;
            }
        }
    }