Beispiel #1
0
        /// <summary>
        /// Determines whether or not 'member' should be visible in the inspector
        /// The logic goes like this:
        /// If member was a method or property it is visible only if it's annotated with [Show]
        /// If member was a field it is visible if
        /// 1- it's annotated with [Show]
        /// 2- OR if it's serializable
        /// </summary>
        public static bool IsVisibleMember(MemberInfo member)
        {
            if (member is MethodInfo)
            {
                return(Attributes.Show.Any((t) => MemberInfoExtensions.IsDefined(member, t)));
            }

            var field = member as FieldInfo;

            if (field != null)
            {
                if (Attributes.Hide.Any((t) => MemberInfoExtensions.IsDefined(field, t)))
                {
                    return(false);
                }

                if (Attributes.Show.Any((t) => MemberInfoExtensions.IsDefined(field, t)))
                {
                    return(true);
                }

                if (field.IsDefined <SerializeField>())
                {
                    return(true);
                }

                return(IsSerializableField(field));
            }

            var property = member as PropertyInfo;

            if (property == null || Attributes.Hide.Any((t) => MemberInfoExtensions.IsDefined(property, t)))
            {
                return(false);
            }

            // accept properties such as transform.position, rigidbody.mass, etc
            // exposing unity properties is useful when inlining objects via [Inline]
            // (which is the only use-case these couple of lines are meant for)
            var  declType         = property.DeclaringType;
            bool isValidUnityType = declType.IsA <Component>() && !declType.IsA <MonoBehaviour>();
            bool unityProp        = isValidUnityType && property.CanReadWrite() && !IgnoredUnityProperties.Contains(property.Name);

            if (unityProp)
            {
                return(true);
            }

            if (Attributes.Show.Any((t) => MemberInfoExtensions.IsDefined(property, t)))
            {
                return(true);
            }

            return(false);
        }