UIDrawCall
public string sortingLayerName
{
get
{
return (mRenderer != null) ? mRenderer.sortingLayerName : "default";
}
set
{
if (mRenderer != null && mRenderer.sortingLayerName != value)
{
mRenderer.sortingLayerName = value;
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
}
}
}
static UIDrawCall Create (string name, UIPanel pan, Material mat, Texture tex, Shader shader)
{
UIDrawCall dc = Create(name);
dc.gameObject.layer = pan.cachedGameObject.layer;
dc.baseMaterial = mat;
dc.mainTexture = tex;
dc.shader = shader;
dc.renderQueue = pan.startingRenderQueue;
dc.sortingOrder = pan.sortingOrder;
dc.sortingLayerName = pan.sortingLayerName;
dc.manager = pan;
return dc;
}
UIPanel
[HideInInspector][SerializeField] int mSortingOrder = 0;
[HideInInspector][SerializeField] string mSortingLayerName;
public string sortingLayerName { get {
return mSortingLayerName;
} set {
if (mSortingLayerName != value)
{
mSortingLayerName = value;
#if UNITY_EDITOR
NGUITools.SetDirty(this);
#endif
UpdateDrawCalls();
}
}
}
void UpdateDrawCalls (){
******
dc.sortingOrder = mSortingOrder;
dc.sortingLayerName = mSortingLayerName;
*******
}
面板添加
UIPanelInspector
string[] sortingLayerNames;
protected override void OnEnable ()
{
base.OnEnable();
mPanel = target as UIPanel;
sortingLayerNames = GetSortingLayerNames();
}
protected override bool ShouldDrawProperties (){
************
int sortingLayerIndex = GetSortingLayerIndex(mPanel.sortingLayerName);
int newSortingLayerIndex = EditorGUILayout.Popup("Sorting Layer", sortingLayerIndex, sortingLayerNames);
if(sortingLayerIndex != newSortingLayerIndex)
{
mPanel.sortingLayerName = sortingLayerNames[newSortingLayerIndex];
}
************
}
private string[] GetSortingLayerNames()
{
Type t = typeof(InternalEditorUtility);
PropertyInfo property = t.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
return property.GetValue(null, null) as string[];
}
int GetSortingLayerIndex(string layerName)
{
for (int i = 0;i < sortingLayerNames.Length;i++)
{
if (sortingLayerNames[i] == layerName)
{
return i;
}
}
return 0;
}
标签:layer,排序,return,string,dc,sortingLayerNames,sortingLayerName,NGUI,pan From: https://www.cnblogs.com/kayRao/p/18243334