Search Unity

How to get button shown in the inspector for method on scriptable with using attribute

Discussion in 'Editor & General Support' started by pretender, Jun 9, 2017.

  1. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Hi! I was trying to figure out how to have button shown in the inspector that will trigger method
    in the scriptable object like this

    [Button]
    public void Populate()
    {

    }

    so, I have a scriptable object, named Storage. I create instance of it in editor time. I have a few methods that I currently trigger via context menu that I want now just to mark with attribute like this [Button] and to have it shown in the inspector. I suspect that I need to have atrribute class and custom property drawer but I am not sure how to get the method to trigger?

    This is the most simplest case that I can't figure out, can somebody point me in the right direction or share samples.

    Thanks!
     
    fffMalzbier likes this.
  2. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Any idea how to do this? it's for learning purposes...
    I know I need to get the button attribute class that will be used on some method and property drawer, but how to get
    the method to invoke? I should be using reflection, but don't know how to connect it all
     
  3. Hs_Jack

    Hs_Jack

    Joined:
    Nov 19, 2015
    Posts:
    3
    I just have the same question for a longtime, until I find this perfect solution:
    https://github.com/dbrizov/NaughtyAttributes

    Not only you can create Button Attribute to Invoke Method, but also ReorderableList, Dropdown, Preview and so on!