Пример #1
0
        void GenerateButtons()
        {
            float yForEachButton = 1.0f / (float)MaxButtons;

            for (int i = 0; i < MaxButtons; i++)
            {
                var newButton = Instantiate(ButtonPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                newButton.transform.SetParent(ButtonsSection.transform);
                var rect = newButton.GetComponent <RectTransform>();

                float diff = yForEachButton * i;

                rect.anchorMin = new Vector2(0.0f, 1.0f - diff - yForEachButton);
                rect.anchorMax = new Vector2(1.0f, 1.0f - diff);

                // post anchor adjustment
                rect.offsetMax = new Vector2(0.0f, 0.0f);
                rect.offsetMin = new Vector2(0.0f, 0.0f);

                var newButtonData = new ButtonData(newButton);

                AvailableButtonList.Add(newButtonData);
                newButtonData.SetVisibility(false);
            }
        }