ngui 和粒子層級問題

轉自http://blog.csdn.net/highning0007/article/details/37991193


方法一:

提供一個腳本。放在粒子上。

調整相應的renderQueue使粒子顯示在UI前面。如果有些UI需要顯示在粒子前面,記得修改相應UI的renderQueue。


[csharp] view plaincopy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. [ExecuteInEditMode]  
  5. public class SZUIRenderQueue : MonoBehaviour {  
  6.       
  7.     public int renderQueue = 3000;  
  8.     public bool runOnlyOnce = false;  
  9.       
  10.     void Start()  
  11.     {  
  12.         Update();  
  13.     }  
  14.       
  15.     void Update()  
  16.     {  
  17.         if (renderer != null && renderer.sharedMaterial != null)  
  18.         {  
  19.             renderer.sharedMaterial.renderQueue = renderQueue;  
  20.         }  
  21.         if (runOnlyOnce && Application.isPlaying)  
  22.         {  
  23.             this.enabled = false;  
  24.         }  
  25.     }  
  26. }  

方法二:

去官方下載粒子的Shader,之後手動在Shader裏面修改RenderQueue。

http://unity3d.com/unity/download/archive  (Built-in shaders)


方法三:

(感謝穆斯提供腳本)

[csharp] view plaincopy
  1. using UnityEngine;  
  2.   
  3. [ExecuteInEditMode]  
  4. class SZUIRenderQueueToWidget : MonoBehaviour  
  5. {  
  6.     public UIWidget widget;  
  7.     public int rendererQOffset = 3000;  
  8.     public bool runOnlyOnce = false;    
  9.   
  10.     void Update()  
  11.     {  
  12.         Renderer r = renderer;  
  13.   
  14.         if (widget == null)   
  15.         {  
  16.             widget = GetComponent<UIWidget>();  
  17.         }  
  18.   
  19.         if (widget != null && widget.drawCall != null && r != null)  
  20.         {  
  21.             int targetQ = widget.drawCall.renderQueue + rendererQOffset;  
  22.             if (targetQ > 0)  
  23.             {  
  24.                 r.sharedMaterial.renderQueue = targetQ;   
  25.             }  
  26.         }  
  27.         if (runOnlyOnce && Application.isPlaying)    
  28.         {    
  29.             this.enabled = false;    
  30.         }    
  31.     }  
  32. }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章