Example #1
0
 // Change which candy is selected
 private void SelectCandy(int candyIndex)
 {
     // If index is valid, change
     // else, do nothing
     if (candyIndex >= candyMinIndex && candyIndex <= candyMaxIndex)
     {
         selectedCandyIndex = candyIndex;
         selectedCandy      = candyDataList.GetCandyDataObject(selectedCandyIndex);
         candySelectionUI.SelectCandy(candyIndex);
     }
 }
    public void Setup(CandyDataList candyList)
    {
        for (int i = 0; i < candyList.GetCount(); ++i)
        {
            CandySelectorUI newSelector = Instantiate(candySelectorPrefab, transform).gameObject.GetComponent <CandySelectorUI>();
            newSelector.Setup(candyList.GetCandyDataObject(i), i + 1);

            candySelectors.Add(newSelector);
        }

        // Resize our component to fit everything
        RectTransform         rectTransform         = GetComponent <RectTransform>();
        HorizontalLayoutGroup horizontalLayoutGroup = GetComponent <HorizontalLayoutGroup>();
        float width = (selectorWidth * candySelectors.Count) + (horizontalLayoutGroup.spacing * candySelectors.Count - 1);

        rectTransform.sizeDelta        = new Vector2(width, selectorHeight);
        rectTransform.anchoredPosition = new Vector2((width / 2) + (horizontalLayoutGroup.spacing * 2), rectTransform.anchoredPosition.y);
    }