Пример #1
0
    private void SetButtonContent(RecyclingButton currentButton, int dataIndex)
    {
        if (_LabelData == null || _LabelData.Count <= dataIndex)
        {
            return;
        }

        // set data
        currentButton.Model = _LabelData[dataIndex];

        // set text
        string buttonLabel = _LabelData[dataIndex].Label;

        currentButton.SetText(buttonLabel);

        if (OnDataSet != null)
        {
            if (OnDataSet != null)
            {
                OnDataSet(currentButton);
            }
        }

        currentButton.OnClick = delegate
        {
            if (OnButtonClicked != null)
            {
                OnButtonClicked(currentButton);
            }
        };
    }
    void RecyclingContainer_OnButtonClicked(RecyclingButton recyclingButton)
    {
        CustomDataSample customData = null;

        if (customDataDictionary.TryGetValue(recyclingButton.Model.Id, out customData))
        {
            Debug.Log(customData.CustomLabel);
        }
    }
    void RecyclingContainer_OnDataSet(RecyclingButton recyclingButton)
    {
        CustomButton customButton = recyclingButton.GetComponent <CustomButton>();

        if (customButton != null)
        {
            CustomDataSample customData = null;
            if (customDataDictionary.TryGetValue(recyclingButton.Model.Id, out customData))
            {
                customButton.OtherLabel.text = customData.CustomLabel;
            }
        }
    }
Пример #4
0
    private void FillPrefabs()
    {
        for (int i = 0; i < _PrefabCount - 1; i++)
        {
            RecyclingButton newTextButton = Instantiate(PrefabButton, _ContainerRT);
            RectTransform   rt            = newTextButton.GetComponent <RectTransform>();

            rt.localScale         = PrefabRT.localScale;
            rt.sizeDelta          = PrefabRT.sizeDelta;
            rt.transform.position = PrefabRT.transform.position;
            rt.anchoredPosition   = new Vector2(0, (i + 1) * -PrefabRT.sizeDelta.y);

            Buttons.Add(newTextButton);
        }
    }
Пример #5
0
    private void RestackButtons(int index, int dataIndex)
    {
        int itButtons          = 0;
        int currentButtonIndex = index;

        while (itButtons < Buttons.Count)
        {
            if (currentButtonIndex > Buttons.Count - 1)
            {
                currentButtonIndex = 0;
            }
            RecyclingButton currentButton = Buttons[currentButtonIndex];

            // set visible
            if (dataIndex < _DataCount)
            {
                currentButton.gameObject.SetActive(true);

                // set position
                RectTransform currentButtonRT = currentButton.GetComponent <RectTransform>();
                currentButtonRT.localPosition = new Vector3(
                    currentButtonRT.localPosition.x,
                    (-itButtons * PrefabRT.sizeDelta.y) + (-_TopIndex * PrefabRT.sizeDelta.y),
                    currentButtonRT.localPosition.z);

                // set content
                SetButtonContent(currentButton, dataIndex);
            }
            else
            {
                currentButton.gameObject.SetActive(false);
            }

            currentButtonIndex++;
            dataIndex++;
            itButtons++;
        }
    }
Пример #6
0
 private void GetPrefab()
 {
     PrefabButton = GetComponentInChildren <RecyclingButton>();
     PrefabRT     = PrefabButton.GetComponent <RectTransform>();
     Buttons.Add(PrefabButton);
 }