Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Functionality of EditorGUILayout.LayerField for SerializedProperty

Discussion in 'Scripting' started by cjddmut, Aug 5, 2014.

  1. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    178
    I'm building a custom editor for one of my components and one of the properties I can define is a layer index. Previously I just had it so you would set an int for the desired index, this was obviously undesirable so I searched a bit and found something that almost did what I wanted it to.

    Code (csharp):
    1.  
    2. myLayerProp.intValue = EditorGUILayout.LayerField("Layer", myLayerProp.intValue);
    3.  
    And this works awesomely, shows the name of the layer that I could select and assigned the correct index integer. However, it only works if all of the objects I'm editing have the value (actually that line above would even potentially overwrite some of the objects). So I'd like to support allowing editing multiple objects with the layer field but I can't find a way to quite pull this off. Or at least, not an easy straight forward way.

    TL;DR How can I get the allow edit of multiple objects using a layer field (not mask) and not just by assigning an integer?

    Thanks!
    C.J.
     
  2. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    178
    Let me rephrase what I'm looking for.

    What is the best way to edit a layer index property with a custom editor that supports editing multiple objects?
     
  3. BiomotionLab

    BiomotionLab

    Joined:
    Oct 9, 2018
    Posts:
    11
    Yes I"m having the same issue. Did you ever solve this?
     
  4. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    178
    Um that was 5 years ago so I can't remember. But thinking on it now you can resolve it with a custom editor/property drawer, check if it has multiple properties and if so use 'EditorGUI.showMixedValue' and only set the value back if it has been changed (which will set it to all the objects).