Author Topic: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?  (Read 5131 times)

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
« 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

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
« Reply #1 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. }



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
« Reply #2 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.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
« Reply #3 on: December 28, 2014, 11:24:27 AM »
how about use of transform.GetSiblingIndex() ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
« Reply #4 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.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
« Reply #5 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.




yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: NGUI's UIPanel depth sorting by Transform Hierarchy like uGUI?
« Reply #6 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])