public void Init(string Content, string Title, UiDialogType DialogType, UiInputDialogButtonPress OnOkPress = null, UnityAction OnCancelPress = null, UiDialogInputInterface OnSubmit = null) { if (DialogType == UiDialogType.UI_DIALOG_CONFIRM) { CancelButton.gameObject.SetActive(true); } OkButton.gameObject.SetActive(true); if (OnOkPress != null) { OkButton.onClick.AddListener(delegate { OnOkPress.OnButtonPress(UiDialogButton.UI_DIALOG_BUTTON_OK); }); } else { OkButton.onClick.AddListener(delegate { CloseDialog(); }); } if (OnCancelPress != null) { CancelButton.onClick.AddListener(OnCancelPress); } else { CancelButton.onClick.AddListener(delegate { CloseDialog(); }); } if (DialogType == UiDialogType.UI_DIALOG_INPUT) { DialogInputField.gameObject.SetActive(true); if (OnSubmit != null) { DialogInputField.onEndEdit.AddListener(delegate { OnSubmit.OnEndEdit(DialogInputField); }); } else { DialogInputField.onEndEdit.AddListener(delegate { CloseDialog(); }); } } RectTransform CanvasRect; //Make it show on top. CanvasRect = transform as RectTransform; CanvasRect.SetAsLastSibling(); DialogTitle.text = Title; DialogContent.text = Content; }
public static GameObject ShowInputDialog(string Content, string Title = "Question", UiInputDialogButtonPress OnOkPress = null, UiDialogInputInterface OnSubmit = null) { GameObject Temp = Instantiate(Resources.Load("Prefabs/UiDialog")) as GameObject; Temp.GetComponent <UiDialog>().Init(Content, Title, UiDialogType.UI_DIALOG_INPUT, OnOkPress, null, OnSubmit); return(Temp); }