Esempio n. 1
0
        /// <summary>
        /// Raises the GUI event.
        /// </summary>
        /// <param name="position">Position.</param>
        /// <param name="property">Property.</param>
        /// <param name="label">Label.</param>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // initialize the status getter method
            string key = property.propertyPath;

            if (!m_PopupData.ContainsKey(key))
            {
                m_PopupData[key] = new PopupData();
            }
            PopupData popupData = m_PopupData[key];

            if (!string.IsNullOrEmpty(this.Attribute.StatusGetter))
            {
                popupData.GetStatusCallback =
                    StatusPropertyDrawer.GetStatusCallback(property, this.Attribute.StatusGetter);
            }
            Rect             iconPosition  = new Rect();
            ValidationStatus status        = ValidationStatus.None;
            string           statusTooltip = null;

            if (popupData.GetStatusCallback != null || !string.IsNullOrEmpty(this.Attribute.StatusGetter))
            {
                FieldInfo field;
                object    provider = property.GetProvider(out field);
                if (popupData.GetStatusCallback != null)
                {
                    status = popupData.GetStatusCallback(provider, property.GetValue(), out statusTooltip);
                }
                else
                {
                    status        = ValidationStatus.Warning;
                    statusTooltip = string.Format(
                        "{0} {1}.{2} not found.",
                        typeof(StatusPropertyAttribute.GetStatusCallback),
                        provider.GetType(),
                        this.Attribute.StatusGetter
                        );
                }
                if (status != ValidationStatus.None)
                {
                    position.width    -= EditorGUIUtility.singleLineHeight;
                    iconPosition       = position;
                    iconPosition.x    += iconPosition.width;
                    iconPosition.width = EditorGUIUtility.singleLineHeight;
                }
            }
            DisplayPopup(position, property, label);
            if (status != ValidationStatus.None)
            {
                EditorGUIX.DisplayValidationStatusIcon(iconPosition, status, statusTooltip);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Raises the draw word form event.
        /// </summary>
        /// <param name="position">Position.</param>
        /// <param name="wordFormProperty">Word form property.</param>
        /// <param name="synonymCount">Synonym count, if e.g., the word is a main form.</param>
        private void OnDrawWordForm(
            Rect position, SerializedProperty wordFormProperty, int synonymCount = -1
            )
        {
            float countLabelWidth = 30f;

            position.width -= EditorGUIUtility.singleLineHeight + (synonymCount < 0 ? 0 : countLabelWidth);
            position.height = EditorGUIUtility.singleLineHeight;
            EditorGUI.PropertyField(position, wordFormProperty);
            position.x    += position.width;
            position.width = EditorGUIUtility.singleLineHeight;
            EditorGUIX.DisplayValidationStatusIcon(
                position,
                m_WordFormStatuses[wordFormProperty.propertyPath].Status,
                m_WordFormStatuses[wordFormProperty.propertyPath].Tooltip
                );
            if (synonymCount >= 0)
            {
                position.x    += position.width;
                position.width = countLabelWidth;
                EditorGUI.LabelField(position, string.Format("({0})", synonymCount), EditorStylesX.LabelRight);
            }
        }