Beispiel #1
0
        public override void OnGUI(Rect r, SerializedProperty p, GUIContent label)
        {
            ShowIfInterfaceAttribute attr = attribute as ShowIfInterfaceAttribute;

            templabel.text    = label.text;
            templabel.tooltip = attr.tooltip;

            Type interfaceType = attr.type;
            Type targetType    = p.serializedObject.targetObject.GetType();

            if (interfaceType.IsAssignableFrom(targetType))
            {
                switch (p.propertyType)
                {
                case SerializedPropertyType.Float:
                    EditorGUI.Slider(r, p, attr.min, attr.max, templabel);
                    break;

                case SerializedPropertyType.Integer:
                    EditorGUI.IntSlider(r, p, (int)attr.min, (int)attr.max, templabel);
                    break;

                default:
                    EditorGUI.PropertyField(r, p, templabel);
                    break;
                }
            }
        }
Beispiel #2
0
        public override float GetPropertyHeight(SerializedProperty p, GUIContent label)
        {
            ShowIfInterfaceAttribute attr = attribute as ShowIfInterfaceAttribute;
            Type interfaceType            = attr.type;
            Type targetType = p.serializedObject.targetObject.GetType();

            bool containsInterface = (interfaceType.IsAssignableFrom(targetType));

            return(containsInterface ? base.GetPropertyHeight(p, label) : 0);
        }