混用ngui和ugui渲染顺序问题
http://blog.csdn.net/xtxy/article/details/38332801
接着上一篇文章的问题,看到了老外做的一个补丁,为ngui panel添加sorting layer,我也照着做了一个,这样ngui和unity2d就可以完全融合在一起了,层次关系可以任意设置。
ngui的版本为3.6.8,在其中添加代码:
文件:UIDrawCall.cs 109行左右
- /// <summary>
- /// Renderer's sorting order, to be used with Unity's 2D system.
- /// </summary>
- public int sortingOrder
- {
- get { return (mRenderer != null) ? mRenderer.sortingOrder : 0; }
- set { if (mRenderer != null && mRenderer.sortingOrder != value) mRenderer.sortingOrder = value; }
- }
- // added by Clark
- 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
- }
- }
- }
- // added end by Clark
712行左右
- /// <summary>
- /// Create a new draw call, reusing an old one if possible.
- /// </summary>
- 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;
- // added by Clark
- dc.sortingLayerName = pan.sortingLayerName;
- // added end by Clark
- dc.manager = pan;
- return dc;
- }
文件UIPanel.cs 130行左右
- // Clipping rectangle
- [HideInInspector][SerializeField] UIDrawCall.Clipping mClipping = UIDrawCall.Clipping.None;
- [HideInInspector][SerializeField] Vector4 mClipRange = new Vector4(0f, 0f, 300f, 200f);
- [HideInInspector][SerializeField] Vector2 mClipSoftness = new Vector2(4f, 4f);
- [HideInInspector][SerializeField] int mDepth = 0;
- [HideInInspector][SerializeField] int mSortingOrder = 0;
- // added by Clark
- [HideInInspector][SerializeField] string mSortingLayerName;
- // added end by Clark
252行左右
- public int sortingOrder
- {
- get
- {
- return mSortingOrder;
- }
- set
- {
- if (mSortingOrder != value)
- {
- mSortingOrder = value;
- if UNITY_EDITOR
- NGUITools.SetDirty(this);
- endif
- UpdateDrawCalls();
- }
- }
- }
- // added by Clark
- public string sortingLayerName
- {
- get { return mSortingLayerName; }
- set
- {
- if(mSortingLayerName != value)
- {
- mSortingLayerName = value;
- if UNITY_EDITOR
- NGUITools.SetDirty(this);
- endif
- UpdateDrawCalls();
- }
- }
- }
- // added end by Clark
1432行左右,在函数UpdateDrawCalls里面
- for (int i = 0; i < drawCalls.Count; ++i)
- {
- UIDrawCall dc = drawCalls[i];
- Transform t = dc.cachedTransform;
- t.position = pos;
- t.rotation = rot;
- t.localScale = scale;
- dc.renderQueue = (renderQueue == RenderQueue.Explicit) ? startingRenderQueue : startingRenderQueue + i;
- dc.alwaysOnScreen = alwaysOnScreen &&
- (mClipping == UIDrawCall.Clipping.None || mClipping == UIDrawCall.Clipping.ConstrainButDontClip);
- dc.sortingOrder = mSortingOrder;
- // added by Clark
- dc.sortingLayerName = mSortingLayerName;
- // added end by Clark
- }
文件UIPanelInspector.cs 9行
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- // added by Clark
- using System;
- using System.Reflection;
- using UnityEditorInternal;
- // added end by Clark
39行左右
- UIWidget.Pivot mDragPivot = UIWidget.Pivot.Center;
- GUIStyle mStyle0 = null;
- GUIStyle mStyle1 = null;
- // added by Clark
- string[] sortingLayerNames;
- // added end by Clark
49行左右
- protected override void OnEnable ()
- {
- base.OnEnable();
- mPanel = target as UIPanel;
- // added by Clark
- sortingLayerNames = GetSortingLayerNames();
- // added end by Clark
- }
574行左右
- GUI.changed = false;
- int so = EditorGUILayout.IntField("Sort Order", mPanel.sortingOrder, GUILayout.Width(120f));
- if (GUI.changed) mPanel.sortingOrder = so;
- // added by Clark
- int sortingLayerIndex = GetSortingLayerIndex(mPanel.sortingLayerName);
- int newSortingLayerIndex = EditorGUILayout.Popup("Sorting Layer", sortingLayerIndex, sortingLayerNames);
- if(sortingLayerIndex != newSortingLayerIndex)
- {
- mPanel.sortingLayerName = sortingLayerNames[newSortingLayerIndex];
- }
- // added end by Clark
785行左右,在文件最后
- // added by Clark
- string[] GetSortingLayerNames()
- {
- Type t = typeof(InternalEditorUtility);
- PropertyInfo prop = t.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
- return (string[])prop.GetValue(null, null);
- }
- int GetSortingLayerIndex(string layerName)
- {
- for(int i = 0; i < sortingLayerNames.Length; i++)
- {
- if(sortingLayerNames[i] == layerName)
- {
- return i;
- }
- }
- return 0;
- }
- // added end by Clark
这样,在UIPanel里面就多一个选项sorting layer:
完整的修改好的文件我放到我的资源里面了。
混用ngui和ugui渲染顺序问题的更多相关文章
- Unity NGUI和UGUI与模型、特效的层级关系
目录 1.介绍两大UI插件NGUI和UGUI 2.unity渲染顺序控制方式 3.NGUI的控制 4.UGUI的控制 5.模型深度的控制 6.粒子特效深度控制 7.NGUI与模型和粒子特效穿插层级管理 ...
- KING_Unity学习之UGUI_Canvas渲染顺序以及层次关系总结
http://blog.csdn.net/kingsea168/article/details/50252733 之前一直用NGUI开发界面,但看到现在的unity的新版本的UGUI也不错,这几天专门 ...
- Unity3D NGUI,uGUI总结
跪求官方UI系统(2014年11月底已出,用原生的比用NGUI放心) uGUI注意点 1.要防止多个canvas叠加点击穿透,canvas里面的graphics raycaster调整到恰当选项 2. ...
- [UGUI]渲染层级关系
参考链接: http://blog.csdn.net/meegomeego/article/details/42060389 Unity中的渲染顺序自上而下大致可以分为三层: 1.Camera层.可以 ...
- SKNode的渲染顺序
[SKNode的渲染顺序] SKNode的zPosition属性,指定相对于其父视图的z轴坐标. The default value is 0.0. The positive z axis is pr ...
- 【Unity笔记】UGUI物体的渲染顺序
①不同Camera的Depth.(大在前,小在后)②同Camera的SortingLayer.(下在前,上在后)③同SortingLayer下的Order in Layer.(大在前,小在后)④同Or ...
- SVG渲染顺序及z轴显示问题(zIndex)
SVG是严格按照定义元素的顺序来渲染的,这个与HTML靠z-index值来控制分层不一样. 在SVG中,写在前面的元素先被渲染,写在后面的元素后被渲染.后渲染的元素会覆盖前面的元素,虽然有时候受透明度 ...
- 关于Unity中的NGUI和UGUI
一.用Unity开发2D游戏,有三套关系 1.GUI:Unity本身自带的GUI 2.NGUI:以前在Unity中广泛来做2D的,是第三方的包,需要安装 3.UGUI:Unity5.X后(其实是Uni ...
- NGUI和UGUI动画不能设置alpha值的问题
动画播放alpha参数改变但无实际画面效果,原因是要挂一个脚本,设置实时更新数据. NGUI void Update() { widget.SetDirty(); } UGUI void Update ...
随机推荐
- git和github菜鸟使用步骤
刚刚在windows7下安装完git.奉上安装步骤. git安装 安装git程序.运行以下操作: 1. $ cd ~/.ssh //检查计算机ssh密钥 2.假设没有提示:No such fil ...
- EasyDarwin开源流媒体服务器实现RTSP直播同步输出MP4、RTMP、HLS的方案思路
背景 近期跟开源团队商量,想在EasyDarwin上继续做一些功能扩展,目前EasyDarwin开源流媒体服务器只能够实现高效的RTSP推流直播转发/分发功能,输入与输出都是RTSP/RTP流,不能够 ...
- [Phoenix] 六、MR在Ali-Phoenix上的使用
摘要: 在云HBASE上利用MR BULKLOAD入库PHOENIX表或通过MR构建PHOENIX索引表. 一.MR在Phoenix上的用途 利用MR对Phoenix表(可带有二级索引表)进行Bulk ...
- memcached和一致性hash算法
1 一致性hash算法的一致性 这里的一致性指的是该算法可以保持memcached和数据库中的数据的一致性. 2 什么是一致性hash算法 2.1 为什么需要一致性hash算法 现在有大量的key v ...
- appium()-java-client-api
//appium java-client-api 介绍 原文地址:http://appium.github.io/java-client/index-all.html#_S_ A B C D E F ...
- 调用远程service aidl接口定义
Android studio 查看aidl定义的文件:当你进入你的AIDL文件并编写好了之后,点击AS上方菜单栏中的Build->Make Project,之后便可以在当前工程的app/buil ...
- 负载均衡LVS
可参考:http://ixdba.blog.51cto.com/2895551/555738 http://os.51cto.com/art/201202/319979.html 也可以参考官网:ht ...
- hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)
#1103 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorit ...
- docker安装mysql挂载宿主本地目录资源后无法启动的问题
可能是权限问题,添加--privileged=true参数: docker run -p : --name zsmysql -v $PWD/data:/var/lib/mysql -v $PWD/lo ...
- DDD领域驱动之干货 (一)
说道DDD不得不说传统的架构与DDD的架构区别. 传统的架构不外乎就是三层,而在这三层里面又不断的细分,始终没有达到想要的效果,那么为什么当时还是采用三层. 当然在DDD没有提出的时候三层是大多数人的 ...