首页 > 其他分享 >NGUI增加根据layer排序

NGUI增加根据layer排序

时间:2024-06-12 09:57:09浏览次数:10  
标签:layer 排序 return string dc sortingLayerNames sortingLayerName NGUI pan

 

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

相关文章

  • openlayers解决坐标经过本初子午线后横跨整个地图的异常问题
    在使用OpenLayers处理坐标系统和地图投影时,确保地图上的线条平滑过渡过本初子午线是一个常见的问题。本博客提供了一个针对EPSG:3857和EPSG:4326投影的坐标调整方法,以避免线条异常横跨整个地图的情况。针对3857投影当使用EPSG:3857投影时,坐标系统使用的是米为单位,而绘图......
  • Combining Recurrent, Convolutional, and Continuous-time Models with Linear State
    目录概符号说明LSSL和其它方法的联系代码GuA.,JohnsonI.,GoelK.,SaabK.,DaoT.,RudraA.,andReC.Combiningrecurrent,convolutional,andcontinuous-timemodelswithlinearstate-spacelayers.NeurIPS,2021.Statespacerepresentaion-wiki.概Mamba......
  • Java中List集合中多个字段如何排序
    开源项目SDK:https://github.com/mingyang66/spring-parent个人文档:https://mingyang66.github.io/raccoon-docs/#/一、首先定义一个三个属性的People类publicclassPeople{privateStringname;privateintage;privateintheight;publicPeople......
  • 【Java】7-1 职工排序题 分数 20
    1.为某保险公司设计一个职工管理系统,其中职工类的属性有:职工编号,姓名,性别,团体险业绩,个体险业绩;方法有:每个属性对应的set,get方法;不带参数的构造方法;带参数的构造方法,完成对职工属性的初始化;该类实现接口Comparable,完成对职工总业绩的比较。2.设计一个类,实现Comparator接口,......
  • Codeforces Problem 1980B Choosing cubes(基本排序)
    timelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputDmitryhas n......
  • 数据结构--第十章--内排序
    插入排序直接插入排序是一种稳定的排序方法快速排序递归调用树与性能分析快排算法实际上就是对枢轴的左右分区进行递归操作高效实现的快速排序算法是不稳定的且很复杂堆排序堆排序是不稳定的排序方法归并排序基数排序......
  • 【OJ】链表的按顺序排序
    题目描述~~~将带有头结点的单向链表结点中的数据从小到大排序。输入描述第一行输入链表长度;第二行输入链表结点中的数据。输出描述排序后的链表(输出头结点,用“Head”表示)用例输入160104286用例输出1Head->0->2->4->6->8->10code:#include<stdio.h>......
  • 数据结构---排序算法
    个人介绍hellohello~,这里是code袁~......
  • [Cloud Networking] Layer 2
    目录1.什么是MacAddress?2.如何查找MAC地址?3.二层数据交换1.什么是MacAddress?MAC地址是计算机的唯一48位硬件编码,嵌入到网卡中。MAC地址也称为网络设备的物理地址,在IEEE802中规定,数据链路层分为逻辑链路控制(LLC)子层和媒体控制访问(MAC)子层。MAC地址由数据链路层的......
  • 排序-选择排序
    学习目标:掌握选择排序学习内容:基本思想时间复杂度动画演示代码基本思想:首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置。再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。重复上一步,直到所有元素均排序完毕。时间复杂度:O(n^2)动......