Search Unity

EditorGUILayout.MaskField how to?

Discussion in 'Editor & General Support' started by dothem, Nov 23, 2016.

  1. dothem

    dothem

    Joined:
    Feb 28, 2016
    Posts:
    22
    Heyo

    I'm trying to figure out how I have to use EditorGUILayout.MaskField. I have a normal script, which I attach to a GameObject as Component.

    In this script is a String[] which should hold all the selected data from MaskField.

    I've created a CustomEditor class, this all works fine on other properties like Enum (single select) or other single select values.

    My only problem ist the multi select (MaskField). What I have so far for the MaskField:

    Code (CSharp):
    1. int flag = EditorGUILayout.MaskField("Test", 0, allElements);
    2.             for (int i = 0; i < allElements.Length; i++)
    3.             {
    4.                 int layer = 1 << i;
    5.                 if ((flag & layer) != 0)
    6.                 {
    7.                     string selectedItem = allElements[i];
    8.                 }
    9.             }
    In OnEnable I have the following:

    Code (CSharp):
    1. public void OnEnable()
    2.     {
    3.         elementsToColor = serializedObject.FindProperty("_elementsToColor");
    4.  
    5.     }
    I also have this at the end of the script:

    Code (CSharp):
    1. serializedObject.ApplyModifiedProperties();
    These is the propery from the Component script class.

    Can someone please help me?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562