1 - I think PropertyAttribute is only for Fields, how can I fix it?
2 - How do I get the value of SerializedProperty? With that it would be easy to get the MemberInfo and do the Invoke
[AttributeUsage(AttributeTargets.Method)]
public sealed class ButtonAttribute : PropertyAttribute
{
public string Name { get; set; }
public ButtonAttribute(string name)
{
Name = name;
}
}
[CustomPropertyDrawer(typeof(ButtonAttribute))]
public class ButtonAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// TODO: How to get the MemberInfo?
MethodInfo methodInfo = null;
ButtonAttribute buttonAttribute = attribute as ButtonAttribute;
if (GUILayout.Button(buttonAttribute.Name))
{
// TODO: this is right?
object target = property.serializedObject;
methodInfo.Invoke(target, null);
}
}
}
}
That’s exactly what I’m trying to do! I actually did it the same way EasyButton did it, drawing buttons from using [CustomEditor(typeof(Object), true)]
I downloaded EasyButton and tested it, it has the same problem I’m going through. It does not support buttons inside Objects.
Do you know how can I draw buttons inside objects?
DISREGARD the following, I just looked at how CPDs work… Sorry, not sure how to solve your problem!
I think you could perhaps just wind it in with the Custom Property drawer concept we talked about in the other thread?
I think once you are in code that is drawing a custom property, you would just do an if (GUILayout.Button()) for that item… I gotta admit though, I’ve not gone to this level of Inception on the editor.