Пример #1
0
    /// <summary>
    /// Initializes the action buttons to represent the numbers contained within the 'values' parameter. The array must contain three values.
    /// </summary>
    /// <param name="values">An array of the values that each button should represent.</param>
    internal void InitActionButtons(int[] values)
    {
        if (values.Length == 3)
        {
            buttonSequence = new ActionSequence();

            for (int i = 0; i < ActionButtons.Length; i++)
            {
                int          spriteIndex = values[i] - 1;
                ActionButton ab          = ActionButtons[i];
                ab.IsSelected = false;
                ab.InitActionButton(ButtonHeight, DefaultSprites[spriteIndex], SelectedSprites[spriteIndex], values[i]);
            }

            AttackButton.InitAttackButton(ButtonHeight);

            if (!InitializedButtonPositions)
            {
                //Calculations for positioning.
                RectTransform canvas               = gameObject.transform.root.transform as RectTransform;
                float         attackButtonOffset   = .025f * canvas.sizeDelta.x;
                float         bottomMargin         = .025f * canvas.sizeDelta.y;
                float         totalWidthOfButtons  = ActionButtons.Length * ActionButtons[0].Width + attackButtonOffset + AttackButton.Width;
                float         remainingCanvasWidth = canvas.sizeDelta.x - totalWidthOfButtons;

                //Set positions.
                float totalOffset = remainingCanvasWidth / 2;
                foreach (ActionButton button in ActionButtons)
                {
                    button.SetAbsolutePosition(totalOffset, bottomMargin);
                    totalOffset += button.Width;
                }
                totalOffset += attackButtonOffset;
                AttackButton.SetAbsolutePosition(totalOffset, bottomMargin);

                InitializedButtonPositions = true;
            }
        }
        else
        {
            throw new UnityException(
                      string.Format("Invalid array length. There exist three action buttons so 'values' int[] parameter Length must equal 3. Length = {0}", values.Length));
        }
    }