Beispiel #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);
        }
Beispiel #2
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            object variable = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property);

            if (variable != null)
            {
                if (uNodeGUIUtility.IsHide(fieldInfo, variable))
                {
                    return(-EditorGUIUtility.standardVerticalSpacing);
                }
            }
            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(-EditorGUIUtility.standardVerticalSpacing);
                        }
                    }
                }
            }
            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))
            {
                if (fieldInfo.IsDefined(typeof(ObjectTypeAttribute), true))
                {
                    var fieldAttributes = fieldInfo.GetCustomAttributes(true);
                    if (variable != null && ReflectionUtils.TryCorrectingAttribute(variable, ref fieldAttributes))
                    {
                        var OTA = ReflectionUtils.GetAttribute <ObjectTypeAttribute>(fieldAttributes);
                        if (OTA != null && OTA.type != null)
                        {
                            return(EditorGUI.GetPropertyHeight(property, label, true));
                        }
                    }
                    return(-EditorGUIUtility.standardVerticalSpacing);
                }
            }
            return(EditorGUI.GetPropertyHeight(property, label, true));
        }
Beispiel #3
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     if (fieldInfo.IsDefined(typeof(ObjectTypeAttribute), true))
     {
         var    fieldAttributes = fieldInfo.GetCustomAttributes(true);
         object variable        = PropertyDrawerUtility.GetParentObjectFromSerializedProperty <object>(property);
         if (variable != null && ReflectionUtils.TryCorrectingAttribute(variable, ref fieldAttributes))
         {
             var OTA = ReflectionUtils.GetAttribute <ObjectTypeAttribute>(fieldAttributes);
             if (OTA != null && OTA.type != null)
             {
                 return(base.GetPropertyHeight(property, label));
             }
         }
         return(0);
     }
     return(base.GetPropertyHeight(property, label));
 }
Beispiel #4
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);
            }
        }