Example #1
0
    private void Awake()
    {
        int count = Mathf.Min(transform.childCount, colorTable.Count);

        for (int i = 0; i < count; i++)
        {
            var child = transform.GetChild(i);

            Image layoutImage = child.GetComponent <Image>();
            Image colorImage  = child.GetChild(0).GetComponent <Image>();
            Color color       = colorTable.GetColorInfo(i).color;

            colorImage.color = color;

            int idx = i;
            child.GetComponent <Button>().onClick.AddListener(() =>
            {
                SelectButton(idx);
            });

            colorButtonDatas.Add(new ColorButtonData {
                layoutImage = layoutImage, color = color
            });
        }
    }