void Update()
 {
     //if this building is not current building in building placer then turn this building to grey
     if (BuildingPlacer.GetInstance().getCurrentBuilding() != this.transform)
     {
         MarkGrey();
     }
 }
示例#2
0
 public void OnPointerExit(PointerEventData eventData)
 {
     //handle on pinter exit event
     if (BuildingPlacer.GetInstance().currentSelectedPanelItem != null && BuildingPlacer.GetInstance().hasPlaced)
     {
         BuildingPlacer.GetInstance().currentSelectedPanelItem.RemoveBuilding(); //remove a building from currently selected scroll panel item
         BuildingPlacer.GetInstance().currentSelectedPanelItem = null;
         BuildingPlacer.GetInstance().pointerInScrollBar       = false;
     }
 }
示例#3
0
    void Update()
    {
        UpdateList();
        UpdateVisibleButtonCount();

        //if buttons exceed the screen or pointer is not inside scroll bar then stop scrolling
        if ((visibleButtonCount - 1) * buttonDistance < (rightBoundary.anchoredPosition.x - leftBoundary.anchoredPosition.x) ||
            !BuildingPlacer.GetInstance().pointerInScrollBar)
        {
            scrollable = false;
        }
        else
        {
            scrollable = true;
        }


        if (scrollable)
        {
            scrollPanel.parent.GetComponent <ScrollRect>().horizontal = true;
            if (!dragging)
            {
                //if not dragging, lerp the scroll bar to appropriate position based on the boundaries
                //if scroll bar dragged such that first scroll bar item crossed left boundary then lerp it back
                if (scrollPanelItems[0].transform.position.x > leftBoundary.transform.position.x)
                {
                    scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, leftBoundary.GetComponent <RectTransform>().anchoredPosition.x, Time.deltaTime * 10f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y);
                }
                //if scroll bar dragged such that last visible scroll bar item crossed right boundary then lerp it forward
                if (scrollPanelItems[visibleButtonCount - 1].transform.position.x < rightBoundary.transform.position.x)
                {
                    scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, rightBoundary.GetComponent <RectTransform>().anchoredPosition.x - buttonDistance * (visibleButtonCount - 1), Time.deltaTime * 10f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y);
                }
            }
        }
        else
        {
            scrollPanel.parent.GetComponent <ScrollRect>().horizontal = false;
            if (scrollPanelItems.Count != 0)
            {
                //if not scrollable and still scroll panel items visible then lerp scroll bar such that first scroll panel item is at start of scroll panel
                if (scrollPanelItems[0].transform.position.x > leftBoundary.transform.position.x)
                {
                    scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, leftBoundary.GetComponent <RectTransform>().anchoredPosition.x, Time.deltaTime * 7f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y);
                }
                if (scrollPanelItems[0].transform.position.x < leftBoundary.transform.position.x)
                {
                    scrollPanel.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.Lerp(scrollPanel.GetComponent <RectTransform>().anchoredPosition.x, leftBoundary.GetComponent <RectTransform>().anchoredPosition.x, Time.deltaTime * 7f), scrollPanel.GetComponent <RectTransform>().anchoredPosition.y);
                }
            }
        }
    }
示例#4
0
 public void OnPointerDown(PointerEventData eventData)
 {
     //handle pointer down event on scroll panel item
     BuildingPlacer.GetInstance().currentSelectedPanelItem = this;
 }
示例#5
0
 public void RemoveBuilding()
 {
     buildingCount--;
     //remove building from scroll panel item but add to BuildigPlacer
     BuildingPlacer.GetInstance().SetCurrentBuilding(buildingPrefab, gameObject);
 }
示例#6
0
 public void OnPointerEnter(PointerEventData eventData)
 {
     BuildingPlacer.GetInstance().pointerInScrollBar = true;
 }