public override void DrawMethod(MightyMember <MethodInfo> mightyMember, BaseMethodAttribute baseAttribute)
        {
            var methodInfo = mightyMember.MemberInfo;

            if (methodInfo.GetParameters().Length == 0)
            {
                var buttonAttribute = (ButtonAttribute)baseAttribute;
                var buttonText      = string.IsNullOrEmpty(buttonAttribute.Text) ? methodInfo.Name.DrawPrettyName() : buttonAttribute.Text;

                var enabled = GUI.enabled;
                if (!m_buttonCache.Contains(mightyMember))
                {
                    InitDrawer(mightyMember, baseAttribute);
                }
                GUI.enabled = m_buttonCache[mightyMember].Value && (buttonAttribute.ExecuteInPlayMode || !EditorApplication.isPlaying);

                if (GUILayout.Button(buttonText, GUILayout.Height(buttonAttribute.Height)))
                {
                    methodInfo.Invoke(mightyMember.Target, null);
                }

                GUI.enabled = enabled;
            }
            else
            {
                EditorDrawUtility.DrawHelpBox($"{typeof(ButtonAttribute).Name} works only on methods with no parameters");
            }
        }
Exemple #2
0
        public override void DrawField(MightyMember <FieldInfo> mightyMember, BaseDrawerAttribute baseAttribute)
        {
            var attribute = (ShowNonSerializedAttribute)baseAttribute;
            var field     = mightyMember.MemberInfo;
            var value     = field.GetValue(mightyMember.Target);

            if (EditorDrawUtility.DrawLayoutField(attribute.DrawPrettyName ? field.Name.DrawPrettyName() : field.Name, value,
                                                  attribute.Enabled))
            {
                return;
            }

            EditorDrawUtility.DrawHelpBox($"{typeof(ShowNonSerializedAttribute).Name} doesn't support {field.FieldType.Name} types");
        }
        public static void CacheClassDrawersForType(this MightyMember <Type> mightyMember, Type type,
                                                    IEnumerable <BaseMightyAttribute> wrappedAttributes)
        {
            var classAttributes = new List <BaseClassAttribute>();

            var any = PopulateAttributesList(classAttributes, type.GetCustomAttributes <BaseClassAttribute>(true));

            any = PopulateAttributesList(classAttributes, wrappedAttributes) || any;

            if (any)
            {
                mightyMember.SetAttributes(classAttributes.ToArray());
            }
        }
Exemple #4
0
        private bool CacheClass(Type type, MightyContext context)
        {
            if (type.IsSubclassOf(typeof(BaseWrapperAttribute)) || !type.HasAttributeOfType <BaseClassAttribute>())
            {
                return(false);
            }

            m_classMember = new MightyMember <Type>(type, context);

            var wrappedAttributes = m_classMember.GetWrappedAttributes <BaseClassAttribute>();

            m_classMember.CacheClassDrawersForType(type, wrappedAttributes);

            return(true);
        }
Exemple #5
0
        public override void DrawMethod(MightyMember <MethodInfo> mightyMember, BaseMethodAttribute baseAttribute)
        {
            var methodInfo = mightyMember.MemberInfo;

            if (methodInfo.GetParameters().Length == 0)
            {
                if (baseAttribute.ExecuteInPlayMode || !EditorApplication.isPlaying)
                {
                    methodInfo.Invoke(mightyMember.Target, null);
                }
            }
            else
            {
                EditorDrawUtility.DrawHelpBox($"{baseAttribute.GetType().Name} works only on methods with no parameters");
            }
        }
        public override void DrawField(MightyMember <FieldInfo> mightyMember, BaseDrawerAttribute baseAttribute)
        {
            var attribute = (EditorSerializeAttribute)baseAttribute;
            var context   = mightyMember.Context;
            var field     = mightyMember.MemberInfo;
            var target    = mightyMember.Target;

            if (attribute.OldName != null)
            {
                EditorFieldsDatabase.RenameField(context, attribute.OldName, field.Name);
            }

            if (attribute.Options == EditorFieldOption.Hide)
            {
                return;
            }

            var editorField = EditorFieldsDatabase.GetEditorField(context, field.Name);
            var value       = field.GetValue(target);

            if (attribute.Options.Contains(EditorFieldOption.Deserialize))
            {
                Deserialize(attribute, editorField, target, field, ref value);
            }

            if (attribute.Options.Contains(EditorFieldOption.Hide) &&
                field.GetCustomAttribute(typeof(HideAttribute), true) is HideAttribute)
            {
                if (attribute.Options.Contains(EditorFieldOption.Serialize))
                {
                    Serialize(attribute, editorField, value, field.FieldType);
                }
                return;
            }

            if (attribute.Options.Contains(EditorFieldOption.Hide))
            {
                return;
            }

            EditorGUI.BeginChangeCheck();

            if (field.GetCustomAttribute(typeof(CustomDrawerAttribute), true) is CustomDrawerAttribute drawerAttribute &&
                (DrawersDatabase.GetDrawerForAttribute <CustomDrawerPropertyDrawer>(typeof(CustomDrawerAttribute)) is var drawer))
            {
                value = drawer.DrawField(field, context, value, drawerAttribute);
            }
        public override void DrawNativeProperty(MightyMember <PropertyInfo> mightyMember, BasePropertyAttribute baseAttribute)
        {
            var property = mightyMember.MemberInfo;

            if (!m_showNativeCache.Contains(mightyMember))
            {
                InitDrawer(mightyMember, baseAttribute);
            }
            var value = m_showNativeCache[mightyMember].Value;

            if (value == null)
            {
                EditorDrawUtility.DrawHelpBox($"{typeof(ShowNativePropertyNativePropertyDrawer).Name} doesn't support Reference types");
            }
            else if (!EditorDrawUtility.DrawLayoutField(property.Name, value, false))
            {
                EditorDrawUtility.DrawHelpBox(
                    $"{typeof(ShowNativePropertyNativePropertyDrawer).Name} doesn't support {property.PropertyType.Name} types");
            }
        }
Exemple #8
0
 public void EndDrawClass(MightyMember <Type> mightyType, BaseClassAttribute baseAttribute) =>
 EndDrawClass(mightyType, (T)baseAttribute);
Exemple #9
0
 public void OnDisableClass(MightyMember <Type> mightyType, BaseClassAttribute baseAttribute) =>
 OnDisableClass(mightyType, (T)baseAttribute);
Exemple #10
0
 protected override void OnEnableClass(MightyMember <Type> mightyType, HideStatusAttribute attribute) =>
 mightyType.Context.Drawer.hideStatus |= attribute.HideStatus;
Exemple #11
0
 protected override void EndDrawClass(MightyMember <Type> mightyType, HideStatusAttribute attribute)
 {
 }
Exemple #12
0
 protected override void OnDisableClass(MightyMember <Type> mightyType, HideStatusAttribute attribute)
 {
 }
 public abstract void DrawNativeProperty(MightyMember <PropertyInfo> mightyMember, BasePropertyAttribute baseAttribute);
Exemple #14
0
 public abstract void DrawMethod(MightyMember <MethodInfo> mightyMember, BaseMethodAttribute baseAttribute);
Exemple #15
0
 protected abstract void OnDisableClass(MightyMember <Type> mightyType, T attribute);
Exemple #16
0
 protected abstract void EndDrawClass(MightyMember <Type> mightyType, T attribute);
 public abstract void DrawField(MightyMember <FieldInfo> mightyMember, BaseDrawerAttribute baseAttribute);