Exemple #1
0
 /// <summary>
 /// 初始化。設定關閉前動作,及確認後動作。
 /// </summary>
 public void Init(string message, UIOption.UICallback onOk, UIOption.UICallback onCancel)
 {
     option.message = message;
     option.SetOkCallback(onOk);
     option.SetCancelCallback(onCancel);
     SpecificInit();
 }
Exemple #2
0
    protected override void SpecificInit()
    {
        if (option != null)//有設置
        {
            messageText.text = option.message;

            //按鍵設置
            if (option.btnSettings != null)
            {
                //清空按鍵
                foreach (Transform b in buttonZone)
                {
                    Destroy(b.gameObject);
                }

                int btnAmount = option.btnSettings.Count;
                if (btnAmount < minAmount && btnAmount > maxAmount)
                {
                    Debug.LogErrorFormat("按鍵數量錯誤,需於{0}~{1}之間", minAmount, maxAmount);
                }
                else
                {
                    //依序設置按鍵
                    for (int i = 0; i < btnAmount; i++)
                    {
                        GameObject btn = Instantiate(buttonPrefab);
                        btn.name = (i + 1).ToString();
                        btn.transform.SetParent(buttonZone.transform, false);
                        //顏色
                        btn.GetComponent <Image>().color = option.btnSettings[i].color;
                        //內容
                        btn.GetComponentInChildren <Text>().text = option.btnSettings[i].text;
                        //動作
                        if (option.btnSettings[i].onClick != null)
                        {
                            UIOption.UICallback callback = option.btnSettings[i].onClick;
                            btn.GetComponent <Button>().onClick.AddListener(() => {
                                callback.Invoke(UIResult.Memo(btn.name));
                                Cancel();
                            });
                        }
                        else
                        {
                            btn.GetComponent <Button>().onClick.AddListener(Cancel);
                        }
                    }
                }
            }
            else //無按鍵設置
            {
                DefaultBtnSettings();
            }
        }
        else
        {
            Debug.LogErrorFormat("需進行視窗設置。");//需要DialogOption
        }
    }
Exemple #3
0
    /// <summary>
    /// 根據類型視窗進行初始化。
    /// </summary>
    protected override void SpecificInit()
    {
        //文字內容設置
        messageText.text = option.message;
        Debug.Log(option.type);
        //按鍵配置
        if (option.type == DialogOption.Type.ALERT_DIALOG)
        {
            confirmBtn.SetActive(true);
            cancelBtn.SetActive(false);
        }
        else if (option.type == DialogOption.Type.OK_OR_CANCEL_DIALOG)
        {
            confirmBtn.SetActive(true);
            cancelBtn.SetActive(true);
        }
        else//按鍵配置Custom
        {
            //有按鍵配置
            if (option.btnSettings != null)
            {
                //清除按鍵
                foreach (Transform b in buttonZone)
                {
                    Destroy(b.gameObject);
                }

                int btnAmount = option.btnSettings.Count;
                if (btnAmount > 2 || btnAmount == 0)
                {
                    Debug.LogError("按鍵數量錯誤: " + btnAmount);
                }
                else
                {
                    //依序設置按鍵
                    for (int i = 0; i < btnAmount; i++)
                    {
                        GameObject btn = Instantiate(buttonPrefab);
                        btn.transform.SetParent(buttonZone.transform, false);
                        //顏色
                        btn.GetComponent <Image>().color = option.btnSettings[i].color;
                        //內容
                        btn.GetComponentInChildren <Text>().text = option.btnSettings[i].text;
                        //動作
                        if (option.btnSettings[i].onClick != null)
                        {
                            UIOption.UICallback callback = option.btnSettings[i].onClick;
                            btn.GetComponent <Button>().onClick.AddListener(() => { callback.Invoke(UIResult.Memo("")); Cancel(); });
                            Cancel();
                        }
                        else
                        {
                            btn.GetComponent <Button>().onClick.AddListener(Cancel);
                        }
                    }
                }
            }
            else
            {
                DefaultBtnSettings();
            }
        }
    }
Exemple #4
0
 /// <summary>
 /// 初始化。設定確認後動作。
 /// </summary>
 public void Init(string message, UIOption.UICallback onOk)
 {
     Init(message, onOk, null);
 }