public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { float height = EditorStyles.label.CalcHeight(label, int.MaxValue); position.height = height; ValidRegexAttribute regexAttribute = attribute as ValidRegexAttribute; string regex = regexAttribute.Regex; string newValue = EditorGUI.TextField(position, label, property.stringValue); if (!Regex.IsMatch(newValue, regex)) { Rect errorPosition = position; errorPosition.y += height; GUIStyle redStyle = new GUIStyle(EditorStyles.label); redStyle.normal.textColor = Color.red; redStyle.fontStyle = FontStyle.Bold; EditorGUI.LabelField(errorPosition, " ", "Invalid Format!", redStyle); } property.stringValue = newValue; }
public void InvalidRegexReturnsErrors() { ValidRegexAttribute validRegexAttribute = new ValidRegexAttribute(); TestNode testClass = new TestNode("\\"); List <ValidationError> errors = new List <ValidationError>(); validRegexAttribute.Validate(testClass, regexProperty, errors, ServiceProvider); Assert.AreEqual(1, errors.Count); }
public void EmptyRegexIsValid() { ValidRegexAttribute validRegexAttribute = new ValidRegexAttribute(); TestNode testClass = new TestNode(string.Empty); List <ValidationError> errors = new List <ValidationError>(); validRegexAttribute.Validate(testClass, regexProperty, errors, ServiceProvider); Assert.AreEqual(0, errors.Count); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { ValidRegexAttribute regexAttribute = attribute as ValidRegexAttribute; string regex = regexAttribute.Regex; if (Regex.IsMatch(property.stringValue, regex)) { return(EditorStyles.label.CalcHeight(label, int.MaxValue)); } else { return(EditorStyles.label.CalcHeight(label, int.MaxValue) * 2); } }