Esempio n. 1
0
    public void Initialize(bool displayFrontLine, bool isFrontLine, int defaultCount, string defaultLabel, List <WeaponSelectionSection> weaponSelections)
    {
        IsFrontLine.gameObject.SetActive(displayFrontLine);
        if (displayFrontLine)
        {
            IsFrontLine.isOn = isFrontLine;
        }

        int        yPos        = -5;
        GameObject defaultLine = Instantiate(NumberPickerPrefab,
                                             new Vector3(0, yPos, 0),
                                             Quaternion.identity,
                                             Pane.transform);

        defaultLine.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, yPos);
        _default = defaultLine.GetComponent <NumberPicker>();
        _default.MakeInteractable(false);
        _default.OnValueChanged.AddListener(NumberPicker_OnValueChanged);
        int availableCount = defaultCount;

        //_default.CurrentValue = defaultCount;
        _default.Label.text         = defaultLabel;
        _default.MaxValue           = defaultCount;
        _default.DoChildrenSubtract = true;
        // it'd be cleaner to get the height from the prefab's rect transform
        yPos       -= 50;
        _selections = new List <NumberPicker>();
        foreach (WeaponSelectionSection section in weaponSelections)
        {
            GameObject sectionHeader = Instantiate(NumberPickerPrefab,
                                                   new Vector3(0, yPos, 0),
                                                   Quaternion.identity,
                                                   Pane.transform);
            sectionHeader.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, yPos);
            var middle = sectionHeader.GetComponent <NumberPicker>();
            middle.MakeInteractable(false);
            middle.CurrentValue       = section.CurrentCount;
            middle.MaxValue           = section.MaxCount;
            middle.Label.text         = section.Label + " (max " + section.MaxCount + ")";
            middle.DoChildrenSubtract = false;
            _default.AddChild(middle);
            yPos -= 25;
            foreach (Tuple <string, int> weapon in section.Selections)
            {
                GameObject leaf = Instantiate(NumberPickerPrefab,
                                              new Vector3(0, yPos, 0),
                                              Quaternion.identity,
                                              Pane.transform);
                leaf.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, yPos);
                var picker = leaf.GetComponent <NumberPicker>();
                picker.MakeInteractable(true);
                picker.CurrentValue = weapon.Item2;
                availableCount     -= weapon.Item2;
                picker.MaxValue     = picker.CurrentValue + section.MaxCount - section.CurrentCount;
                picker.Label.text   = weapon.Item1;
                middle.AddChild(picker);
                yPos -= 25;
            }
            yPos -= 25;
        }
        _default.CurrentValue = availableCount;
    }