Author Topic: Can't get renderer on UIWidget so RenderQueueModifier can't work  (Read 7552 times)

wangzy_88

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
I use RenderQueueModifier to control gameObject(model and paticle) and UIWidget depth.But I find can't get renderer on UIWidget now,I use unity5.0.4 and NGUI3.8.0.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can't get renderer on UIWidget so RenderQueueModifier can't work
« Reply #1 on: April 01, 2015, 10:59:17 PM »
Widgets never had renderers, so I am not sure what you're asking here...

cuidaguang

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 5
    • View Profile
Re: Can't get renderer on UIWidget so RenderQueueModifier can't work
« Reply #2 on: April 02, 2015, 02:45:23 AM »
I use RenderQueueModifier to control gameObject(model and paticle) and UIWidget depth.But I find can't get renderer on UIWidget now,I use unity5.0.4 and NGUI3.8.0.

I guess the "UIWidget" you mean is “UISprite”. You want to set the paticle to be in front or back of the sprite. So just add <UISprite> component to the widget. BTW, to render a model into uipanel, you should try rendertarget.

wangzy_88

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: Can't get renderer on UIWidget so RenderQueueModifier can't work
« Reply #3 on: April 03, 2015, 04:33:29 AM »
I change script in "Topic: Useful stuff" like this:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [ExecuteInEditMode]
  5. public class RenderQueueModifier : MonoBehaviour
  6. {
  7.  
  8.     #region VARIABLE
  9.     public enum renderType
  10.     {
  11.         front,
  12.         back
  13.     }
  14.     public GameObject target;
  15.     public renderType type = renderType.front;
  16.  
  17.     Renderer[] _renderers;
  18.     int _lastQueue;
  19.     #endregion
  20.  
  21.     #region FUNCTION
  22.  
  23.     #endregion
  24.  
  25.     #region MONOBEHAVIOUR
  26.     void Start()
  27.     {
  28.         _renderers = GetComponentsInChildren<Renderer>();
  29.     }
  30.  
  31.     void Update()
  32.     {
  33.         if (target == null)
  34.         {
  35.             return;
  36.         }
  37.         UIWidget widget = target.GetComponent<UIWidget>();
  38.         int queue = 0;
  39.         if (widget == null)
  40.         {
  41.             if (widget.drawCall == null)
  42.             {
  43.                 return;
  44.             }
  45.             queue = widget.drawCall.renderQueue;
  46.         }
  47.         else
  48.         {
  49.             Material m = target.GetComponentInChildren<Renderer>().sharedMaterial;
  50.             if (m == null)
  51.             {
  52.                 return;
  53.             }
  54.             queue = m.renderQueue;
  55.         }
  56.         queue += type == renderType.front ? 1 : -1;
  57.         if (_lastQueue != queue)
  58.         {
  59.             _lastQueue = queue;
  60.             foreach (Renderer r in _renderers)
  61.             {
  62.                 r.material.renderQueue = _lastQueue;
  63.             }
  64.         }
  65.     }
  66.     #endregion
  67. }
  68.  
I use this to control mesh/particle and UIComponent depth.It works very well before,but now it can't work.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can't get renderer on UIWidget so RenderQueueModifier can't work
« Reply #4 on: April 04, 2015, 04:12:38 AM »
The script in the Useful Stuff sticky post was meant to be used on renderers and particle effects. It won't work on widgets at all. To change the draw order of widgets you'd need to alter the UIPanel they belong to -- giving it an explicit render queue.

Assuming you've done that correctly (as you've mentioned it worked before), can you confirm that it works as expected in Unity 4, and doesn't work in Unity 5?

wangzy_88

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: Can't get renderer on UIWidget so RenderQueueModifier can't work
« Reply #5 on: April 05, 2015, 10:09:43 PM »
1.My script is wrong,"if (widget == null)" should be "if (widget != null)". :P
2.The wrong script worked well on ngui3.7.4 but can't work on ngui3.8.0,both Unity5.
3.I change my fault and test again on ngui3.8.0,find it can't work very well still,mesh and UIWidget depth only decided by position,particle and UIWidget depth decided by position and renderQueue.Maybe is Unity standard shader's business.