Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: yuewah on December 20, 2014, 10:36:01 AM

Title: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
Post by: yuewah on December 20, 2014, 10:36:01 AM
Any plan to add feature of NGUI UIPanel depth sorting by Transform Hierarchy ?

I have tried to modify the UIPanel.cs

static public int CompareFunc (UIPanel a, UIPanel b)

Maybe it is possible to sort the UIPanel by its Transform Hierarchy Depth and SiblingIndex
Title: Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
Post by: yuewah on December 24, 2014, 11:34:56 AM
Actually, when traverse the transform hierarchy tree using GetComponentsInChildren, it returns an array of UIPanel with the same sort order as uGUI. It would be easier than using UIPanel.depth

  1. foreach ( UIPanel panel in this.transform.root.GetComponentsInChildren<UIPanel>() )
  2. {
  3.      Debug.Log( panel );
  4. }


Title: Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
Post by: ArenMook on December 27, 2014, 09:22:50 AM
GetComponentsInChildren is very expensive, and allocates an array every time you call it. Doing it in a foreach is even worse. So no, no plans right now.
Title: Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
Post by: yuewah on December 28, 2014, 11:24:27 AM
how about use of transform.GetSiblingIndex() ?
Title: Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
Post by: ArenMook on December 28, 2014, 12:00:44 PM
GetSiblingIndex isn't cumulative. For example you'd end up with these values:

Panel
- Widget 0
-- Widget 0
-- Widget 1
--- Widget 0

And in any case, what would be the point? Explicit depth gives you control of exactly what you want to do. It's more powerful.

Furthermore going down the transform-based route, how would you know if the transform was moved in the hierarchy? If there is a notification for that in C#, I am not aware of it.
Title: Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
Post by: yuewah on December 29, 2014, 01:38:56 AM
you are right. Unless unity expose more event or property. What I want is making transition from NGUI to uGUI more smoothly.



Title: Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
Post by: yuewah on December 29, 2014, 02:14:52 AM
each View prefab contains more than one UIPanel, when I insert a new ViewC between ViewB and ViewD, all UIPanel depth need to be updated as follows, the easier method is traverse the hierarchy in order.

ViewA (PanelA [depth = 0], PanelB [depth = 1])
ViewB (PanelC [depth = 0], PanelD [depth = 1])
ViewC (PanelE [depth = 0], PanelF [depth = 1])
ViewD (PanelG [depth = 0], PanelH [depth = 1])

step 1:
ViewA   (PanelA [depth = 1], PanelB [depth = 2])
|-ViewB (PanelC [depth = 3], PanelD [depth = 4])
|-ViewD (PanelG [depth = 5], PanelH [depth = 6])

step 2:
ViewA   (PanelA [depth = 1], PanelB [depth = 2])
|-ViewB (PanelC [depth = 3], PanelD [depth = 4])
|-ViewC (PanelE [depth = 5], PanelF [depth = 6])
|-ViewD (PanelG [depth = 7], PanelH [depth = 8])