Пример #1
0
        private void HighlightUsingMethod(Rect position, SerializedProperty property, GUIContent label)
        {
            var highlightAttribute = attribute as HighlightAttribute;

            if (highlightAttribute.Value == null)
            {
                var message = $"Couldn't find a method called {highlightAttribute.ValidationMethodName}.";
                DrawErrorMessage(position, message);
                return;
            }

            System.Object objectInstance = property.GetTargetObjectWithProperty();
            var           targetMethod   = objectInstance.GetAllMethods(m => m.Name
                                                                        .Equals(highlightAttribute.ValidationMethodName))
                                           .FirstOrDefault();

            if (targetMethod == null)
            {
                var message = "You can't use a null value when using method validation.";
                DrawErrorMessage(position, message);
                return;
            }

            if (targetMethod.GetParameters().Length == 0)
            {
                var message = "The selected method doesn't match the rule of a single boolean parameter.";
                DrawErrorMessage(position, message);
                return;
            }

            var highlight = (bool)targetMethod.Invoke(
                property.serializedObject.targetObject, new [] { highlightAttribute.Value });

            if (highlight)
            {
                HighlightField(position, property, label);
            }
            else
            {
                DrawProperty(position, property, label);
            }
        }