Search Unity

List of sorting layers

Discussion in '2D' started by Angelo-Franco, Nov 13, 2013.

  1. Angelo-Franco

    Angelo-Franco

    Joined:
    Feb 1, 2013
    Posts:
    10
    I would like to know how to get a list of all sorting layers.

    I'm able to access the tags list and layers list by using the class UnityEditorInternal.InternalEditorUtility.
    But I can't find the sorting layers anywhere.

    Please advise.
     
  2. DevSketchpad

    DevSketchpad

    Joined:
    Oct 5, 2013
    Posts:
    2
    Bump...

    Yep, this would definitely be really handy
     
  3. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Agreed. Anyone figure this out?
     
  4. imurashka

    imurashka

    Joined:
    Aug 5, 2012
    Posts:
    20
    This property is internal and we can't get sortingLayers. But...
    Code (csharp):
    1.  
    2. Type internalEditorUtilityType = typeof(InternalEditorUtility);
    3. PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
    4. string[] sortingLayers = (string[])sortingLayersProperty.GetValue(null, new object[0]);
    5. foreach (string layer in sortingLayers)
    6. {
    7.     Debug.Log(layer);
    8. }
    9.  
     
    st-VALVe and MaxEden like this.