Search Unity

Boolean alignment in Editor Script

Discussion in 'Scripting' started by Studio_Akiba, Jun 30, 2015.

  1. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    For the latest version of one of my assets, I am trying to add a setting to the editor window, this in itself works fine, but there are a few things I will need help being pointed in the right direction with (stuff I haven't done before).

    Currently, I have a boolean in my window called faceDirectionControl, and another 3 booleans that I want to work like radio buttons called X, Y and Z.

    My main issue at the moment is that I want the faceDirectionControl boolean to determine whether the 3 child booleans (X, Y, Z) are visible and settable in the window or not.

    My secondary issue is being able to get booleans to act like radio buttons (I have not seen anyone do this in an editor so I'm not even sure if it is possible).

    Finally, I would need to be able to get all this information (if faceDirectionControl is true (Easy) and WHICH of the radio booleans is ticked).
     
  2. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
  3. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    Use an enum not a boolean.
     
  4. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    If you're fine with it only working like radio buttons while the game (and script) are running, that's easy enough. Just use accessor methods on each of the items during their definition to override the set and turn off the other 3:

    public bool boolOne
    {
    get;
    set
    {
    if (value)
    {
    //set the others to false;
    }
    }
    }

    However, member variables with accessors don't show up in the editor, so that doesn't give you what you want :/. I don't know of any way to add functionality to editor variables. Sorry!
     
  5. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Yeah, good point Korno - just use an enum for a drop-down. Then you know what IS selected, and can infer the rest.
     
  6. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    Thanks, this was actually the same conclusion I came to, but have decided that I won't be able to get the information from the editor script to the main script (I am adding this as a setting in an editor window).

    I do not believe I will be able to use this method to change this setting at the moment, a bit annoying but something I may have to live with.