Exemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            MemberData      variable = PropertyDrawerUtility.GetActualObjectForSerializedProperty <MemberData>(property);
            FilterAttribute filter   = null;

            if (fieldInfo.IsDefined(typeof(ObjectTypeAttribute), true))
            {
                object pVariable       = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property);
                var    fieldAttributes = fieldInfo.GetCustomAttributes(true);
                if (pVariable != null && ReflectionUtils.TryCorrectingAttribute(pVariable, ref fieldAttributes))
                {
                    filter = ReflectionUtils.GetAttribute <FilterAttribute>(fieldAttributes);
                }
                else
                {
                    return;
                }
            }
            else if (fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false).Length > 0)
            {
                filter = (FilterAttribute)fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false)[0];
            }
            if (fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), false).Length > 0)
            {
                label.tooltip = ((TooltipAttribute)fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), false)[0]).tooltip;
            }
            EditorReflectionUtility.RenderVariable(position, variable, label, property.serializedObject.targetObject, filter);
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            object variable = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property);

            if (variable != null)
            {
                if (uNodeGUIUtility.IsHide(fieldInfo, variable))
                {
                    return;
                }
            }
            else
            {
                if (fieldInfo.IsDefined(typeof(HideAttribute), true))
                {
                    HideAttribute[] hide = fieldInfo.GetCustomAttributes(typeof(HideAttribute), true) as HideAttribute[];
                    foreach (HideAttribute ha in hide)
                    {
                        if (string.IsNullOrEmpty(ha.targetField))
                        {
                            return;
                        }
                    }
                }
            }
            if (fieldInfo.IsDefined(typeof(TooltipAttribute), true))
            {
                label.tooltip = ((TooltipAttribute)fieldInfo.GetCustomAttributes(typeof(TooltipAttribute), true)[0]).tooltip;
            }
            System.Type type = fieldInfo.FieldType;
            if (fieldInfo.FieldType.IsArray)
            {
                type = fieldInfo.FieldType.GetElementType();
            }
            else if (fieldInfo.FieldType.IsGenericType)
            {
                System.Type[] gType = fieldInfo.FieldType.GetGenericArguments();
                if (gType.Length == 1)
                {
                    type = gType[0];
                }
            }
            if (type == typeof(MemberData))
            {
                MemberData      obj    = PropertyDrawerUtility.GetActualObjectForSerializedProperty <MemberData>(property);
                FilterAttribute filter = null;
                if (fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false).Length > 0)
                {
                    filter = (FilterAttribute)fieldInfo.GetCustomAttributes(typeof(FilterAttribute), false)[0];
                }
                else if (fieldInfo.IsDefined(typeof(ObjectTypeAttribute), true))
                {
                    var    fieldAttributes = fieldInfo.GetCustomAttributes(true);
                    object pVariable       = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property);
                    if (pVariable != null && ReflectionUtils.TryCorrectingAttribute(pVariable, ref fieldAttributes))
                    {
                        filter = ReflectionUtils.GetAttribute <FilterAttribute>(fieldAttributes);
                    }
                    else
                    {
                        return;
                    }
                }
                EditorReflectionUtility.RenderVariable(position, obj, label, property.serializedObject.targetObject, filter);
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, true);
            }
        }