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
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:
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.