コード例 #1
0
    private List <PromiseButton> CreateButtonsFromLabels(string[] labels)
    {
        var buttons = new List <PromiseButton>();

        foreach (string label in labels)
        {
            Button        btnGO      = this.Clone <Button>(BtnTemplate.gameObject);
            PromiseButton btnPromise = btnGO.gameObject.AddComponent <PromiseButton>();
            btnPromise.btn             = btnGO.GetComponent <Button>();
            btnPromise.background      = btnGO.GetComponent <Image>();
            btnPromise.text            = label;
            btnPromise.label           = btnGO.GetComponentInChildren <TextMeshProUGUI>();
            btnPromise.label.text      = label.TrimStart('*');
            btnPromise.isReject        = label.StartsWith("*");
            btnGO.transform.localScale = Vector2.one;

            if (btnPromise.isReject)
            {
                btnPromise.background.sprite = this.backgroundReject;
            }
            else
            {
                btnPromise.background.sprite = this.backgroundResolve;
            }

            buttons.Add(btnPromise);
        }

        BtnTemplate.gameObject.SetActive(false);

        SetButtons(buttons);

        return(buttons);
    }
コード例 #2
0
    void Btn_OnClick(PromiseButton btnPromise)
    {
        if (!Close())
        {
            return;
        }

        string answerCaps = btnPromise.label.text.ToUpper();

        if (btnPromise.isReject)
        {
            _promise.Reject(new Exception(answerCaps));
            return;
        }

        _promise.Resolve(answerCaps);
    }
コード例 #3
0
    private List <PromiseButton> CreateButtonsFromLabels(string[] labels)
    {
        if (labels == null || labels.Length == 0)
        {
            labels = _DEFAULT_LABELS;
        }

        var buttons = new List <PromiseButton>();

        foreach (string label in labels)
        {
            GameObject    btnGO      = MakeFromPrefab("SubItems/GeneralButton", this.buttonsContainer);
            PromiseButton btnPromise = btnGO.AddComponent <PromiseButton>();
            btnPromise.btn             = btnGO.GetComponent <Button>();
            btnPromise.background      = btnGO.GetComponent <Image>();
            btnPromise.text            = label;
            btnPromise.label           = btnGO.GetComponentInChildren <TextMeshProUGUI>();
            btnPromise.label.text      = label.TrimStart('*');
            btnPromise.isReject        = label.StartsWith("*");
            btnGO.transform.localScale = Vector2.one;

            if (btnPromise.isReject)
            {
                btnPromise.background.sprite = this.backgroundReject;
            }
            else
            {
                btnPromise.background.sprite = this.backgroundResolve;
            }

            buttons.Add(btnPromise);
        }

        SetButtons(buttons);

        return(buttons);
    }