Author Topic: UISprite and UILabel in 3D with Z transform positioning  (Read 6117 times)

playemgames

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
    • Play-Em
UISprite and UILabel in 3D with Z transform positioning
« on: May 08, 2014, 08:36:26 PM »
I've recently finally migrated over to 3.5.8 from 2.7 (been using NGUI for a while now but had a lot of code hooked into it) so I have almost all the issues tackled except one.  I have a speech bubble for each character with some text, and I add their speech bubbles to a panel root object and had the objects sorted by z position on the transform.  So my set up is like this:

UIPanel (Panel Root Object)
--UISprite (Speech Bubble)
--UILabel (Speech Bubble Text)

I had read that this no longer works in 3.0 + and you have to use Explicit Render Queue 3000 in the UIPanel to get it to use z positioning.  I do this because the characters move in 3D space and I want the speech bubbles to move with the character, so I update their transforms along with the characters position.  However when I do this the most recently added speech bubble always appears in front even though the z position is further away.  It moves and zooms properly but it seems like the sorting doesn't get refreshed when new speech bubble objects are added.  The new objects always appear in front and ignores the z transform positioning.  Is there any way around this?  I seem to be stumped on this one.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprite and UILabel in 3D with Z transform positioning
« Reply #1 on: May 09, 2014, 05:43:10 AM »
No need to use explicit render queues. Everything is sorted first by camera depth, then by panel depth, then by widget depth. This means that instead of adjusting Z, you should be adjusting panel depth to bring things in the order you want them to be in. Z isn't used at all in this case.

playemgames

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
    • Play-Em
Re: UISprite and UILabel in 3D with Z transform positioning
« Reply #2 on: May 09, 2014, 08:20:33 AM »
I have multiple speech bubbles per panel so I would save on the draw calls.  How would I manage the z depth with the characters moving in and out of 3D space?  The speech bubbles follow over the characters head in 3D space so the z positioning was easier to see what was in front  and what was in back.  So is there no way to get them to move in 3D space like in 2.7?  Or is there another way to get them to position against each other using the panel/widget depth against the transform z positioning?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprite and UILabel in 3D with Z transform positioning
« Reply #3 on: May 09, 2014, 09:23:17 PM »
Write a script that would set the depth based on the distance from the camera to the target, and you solve the problem neatly.

You can get 2.7 like behaviour back, but then you have to manage Z for everything, and you have to have multiple panels -- one per speech bubble. So your drawcall saving won't work as each panel is a new set of draw calls.

playemgames

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
    • Play-Em
Re: UISprite and UILabel in 3D with Z transform positioning
« Reply #4 on: May 09, 2014, 11:47:17 PM »
Sounds like writing a script on the panel to manage the widget depth would be the best idea.  I imagine keeping a list or an array of all the panel widgets and adjusting the depth according to the distance for each to the camera would be the best way.  Thanks so much for your help!