예제 #1
0
 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);
 }
예제 #2
0
        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();
            }
        }