Is there any update on this? I think this is a very important feature and surprised it's not added yet. Even more so when it can be added relevantly quickly to support it at a Panel level (which I think is all that is required, as you would expect everything on a UIPanel to be drawn on the same layer.
I've edited NGUI's code to support it, but I just know someday I will forget to put the edits back in after an update. For those interested, this is my code to show a dropdown for sorting layers in UIPanel inspector (using the latest NGUI version).
In UIPanelInspector.cs, line 9 add:
using UnityEditorInternal;
using System.Reflection;
using System;
In UIPanelInspector.cs, line 458 add:
GUILayout.BeginHorizontal();
{
EditorGUILayout.PrefixLabel("Sorting Layer");
// Get the names of the Sorting layers
System.Type internalEditorUtilityType
= typeof(InternalEditorUtility
); PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
string[] names
= (string[])sortingLayersProperty
.GetValue(null,
new object[0]);
int index = 0;
if (!String.IsNullOrEmpty(mPanel.mSortingLayer))
{
for (int i = 0; i < names.Length; i++)
{
if (mPanel.mSortingLayer == names[i])
{
index = i;
break;
}
}
}
// Get the selected index and update the panel sorting layer if it has changed
int selectedIndex = EditorGUILayout.Popup(index, names);
if (index != selectedIndex)
{
mPanel.mSortingLayer = names[selectedIndex];
EditorUtility.SetDirty(mPanel);
}
}
GUILayout.EndHorizontal();
In UIDrawCall.cs, line 130 add:
public string sortingLayerName
{
get { return (mRenderer != null) ? mRenderer.sortingLayerName : ""; }
set { if (mRenderer != null && mRenderer.sortingLayerName != value) mRenderer.sortingLayerName = value; }
}
In UIPanel.cs, line 97 add:
/// <summary>
/// The sorting layer for this panel, used to work with Unity 2D system
/// </summary>
public string mSortingLayer = "";
In UIPanel.cs, line 263 add (this could potentially be optimised?):
dc.sortingLayerName = mSortingLayer;
Now you should have a dropdown for your UIPanels to select the sorting layer it should be drawn on.