Author Topic: What's the best practice to control HUD's depth?  (Read 5598 times)

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
What's the best practice to control HUD's depth?
« on: May 02, 2014, 10:51:16 PM »
Hi, I have a prefab like below and there're about 10 HUD in my scene.
HUD
   |--BoxFrame(sprite)
   |--Sprite
   |--Label

I want to control their depth, make every HUD overlap correctly.
My work around is set every sprites depth as queue in script, it works but seems not a good practice.
What's the best practice?
First comes to my mind is UIPanel for each HUD. It works good but extra draw-call is heavy.
Then I noticed the old-style HUD.transform.z, and it seems not working anymore.
I also tried put a UIWidget on HUD hoping depth can work like UIPanel, no luck.

Any idea?
Thank you!
« Last Edit: May 03, 2014, 10:45:37 AM by alexlange »

LightSky

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 56
    • View Profile
Re: What's the best practice to control HUD's depth?
« Reply #1 on: May 04, 2014, 02:17:24 AM »
I don't see a problem with just setting their depth when you create it.  That seems like the most efficient way of going about it,  I have had much success doing it this way for my mobile games.    Creating a new UIPanel for each is a big no no since the draw calls will start to add up quickly depending on how many popups are going on, it would destroy FPS on mobiles.

Everytime you make a new popup just set it like:    (Reference to the HUDText Sprite/Text).depth = DrawCallQueue();

You could just toss this in a static class for global reference.
  1. int mDrawCall = 0; //Start  Depth Value
  2.  
  3. public int DrawCallQueue
  4. {
  5.    get
  6.    {
  7.        mDrawcall++;
  8.        return mDrawCall;
  9.    }
  10. }
  11.  

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: What's the best practice to control HUD's depth?
« Reply #2 on: May 04, 2014, 08:06:27 AM »
I don't see a problem with just setting their depth when you create it.  That seems like the most efficient way of going about it,  I have had much success doing it this way for my mobile games.    Creating a new UIPanel for each is a big no no since the draw calls will start to add up quickly depending on how many popups are going on, it would destroy FPS on mobiles.

Everytime you make a new popup just set it like:    (Reference to the HUDText Sprite/Text).depth = DrawCallQueue();

You could just toss this in a static class for global reference.
  1. int mDrawCall = 0; //Start  Depth Value
  2.  
  3. public int DrawCallQueue
  4. {
  5.    get
  6.    {
  7.        mDrawcall++;
  8.        return mDrawCall;
  9.    }
  10. }
  11.  

Yes, that's exactly what I did, just wondering if there's some container can do it directly.
Thank you :)