public static string TextField(GUIContent label, string text, GUIStyle style, TextFieldChangeHandler change, TextFieldFailureHandler failure = null, TextFieldValidationHandler validate = null, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); text = EditorGUILayout.TextField(label, text, style, options); if (EditorGUI.EndChangeCheck()) { TextFieldApplyChangeHandlers(text, change, failure, validate); } return(text); }
private static void TextFieldApplyChangeHandlers(string text, TextFieldChangeHandler change, TextFieldFailureHandler failure, TextFieldValidationHandler validate) { bool validated = (validate == null) ? true : validate(text); if (validated) { change(text); } else if (!validated && failure != null) { failure(); } }