/// <summary> /// Show the specified alert. /// </summary> /// <param name="alert">Show <see cref="PaperPlaneTools.Alert"/></param> void IAlertPlatformAdapter.Show(Alert alert) { int buttonIndex; if (alert.OnDismiss != null) { onDismiss += alert.OnDismiss; } if (alert.NegativeButton != null && alert.NeutralButton != null) { buttonIndex = UnityEditor.EditorUtility.DisplayDialogComplex(alert.Title, alert.Message, (alert.PositiveButton != null) ? alert.PositiveButton.Title : null, alert.NegativeButton.Title, alert.NeutralButton.Title ); } else { bool substituteNegativeButton = alert.NegativeButton == null; AlertButton negativeButton = substituteNegativeButton ? alert.NeutralButton : alert.NegativeButton; bool res = UnityEditor.EditorUtility.DisplayDialog(alert.Title, alert.Message, (alert.PositiveButton != null) ? alert.PositiveButton.Title : null, (negativeButton != null) ? negativeButton.Title : null ); //DisplayDialog returns true if ok button is pressed. buttonIndex = res ? 0 : (substituteNegativeButton ? 2 : 1); } //0, 1 or 2 corresponding to ok, cancel and alt buttons. if (buttonIndex == 0 && alert.PositiveButton != null && alert.PositiveButton.Handler != null) { alert.PositiveButton.Handler.Invoke(); } if (buttonIndex == 1 && alert.NegativeButton != null && alert.NegativeButton.Handler != null) { alert.NegativeButton.Handler.Invoke(); } if (buttonIndex == 2 && alert.NeutralButton != null && alert.NeutralButton.Handler != null) { alert.NeutralButton.Handler.Invoke(); } if (onDismiss != null) { onDismiss.Invoke(); } }
/// <summary> /// Sets <see cref="PaperPlaneTools.Alert.NeutralButton"/>. /// </summary> public Alert SetNeutralButton(string title, Action handler = null) { NeutralButton = new AlertButton(title, handler); return(this); }
/// <summary> /// Generic set button. /// </summary> public void SetButton(ButtonType whichButton, string title, Action handler) { buttons[(int)whichButton] = new AlertButton(title, handler); }
/// <summary> /// Sets <see cref="PaperPlaneTools.Alert.PositiveButton"/>. /// </summary> public Alert SetPositiveButton(string title, Action handler = null) { PositiveButton = new AlertButton(title, handler); return(this); }