예제 #1
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            var customDrawer = CustomDrawerUtility.GetPropertyDrawerForProperty(property, fieldInfo, attribute);

            if (customDrawer != null)
            {
                return(customDrawer.GetPropertyHeight(property, label));
            }

            return(EditorGUI.GetPropertyHeight(property, label));
        }
예제 #2
0
        /// <summary>
        /// Try to find and cache any PropertyDrawer or PropertyAttribute on the field
        /// </summary>
        private void CachePropertyDrawer(SerializedProperty property)
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;
            if (fieldInfo == null)
            {
                return;
            }

            var customDrawer = CustomDrawerUtility.GetPropertyDrawerForProperty(property, fieldInfo, attribute);

            if (customDrawer == null)
            {
                customDrawer = TryCreateAttributeDrawer();
            }

            _customPropertyDrawer = customDrawer;


            // Try to get drawer for any other Attribute on the field
            PropertyDrawer TryCreateAttributeDrawer()
            {
                var secondAttribute = TryGetSecondAttribute();

                if (secondAttribute == null)
                {
                    return(null);
                }

                var attributeType    = secondAttribute.GetType();
                var customDrawerType = CustomDrawerUtility.GetPropertyDrawerTypeForFieldType(attributeType);

                if (customDrawerType == null)
                {
                    return(null);
                }

                return(CustomDrawerUtility.InstantiatePropertyDrawer(customDrawerType, fieldInfo, secondAttribute));


                //Get second attribute if any
                Attribute TryGetSecondAttribute()
                {
                    return((PropertyAttribute)fieldInfo.GetCustomAttributes(typeof(PropertyAttribute), false)
                           .FirstOrDefault(a => !(a is ConditionalFieldAttribute)));
                }
            }
        }
예제 #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.isArray)
            {
                WarningsPool.LogCollectionsNotSupportedWarning(property, nameof(OverrideLabelAttribute));
            }

            label.text = ((OverrideLabelAttribute)attribute).NewLabel;

            var customDrawer = CustomDrawerUtility.GetPropertyDrawerForProperty(property, fieldInfo, attribute);

            if (customDrawer != null)
            {
                customDrawer.OnGUI(position, property, label);
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, true);
            }
        }