Exemplo n.º 1
0
    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;
    }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
    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);
        }
    }