public static bool Toggle(GUIContent label, bool value, GUIStyle style, ToggleChangeHandler change, ToggleFailureHandler failure = null, ToggleValidationHandler validate = null, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); value = EditorGUILayout.ToggleLeft(label, value, style, options); if (EditorGUI.EndChangeCheck()) { ToggleApplyChangeHandlers(value, change, failure, validate); } return(value); }
private static void ToggleApplyChangeHandlers(bool value, ToggleChangeHandler change, ToggleFailureHandler failure, ToggleValidationHandler validate) { bool validated = (validate == null) ? true : validate(value); if (validated) { change(value); } else if (!validated && failure != null) { failure(); } }