Author Topic: Using UISPrites outside UIRoot  (Read 2106 times)

caldofran

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Using UISPrites outside UIRoot
« on: August 06, 2014, 04:15:56 AM »
Hi,

I'm trying to develop a trading card game, and to make the card sprites i'm using some Atlases and NGUI classes to try to decrease draw calls.

To make easier the use of particle system, and make a 3d world appearence (i'm also using NGUI classes in the GUI), i'm trying to put the card prefabs outside of UIRoot gameobject.
I've done this without any problem, but the draw calls have increased drastically from 6-8 draw calls to 75-80 (each card uses the same 4-5 different atlases, two of them with transparency, so the draw calls must be in 12-14)
Maybe i'm missunderstanding the behaviour of the UISprite or the atlases caching (to avoid re-draws)... but i'm thinking the UISprite class doesn't handle correctly the atlases when is used outside the UI Root.
Is there an easy workaround or explanation to this behaviour?

Thank you folks!

caldofran

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Using UISPrites outside UIRoot
« Reply #1 on: August 06, 2014, 03:26:24 PM »
Ok, i think i've done myself  ;D

To make the UISprites available outside the UIRoot, i created an UIPanel inside the card prefab which contains all the UISprites (and some UILabels too).

This was the workaround to avoid creating automatically few instances of UIRoot (a behaviour of the NGUI editor code, to make our life easier  8)), and was the origin of my headache... what i've done is only add an empty gameobject with an UIPanel and a rigidbody and remove the panel from the prefab. Then when creating the instances with the prefab i simply add the prefabs to the new gameobject as children.

I still don't pretty understand why this worked, but i think each individual panel manages the atlases caches...



zentuit

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Using UISPrites outside UIRoot
« Reply #2 on: August 06, 2014, 03:38:17 PM »
Hi Caldofran,
That's not a workaround, that's the way you do it  ;D

You can put any UIWidget under a UIPanel that's anywhere in your hierarchy. (If you look at UIRoot, you'll see that it has a UIPanel component also.)

For my latest project (that's sitting at Apple waiting review), I have one UIPanel that holds the NGUI health indicator sprites for the 3d models. (the 3d models update their respective health sprite's transform so the sprite travels with them. The health sprites are rendered by the main camera (perspective) and not the HUD camera



caldofran

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Using UISPrites outside UIRoot
« Reply #3 on: August 07, 2014, 01:57:52 AM »
Yep Zentuit, that's the way  8), what i still wondering is how the UIPanel caches all the textures to decrease draw calls... NGUI code is two much complicated for me...  :o


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UISPrites outside UIRoot
« Reply #4 on: August 07, 2014, 03:49:54 AM »
UIPanel simply collects widgets underneath it. It's basically a mesh renderer.