Search Unity

[Solved] Manually set EditorStyles.radioButton selection state

Discussion in 'Immediate Mode GUI (IMGUI)' started by Senshi, Jun 9, 2017.

  1. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Hi all,

    I'm currently working on a custom editor. What I'm trying to accomplish is essentially a radio button togglegroup where, when a radio button is clicked, it should set an int property to it's associated value. However, if the button already was selected, it should set the property to -1.

    GUILayout.Toggle() works nicely, except it fires when it's active, rather than when it's clicked. A GUILayout.Button() with the radioButton style seems to be the way to go then, but I for the life of me can't figure out how to get it to display in the active/ selected state. Any thoughts?

    Thanks,
    Patrick
     
  2. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    And of course I find a solution right after posting. For future readers: I ended up creating a custom GUIStyle derived from the exiting radioButton one and swapping the normal and active states.

    Cheers!
     
    Sundiray likes this.