Custom attribute drawers

FlowCanvas Forums Support Custom attribute drawers

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2295
    lividthedream
    Participant

    I have a class which I created a custom drawer for using the ParadoxNotion API ( it inherits from DrawerAttribute ). This works fine when used in a custom FlowCanvas event, but I would like to be able to use the drawer to display my class the desired way when I use variables of that type in the blackboard and also when objects of that class are passed in as parameters to functions I have FlowCanvas or NodeCanvas nodes for.

    Is this possible? Right now, when I have a blackboard object of this type it displays the class name on a button ( I’d like to be able to control what is displayed on that button ) and then when I click on it I get a popup which just displays the public members of that class (I’d like to be able to control what is displayed there ).

    Thanks in advance!

    #2299
    Gavalakis
    Keymaster

    Hello,

    When you want to create a drawer for an object (class), you need to create an ‘ObjectDrawer’ (derive from ObjectDrawer(T) ). This way, the object will be drawn with this drawer wherver it is encounter, including the popup editor when the Blackboard variable button has been pressed, as well as within the inspector when used as a parameter for example. Here is a simple example:

    Unfortunately though, the button itself shown in the the blackboard variables list can not be changed, but the inspector within that popup editor when that button is clicked can.

    Let me know if that works for you.
    Thanks!

    Join us on Discord: https://discord.gg/97q2Rjh

    #2300
    lividthedream
    Participant

    Hi,

    I implemented this, but it never appears to call my code at all.

    The button on the blackboard variables window appears as before, but when the popup window opens the debug log doesn’t get called and the button doesn’t show. I tried putting the class in both a folder called Editor and a normal game folder ( not at the same time of course!) but neither one appeared to work.

    public class StateFlagObjectDrawer : ObjectDrawer<StateFlagRef>
    {
    static string NO_FLAG_STR = “”;
    bool open = false;

    public override StateFlagRef OnGUI(GUIContent content, StateFlagRef flagRef)
    {
    if (GUILayout.Button(“OK”))
    {
    Debug.Log(“OK”);
    }
    Debug.Log(“my drawer”);
    }
    return flagRef;
    }

    (Not sure how to insert code on this forum, so apologies for any bad formatting!)

    Update: On further debugging, when the code gets to EditorUtils::ReflectedFieldInspector for the variable of this class type, the parameters for field and attributes are both null, preventing it from finding the new drawer type, and instead reverting to the default drawer. Am I missing an attribute to get this to work?

    #2302
    Gavalakis
    Keymaster

    Hello,

    Hmm. What FlowCanvas version are you using just to confirm?
    The folder structure does not matter by the way, and no attribute is required for ObjectDrawer(T) to work.
    Have you tried with the example “MyClass” and “MyClassDrawer” I posted above just for testing purposes?
    Can you please post your code for StateFlagRef? Is it a class or a struct by the way (although this should not really matter)?

    Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

    #2303
    lividthedream
    Participant

    I tried with the MyClass sample you shared and I get the same problems. I was using version 2.8 and Unity 2017.4.0f1

    After that, I just updated both NodeCanvas and FlowCanvas to the latest version on the Asset Store (2.92), and it works fine!

    ( I was previously getting some errors after the update, but spotted that was due to a similarly named function in a static class that somehow ended up being used by FlowCanvas, but changing the function name fixed the errors.

    #2310
    Gavalakis
    Keymaster

    Thank you for the follow up.
    I am glad it works for you in the latest version 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

    #2314
    lividthedream
    Participant

    Thanks for your help. I’m a big fan of all of your tools!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.