protected override void Awake() { base.Awake(); if (placeholderText == null) { throw new UserDialogException("User dialogs's reference to placeholder text is not set!"); } if (inputField == null) { throw new UserDialogException("User dialogs's reference to input field is not set!"); } OKButton.onClick.RemoveAllListeners(); OKButton.onClick.AddListener(Submit); inputField.onEndEdit.AddListener(text => { if (Input.GetKeyDown(KeyCode.Return)) { Submit(); } }); // Set default validator and invalid callback, can be overwritten later validator = text => !string.IsNullOrWhiteSpace(text); invalidCallback = _ => DialogBasic.Show("Input may not be empty!"); }
/// <summary> /// Sets a function for validating the contents of the input field. This is checked /// on submit and if the contents are invalid the dialog stays open. /// </summary> public void SetValidator(Predicate <string> validator) { this.validator = validator; invalidCallback = _ => DialogBasic.Show("Input is invalid!"); }
Show(message, contentValidator, _ => DialogBasic.Show(invalidMessage), cancellable);