Exemplo n.º 1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ItemInfo"/> class.
            /// </summary>
            /// <param name="info">The reflection information.</param>
            /// <param name="attributes">The attributes.</param>
            public ItemInfo(MemberInfo info, object[] attributes)
            {
                Info              = info;
                Order             = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute);
                Display           = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute);
                Tooltip           = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
                CustomEditor      = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute);
                CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute);
                Space             = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute);
                Header            = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute);
                VisibleIf         = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute);
                IsReadOnly        = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null;
                ExpandGroups      = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null;

                if (Display?.Name != null)
                {
                    // Use name provided by the attribute
                    DisplayName = Display.Name;
                }
                else
                {
                    // Use filtered member name
                    DisplayName = CustomEditorsUtil.GetPropertyNameUI(info.Name);
                }
            }
Exemplo n.º 2
0
        private static MemberInfo GetVisibleIfSource(Type type, VisibleIfAttribute visibleIf)
        {
            var property = type.GetProperty(visibleIf.MemberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (property != null)
            {
                if (property.GetMethod == null)
                {
                    Debug.LogError("Invalid VisibleIf rule. Property has missing getter " + visibleIf.MemberName);
                    return(null);
                }

                if (property.GetMethod.ReturnType != typeof(bool))
                {
                    Debug.LogError("Invalid VisibleIf rule. Property has to return bool type " + visibleIf.MemberName);
                    return(null);
                }

                return(property);
            }

            var field = type.GetField(visibleIf.MemberName);

            if (field != null)
            {
                if (field.FieldType != typeof(bool))
                {
                    Debug.LogError("Invalid VisibleIf rule. Field has to be bool type " + visibleIf.MemberName);
                    return(null);
                }
            }

            Debug.LogError("Invalid VisibleIf rule. Cannot find member " + visibleIf.MemberName);
            return(null);
        }
Exemplo n.º 3
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ItemInfo"/> class.
            /// </summary>
            /// <param name="info">The reflection information.</param>
            /// <param name="attributes">The attributes.</param>
            public ItemInfo(MemberInfo info, object[] attributes)
            {
                Info              = info;
                Order             = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute);
                Display           = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute);
                Tooltip           = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
                CustomEditor      = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute);
                CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute);
                Space             = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute);
                Header            = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute);
                VisibleIf         = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute);
                IsReadOnly        = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null;
                ExpandGroups      = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null;

                if (!IsReadOnly && info is FieldInfo fieldInfo && fieldInfo.IsInitOnly)
                {
                    // Field declared with `readonly` keyword
                    IsReadOnly = true;
                }
                if (!IsReadOnly && info is PropertyInfo propertyInfo && !propertyInfo.CanWrite)
                {
                    // Property without a setter
                    IsReadOnly = true;
                }
                if (Display?.Name != null)
                {
                    // Use name provided by the attribute
                    DisplayName = Display.Name;
                }
                else
                {
                    // Use filtered member name
                    DisplayName = CustomEditorsUtil.GetPropertyNameUI(info.Name);
                }
            }
 private void CheckVisibleIfAttribute()
 {
     visibleIfAttribute = ReflectionUtils.GetAttribute <VisibleIfAttribute>(MemberInfo);
     if (visibleIfAttribute != null)
     {
         visibleIfAttribute.TryGetReferencedMember(DeclaringObject, out checkIfShouldBeDrawed);
     }
 }
        public override bool IsVisible()
        {
            VisibleIfAttribute attr = GetAttr <VisibleIfAttribute>();

            if (!string.IsNullOrEmpty(attr.MemberName))
            {
                return(DrawerUtility.GetMemberValue <bool>(attr.MemberName, Property.Target));
            }
            return(false);
        }
Exemplo n.º 6
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ItemInfo"/> class.
            /// </summary>
            /// <param name="info">The reflection information.</param>
            /// <param name="attributes">The attributes.</param>
            public ItemInfo(ScriptMemberInfo info, object[] attributes)
            {
                Info              = info;
                Order             = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute);
                Display           = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute);
                Tooltip           = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
                CustomEditor      = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute);
                CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute);
                Space             = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute);
                Header            = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute);
                VisibleIf         = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute);
                IsReadOnly        = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null;
                ExpandGroups      = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null;

                IsReadOnly |= !info.HasSet;
                DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name);
            }
Exemplo n.º 7
0
        private static void ValidateVisibleIfAttributesOfComponent(MonoBehaviour behaviour)
        {
            var type = behaviour.GetType();
            VisibleIfAttribute invalidAttribute;
            var message = string.Empty;
            var fields  = ReflectionUtils.GetCachedFields(type);

            foreach (var field in fields)
            {
                if (VisibleIfAttribute.TryFindInvalidAttribute(behaviour, field, out invalidAttribute))
                {
                    message = string.Format("The attribute 'VisibleIf' of the field {0} of the component {1}  refers to a missing member -> '{2}'", field, type.Name, invalidAttribute.MemberName);
                    Debug.LogError(message, behaviour);
                    error_count++;
                }
            }
        }
Exemplo n.º 8
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ItemInfo"/> class.
            /// </summary>
            /// <param name="info">The reflection information.</param>
            /// <param name="attributes">The attributes.</param>
            public ItemInfo(ScriptMemberInfo info, object[] attributes)
            {
                Info              = info;
                Order             = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute);
                Display           = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute);
                CustomEditor      = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute);
                CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute);
                Space             = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute);
                Header            = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute);
                VisibleIf         = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute);
                IsReadOnly        = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null;
                ExpandGroups      = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null;

                IsReadOnly |= !info.HasSet;
                DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name);
                var editor = Editor.Instance;

                TooltipText   = editor.CodeDocs.GetTooltip(info, attributes);
                _membersOrder = editor.Options.Options.General.ScriptMembersOrder;
            }
Exemplo n.º 9
0
        private static ScriptMemberInfo GetVisibleIfSource(ScriptType type, VisibleIfAttribute visibleIf)
        {
            var property = type.GetProperty(visibleIf.MemberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (property != ScriptMemberInfo.Null)
            {
                if (!property.HasGet)
                {
                    Debug.LogError("Invalid VisibleIf rule. Property has missing getter " + visibleIf.MemberName);
                    return(ScriptMemberInfo.Null);
                }

                if (property.ValueType.Type != typeof(bool))
                {
                    Debug.LogError("Invalid VisibleIf rule. Property has to return bool type " + visibleIf.MemberName);
                    return(ScriptMemberInfo.Null);
                }

                return(property);
            }

            var field = type.GetField(visibleIf.MemberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (field != ScriptMemberInfo.Null)
            {
                if (field.ValueType.Type != typeof(bool))
                {
                    Debug.LogError("Invalid VisibleIf rule. Field has to be bool type " + visibleIf.MemberName);
                    return(ScriptMemberInfo.Null);
                }

                return(field);
            }

            Debug.LogError("Invalid VisibleIf rule. Cannot find member " + visibleIf.MemberName);
            return(ScriptMemberInfo.Null);
        }