Author Topic: Scroll View and Depth?  (Read 6689 times)

vi1e8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Scroll View and Depth?
« on: February 04, 2015, 12:47:06 AM »
Sorry if this has been asked and answered before, I've looked everywhere for a solution with no luck!

Simply put I have the following:

>UIRoot
      >Widget A -with (UIWidget, UIDragDropRoot, UIDragDropConatiner, Collider)
            >UIPanel -with(UIPanel, UIScrollView)
                >UIGrid -with(UIGrid)
      >Widget B -with (UIWidget, UIDragDropRoot, UIDragDropConatiner, Collider)
            >UIPanel -with(UIPanel, UIScrollView)
                >UIGrid -with(UIGrid)
      >Sprite1 -with(Collider, UIDragDropItem)
      >Sprite2 -with(Collider, UIDragDropItem)
      >Sprite3 -with(Collider, UIDragDropItem)
      >Sprite4 -with(Collider, UIDragDropItem)

The Sprites get parented into one of the grids at runtime.  By design there is some slight overlap within the grid of these sprites.  I can set the sprite depth and get the expected results of which sprite is on top through code or the inspector.  At this point drag and drop and everything works as it should.  BUT, the minute I drag and drop the first item from one container to the other, UISprite.depth has no effect.  So once a drag and drop is made, I can set the depth, and it shows in the inspector as the correct value, but visually in the panel there is no effect on depth.  So before a drag and drop is made, Sprite1 at depth 5 is displayed higher than Sprite2 at depth 4 and can be switched by changing the depth value, as expected, but after a drag and drop, it appears to be random, similar in effect to having all sprites at the same depth, regardless of the actual depth setting.  Changing the depth value has no effect.

Am I just missing something right under my nose?

Thanks in advance!






StabbAmonte

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 7
    • View Profile
Re: Scroll View and Depth?
« Reply #1 on: February 04, 2015, 01:29:46 AM »
You say that the Sprite objects are parented to the Grid at run-time and from looking at that hierarchy each Grid is on a different panel.  The way nGUI rendering works is that each Panel is rendered completely based on the Panel Depth so all objects (Widgets, Sprites, etc.) on a Panel are rendered before the next Panel.

>Panel 1 (depth 1)
     > Sprite A (depth 100)
     > Sprite B (depth 101)
     > Sprite C (depth 102)
>Panel 2 (depth 2)
     > Sprite D (depth 10)
     > Sprite E (depth 11)
     > Sprite F (depth 12)

Even though Sprite D, E and F have a lower Depth than Sprites A, B and C the Sprites A, B and C will be rendered first because they are on a Panel with a lower Depth. Basically EVERYTHING on Panel 1 is rendered before ANYTHING on Panel 2.

You also said that when you drag and drop the Sprites the order gets messed up and looking at your hierarchy your DragDropContainers and not children of the Paneld they are children of the Root. I think that you need to make some changes to your hierarchy to get the rendering in the correct order.

Hope that helps.


vi1e8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Scroll View and Depth?
« Reply #2 on: February 04, 2015, 10:58:07 AM »
I should have clarified this better i guess, but when I say that depth is not working after a drag and drop, and I am referring to the sprites within the same grid.  So prior to a drag and drop, depth effects the sprites parented on the same grid, but after a drag and drop, depth has no effect on the items within the same grid.  This holds true regardless of where I place my DragDropContainers.

vi1e8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Scroll View and Depth?
« Reply #3 on: February 04, 2015, 03:05:40 PM »
As an update to this, the loss of depth control only effects the sprite that was Drag and Dropped.  One a sprite gets dragged, even if it is dropped back into the same grid, adjusting sprite.depth has no effect, but I can still get the other "unDragged" sprites to respond to depth setting.

vi1e8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Scroll View and Depth?
« Reply #4 on: February 04, 2015, 03:41:55 PM »
Solved:

For anyone else experience this, it was something right under my nose.  When I re-parented the sprites at run-time, I used:

  1. sprite1.transform.parent = Grid.transform;

but failed to also use:

  1. NGUITools.MarkParentAsChanged(Grid);

Once I added that after re-parenting, everything appears to be golden.  Lesson learned is to call that method when re-parenting under NGUI!