Search Unity

EnumMaskField and unwanted mixed values

Discussion in 'Scripting' started by Mr-Knieves, Sep 16, 2013.

  1. Mr-Knieves

    Mr-Knieves

    Joined:
    Mar 7, 2013
    Posts:
    41
    Hello!

    I've been poking around Unity for fun, trying to customize the inspector of my gameplay scripts, but when it comes to enums, I can't seem to be able to remove the "Everything", "Nothing" options from there. Is there a way to disable the "mixed" mode and force the inspector to just allow the user to select one value? The default inspector has no problem with that so I guess it's doable.

    My enum
    Code (csharp):
    1.  
    2. public enum PowerUpType
    3. {
    4.     NONE = 0,
    5.     SPEEDBOOST = 1,
    6.     FUEL = 2,
    7.     JUMPBOOST = 3  
    8. }
    9.  
    My OnInspectorGUI()
    Code (csharp):
    1.  
    2.     public override void OnInspectorGUI()
    3.     {      
    4.         PowerUps powerup = target as PowerUps;
    5.         powerup.PowerupType = (PowerUpType)EditorGUILayout.EnumMaskField("PowerupType",powerup.PowerupType);
    6.     }
    7.  
    Unwanted result:
    $Capture.PNG

    All I want there is the options on my enum, nothing else, not sure where those values are coming from or how to remove them. :(

    PS: I'm a seasoned C# programmer, but this is my first time trying to modify the inspector so please be gentle :)

    PS2: I did search google and this forum and couldn't find anything as to how to disable mixed mode, I tried setting showMixedValue to false but to no avail.

    Thanks!!
     
    rakkarage likes this.
  2. Marrrk

    Marrrk

    Joined:
    Mar 21, 2011
    Posts:
    1,032
    None and Everything are autogenerated to cover the both special cases of masked values, mask values are bit combinations of each possible option in your enum. Your enum doesnt look like a real flag/mask enum.

    For example this would be a valid mask/flag enum:

    Code (csharp):
    1.  
    2. [Flags] // not mandatory for unity
    3. public enum FlagTest
    4. {
    5.   CanBreath = 0x1,
    6.   CanDie = 0x2,
    7.   IsBurning = 0x4  
    8. }
    9.  
    With this you can add something like this:

    Code (csharp):
    1.  
    2. bool CanBreath = true;
    3. bool CanDie = false;
    4. bool IsBurning = true;
    5.  
    in one Property:

    Code (csharp):
    1.  
    2. FlagTest ObjectFlags = FlagTest.CanBreath | FlagTest.IsBurning:
    3.  
    For your needs you should better use http://docs.unity3d.com/Documentation/ScriptReference/EditorGUILayout.EnumPopup.html
     
    Katori-Nori likes this.
  3. Mr-Knieves

    Mr-Knieves

    Joined:
    Mar 7, 2013
    Posts:
    41
    EnumPopup worked beautifully! Thanks a LOT kind sir! Time to dig deeper and see what more I can do with it!
     
  4. Katori-Nori

    Katori-Nori

    Joined:
    Mar 3, 2015
    Posts:
    6
    EnumPopup worked beautifully! Legend!