Author Topic: UIPanel  (Read 70819 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIPanel
« on: November 20, 2013, 09:19:16 PM »
Overview

UIPanel is a component that collects and manages all widgets underneath it. UIPanel is responsible for creating the actual draw calls using the widget's geometry. Without panels, nothing can be drawn. If you're familiar with Unity, you can think of a UIPanel as a Renderer.

UIPanel inherits all the functionality of its base class -- UIRect.



All panels have a Depth value which affects all widgets underneath. If you're creating a complex UI with multiple windows, it's often best to have one UIPanel per window. The depth value of panels carries a lot more weight than the depth value on individual widgets, so it's a good idea to ensure that your panels don't share depth values. If values get shared, draw calls will start to get split up frequently in order to preserve the draw order, resulting in a lot more draw calls than usual.
  • Alpha property affects all the widgets underneath. It's a good way to fade out an entire window.
  • If your UI is affected by lighting, be sure to check the Normals checkbox.
  • If you are creating a scrollable panel that has a lot of geometry inside, you may want to toggle the Cull option in order to reduce the number of triangles drawn. Note that doing so may actually reduce performance, however (as the visibility of widgets will need to be checked every update!).
  • Checking the Static checkbox will improve performance by telling NGUI that widgets underneath this panel are not expected to move. NGUI will bypass checking for position/rotation/scale changes. Note that doing so means that moving widgets at run-time will not have any effect, however -- so be careful.
  • If you are trying to debug draw calls created by the panels, Show All option may help you. Doing so will let you see all the draw calls created by NGUI's panels in the order that they are drawn. Each draw call shows detailed information including the material used, which widgets are contributing to it, and even let you turn off the draw calls selectively in order to help you determine what's going on.
The panels can automatically Clip all children using the dimensions of your choice. To enable clipping, just choose one of the options under the Clipping drop-down, then adjust the dimensions of the purple rectangle in the Scene View like you would adjust the dimensions of any widget. If you're going down that route you can turn your panel into a Scroll View and make it draggable fairly easily as well.

In NGUI 3.5.5 and earlier versions, multiple clipped panels would not work. Only the last panel would clip the contents. This limitation was lifted in NGUI 3.5.6.

By default, all of NGUI's panels will begin drawing with Render Queues of 3000 and go up from there. You can change that by choosing something under the Render Q drop-down list. If you want to add a particle system in between of two of your panels, simply make sure that the first panel's render queue is lower than the one used by the particle system's material, and the second one has it set to a higher than the particle system. If you want NGUI 2.X-like behaviour where all draw calls were Z-based instead of depth-based, specify an Explicit render queue (3000 is what NGUI 2.X used).

If you are looking for the documentation regarding the Anchors section, you can find it in the base class -- UIRect.

Pro-Tip

A kinematic Rigidbody gets added to your panels automatically because according to Unity this greatly improves performance in physics-heavy games. Moving static colliders is a very expensive operation in Unity, but moving rigidbodies is not.

Class Documentation

http://tasharen.com/ngui/docs/class_u_i_panel.html

If you have a question regarding this component or would like me to clarify something, just post a reply here.
« Last Edit: March 30, 2014, 03:08:33 PM by ArenMook »

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: UIPanel
« Reply #1 on: November 28, 2013, 06:19:10 AM »
Could you clarify the static checkbox in regards to UILabels? Can we freely update UILabel.text values when the panel is marked as Static, especially if they scale or resize based on their Overflow settings?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel
« Reply #2 on: November 28, 2013, 03:53:37 PM »
Yes you can. The "static" checkbox on panels only tells the panel to not check transform-related changes -- that is position, rotation and scale. Everything NGUI-related will still cause the panels to update correctly.

poulpator

  • Guest
Re: UIPanel
« Reply #3 on: December 04, 2013, 04:52:09 AM »
Hi,
I used to display meshes with shaders with alpha in panels. Since my update to 3.X, those meshes are not displayed anymore. If I change the shader to one without alpha or if I disable the Panel script I can see the meshes again. Any idea?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel
« Reply #4 on: December 04, 2013, 05:30:55 PM »
NGUI never drew meshes. Unity drew them itself.

All NGUI geometry is drawn on render queues 3000 and higher.  If you had a transparent shader-using mesh, it would remain on the render queue of 3000, thus would appear behind most elements. You need to increase its render queue in order to draw it over the UI.

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: UIPanel
« Reply #5 on: April 05, 2014, 03:26:19 PM »
There is no Alpha clip, only soft clip (using 3.5.6) on Unity3.5.7.
I used Alpha Clip before and now it's gone, will it affect performance on mobile?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel
« Reply #6 on: April 06, 2014, 03:02:47 AM »
It was just pointless to have it as you can achieve the same exact effect with a soft clip set to border of 1. There was no performance difference between the two methods that I could discern.

keysosaurus

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: UIPanel
« Reply #7 on: April 07, 2014, 06:34:30 AM »
I have a custom shader that I use, I named it (AlphaClip) and (SoftClip) so it could be used in clipped panels.

Is this not possible any more in the new system???

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel
« Reply #8 on: April 08, 2014, 01:37:05 AM »
The way it's done has changed in 3.5.6 to allow nested clipping. Your old SoftClip shader should still work. There is no more AlphaClip.

keysosaurus

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: UIPanel
« Reply #9 on: April 08, 2014, 11:02:02 AM »
The shader is used to render eyes. It has two textures, one for the pupils and another used as a mask.
It uses texture offsets to move the pupils around, and works perfectly on non clipped panels.
"drawCall.dynamicMaterial.SetTextureOffset" is what i've been changing.

The offsets on the UITexture material seem to be updating in the inspector but the results can't be seen in game.

Any help would be greatly appreciated!
« Last Edit: April 08, 2014, 01:56:06 PM by keysosaurus »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel
« Reply #10 on: April 09, 2014, 04:16:24 AM »
The texture offset was never used properly by NGUI. It was used one way with clipped shaders, and another way with non-clipped shaders.

Instead of setting the texture offset on the material, set it on the UITexture itself. It has the "UV Rect" you can set.

keysosaurus

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: UIPanel
« Reply #11 on: April 09, 2014, 04:34:03 AM »
The problem with doing it that way is both textures in the shader are then offset.
I only want to offset the main texture as the mask texture keeps the pupils inside the eye socket.

It worked before, just wondering what has changed? Or where I can tweak the code myself?
« Last Edit: April 09, 2014, 04:41:28 AM by keysosaurus »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel
« Reply #12 on: April 10, 2014, 08:04:50 AM »
Sure you can. The main texture's UV matrix is not used in the new shaders. You will want to add TRANSFORM_TEX in the vertex shader to where the texture coordinate gets assigned. Check to see how it differs with the old version.

sebas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: UIPanel
« Reply #13 on: April 15, 2014, 06:16:40 AM »
stupid question: when you say scale I assume you mean UIPanel.transform.scale. Is this the official way to change the scaling of a panel?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPanel
« Reply #14 on: April 15, 2014, 10:14:07 AM »
There is no transform.scale in Unity. Lossy scale, yes.