Пример #1
0
        void LateUpdate()
        {
            // handle mouse over animation
            // remove visual changes for buttons (except items)
            if (selectedModeButton != null)
                selectedModeButton.butImage.color = selectedModeButton.selectedColor;
            if (mouseOverModeButton != null && mouseOverModeButton != selectedModeButton)
                mouseOverModeButton.butImage.color = mouseOverModeButton.origColor;
            mouseOverModeButton = null;

            // remove visual changes for items
            if (selectedUIItem != null)
                selectedUIItem.Set(mouseSelectColor);
            if (mouseoverUIItem != null && mouseoverUIItem != selectedUIItem)
                mouseoverUIItem.ResetColor();
            mouseoverUIItem = null;

            if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)gameObject.transform, Input.mousePosition)) // ShopUI rect
            {
                if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)panelItems.transform, Input.mousePosition)) // PanelItems rect
                {
                    for (int i = 0; i < UIItems.Length; ++i)
                    {
                        if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)UIItems[i]._itemElem.transform, Input.mousePosition)) // items
                        {
                            // mouse is within item rect
                            if (Input.GetMouseButton(0))
                            {
                                if (UIItems[i]._hasItem && UIItems[i]._item.amount > 0)
                                {
                                    /* item was clicked on with left mouse button => selected */
                                    if (selectedUIItem != UIItems[i] && selectedUIItem != null)
                                        selectedUIItem.ResetColor(); // a different item was selected previously

                                    selectedUIItem = UIItems[i];
                                    selectedUIItem.Set(mouseSelectColor);
                                }
                            }
                            else
                            {
                                /* mouse is only hovering over the item */
                                // restore old visual for the previously highlighted item
                                if (mouseoverUIItem != null && mouseoverUIItem != UIItems[i] && mouseoverUIItem != selectedUIItem) // mouse hovers over a new item
                                    mouseoverUIItem.ResetColor();
                                else if (selectedUIItem != null && mouseoverUIItem == selectedUIItem) // the previous item could still be selected
                                    selectedUIItem.Set(mouseSelectColor);

                                // set colors for new hover item
                                mouseoverUIItem = UIItems[i];
                                UIItems[i].Set((selectedUIItem == mouseoverUIItem) ? mouseSelectOverColor : mouseOverColor);
                                break;
                            }
                        }
                    }
                }
                else if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)panelTop.transform, Input.mousePosition)) // top bar rect
                {
                    UIButton oldSelectButton = selectedModeButton;
                    if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)buttonClose.button.transform, Input.mousePosition))
                    {
                        if (Input.GetMouseButton(0))
                            currendManager.EndInteraction(); // end of shopping
                        else if (selectedModeButton == buttonClose)
                            selectedModeButton.butImage.color = selectedModeButton.selectedOverColor;
                        else
                            mouseOverModeButton = buttonClose;
                    }
                    else if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)buttonSelectBuy.button.transform, Input.mousePosition))
                    {
                        if (Input.GetMouseButton(0))
                            ChangeModeTo(EShopMode.buy);
                        else if (selectedModeButton == buttonSelectBuy)
                            selectedModeButton.butImage.color = selectedModeButton.selectedOverColor;
                        else
                            mouseOverModeButton = buttonSelectBuy;
                    }
                    else if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)buttonSell.button.transform, Input.mousePosition))
                    {
                        if (Input.GetMouseButton(0))
                            ChangeModeTo(EShopMode.sell);
                        else if (selectedModeButton == buttonSell)
                            selectedModeButton.butImage.color = selectedModeButton.selectedOverColor;
                        else
                            mouseOverModeButton = buttonSell;
                    }
                    else if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)buttonRebuy.button.transform, Input.mousePosition))
                    {
                        if (Input.GetMouseButton(0))
                            ChangeModeTo(EShopMode.rebuy);
                        else if (selectedModeButton == buttonRebuy)
                            selectedModeButton.butImage.color = selectedModeButton.selectedOverColor;
                        else
                            mouseOverModeButton = buttonRebuy;
                    }

                    if (mouseOverModeButton != null)
                        mouseOverModeButton.butImage.color = mouseOverModeButton.mouseOvercolor; // apply visual changes

                    if (selectedModeButton != oldSelectButton )
                    {
                        oldSelectButton.butImage.color = selectedModeButton.origColor;
                        selectedModeButton.butImage.color = selectedModeButton.selectedOverColor;
                    }
                }
            }
        }