コード例 #1
0
    //UI会话操作
    public static UiDialogHandle Show(string msg, QuestionResultDelegate callback = null)
    {
        //实例一个会话操作实体
        UiDialogHandle handle;

        {
            var builtin = UiManager.Instance.FindFromDialogRoot("MessageBox");
            if (builtin != null)
            {
                //显示会话模板
                handle = UiManager.Instance.ShowModalTemplate(builtin.gameObject);
            }
            else
            {
                var msgBoxPrefab = Resources.Load("MessageBox") as GameObject;
                handle = UiManager.Instance.ShowModalPrefab(msgBoxPrefab);
            }
        }

        if (callback != null)
        {
            handle.Hidden += (dlg, returnValue) => callback((QuestionResult)returnValue);
        }

        var msgBox = (UiMessageBox)handle.Dialog;

        msgBox.MessageText.text = msg;
        msgBox.Buttons[0].onClick.AddListener(msgBox.OnMessageBoxOkButtonClick);

        return(handle);
    }
コード例 #2
0
    public static UiDialogHandle Show(string msg, QuestionResultDelegate callback = null)
    {
        UiDialogHandle handle;
        {
            var builtin = UiManager.Instance.FindFromDialogRoot("MessageBox");
            if (builtin != null)
            {
                handle = UiManager.Instance.ShowModalTemplate(builtin.gameObject);
            }
            else
            {
                var msgBoxPrefab = Resources.Load("MessageBox") as GameObject;
                handle = UiManager.Instance.ShowModalPrefab(msgBoxPrefab);
            }
        }

        if (callback != null)
            handle.Hidden += (dlg, returnValue) => callback((QuestionResult)returnValue);

        var msgBox = (UiMessageBox)handle.Dialog;
        msgBox.MessageText.text = msg;
        msgBox.Buttons[0].onClick.AddListener(msgBox.OnMessageBoxOkButtonClick);

        return handle;
    }
コード例 #3
0
    public static UiDialogHandle Show(
        string msg, QuestionType questionType,
        QuestionResultDelegate callback = null, string customOkName = null)
    {
        UiDialogHandle handle;

        {
            var builtin = UiManager.Instance.FindFromDialogRoot("MessageQuestionBox");
            if (builtin != null)
            {
                handle = UiManager.Instance.ShowModalTemplate(builtin.gameObject);
            }
            else
            {
                var msgBoxPrefab = Resources.Load("MessageQuestionBox") as GameObject;
                handle = UiManager.Instance.ShowModalPrefab(msgBoxPrefab);
            }
        }

        if (callback != null)
        {
            handle.Hidden += (dlg, returnValue) => callback((QuestionResult)returnValue);
        }

        var msgBox = (UiMessageBox)handle.Dialog;

        msgBox.MessageText.text = msg;

        var b0     = msgBox.Buttons[0];
        var b0Text = b0.transform.Find("Text").GetComponent <Text>();
        var b1     = msgBox.Buttons[1];
        var b1Text = b1.transform.Find("Text").GetComponent <Text>();

        b1.gameObject.SetActive(questionType != QuestionType.Ok);

        switch (questionType)
        {
        case QuestionType.Ok:
            b0Text.text = customOkName ?? "Ok";
            b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Ok));
            b1.gameObject.SetActive(false);
            break;

        case QuestionType.OkCancel:
            b0Text.text = customOkName ?? "Ok";
            b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Ok));
            b1Text.text = "Cancel";
            b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Cancel));
            break;

        case QuestionType.RetryCancel:
            b0Text.text = "Retry";
            b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Retry));
            b1Text.text = "Cancel";
            b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Cancel));
            break;

        case QuestionType.YesNo:
            b0Text.text = "Yes";
            b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Yes));
            b1Text.text = "No";
            b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.No));
            break;

        case QuestionType.ContinueStop:
            b0Text.text = "Continue";
            b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Continue));
            b1Text.text = "Stop";
            b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Stop));
            break;
        }

        return(handle);
    }
コード例 #4
0
    public static UiDialogHandle Show(
        string msg, QuestionType questionType,
        QuestionResultDelegate callback = null, string customOkName = null)
    {
        UiDialogHandle handle;
        {
            var builtin = UiManager.Instance.FindFromDialogRoot("MessageQuestionBox");
            if (builtin != null)
            {
                handle = UiManager.Instance.ShowModalTemplate(builtin.gameObject);
            }
            else
            {
                var msgBoxPrefab = Resources.Load("MessageQuestionBox") as GameObject;
                handle = UiManager.Instance.ShowModalPrefab(msgBoxPrefab);
            }
        }

        if (callback != null)
            handle.Hidden += (dlg, returnValue) => callback((QuestionResult)returnValue);

        var msgBox = (UiMessageBox)handle.Dialog;
        msgBox.MessageText.text = msg;

        var b0 = msgBox.Buttons[0];
        var b0Text = b0.transform.Find("Text").GetComponent<Text>();
        var b1 = msgBox.Buttons[1];
        var b1Text = b1.transform.Find("Text").GetComponent<Text>();

        b1.gameObject.SetActive(questionType != QuestionType.Ok);

        switch (questionType)
        {
            case QuestionType.Ok:
                b0Text.text = customOkName ?? "Ok";
                b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Ok));
                b1.gameObject.SetActive(false);
                break;

            case QuestionType.OkCancel:
                b0Text.text = customOkName ?? "Ok";
                b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Ok));
                b1Text.text = "Cancel";
                b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Cancel));
                break;

            case QuestionType.RetryCancel:
                b0Text.text = "Retry";
                b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Retry));
                b1Text.text = "Cancel";
                b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Cancel));
                break;

            case QuestionType.YesNo:
                b0Text.text = "Yes";
                b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Yes));
                b1Text.text = "No";
                b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.No));
                break;

            case QuestionType.ContinueStop:
                b0Text.text = "Continue";
                b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Continue));
                b1Text.text = "Stop";
                b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Stop));
                break;
        }

        return handle;
    }