Author Topic: Spawning UILabels into one global UIPanel?  (Read 4220 times)

Vicas

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 8
    • View Profile
Spawning UILabels into one global UIPanel?
« on: August 12, 2014, 07:29:09 AM »
I have a game that upon load spawns a whole range of PreFabs that all holds different UILabels.

Right now, each of these have their own UILabel, since this is added automatically by NGUI, when I add a UILabel to a simple GameObject that is going to become a PreFab to be used.

So how do I work with small simple GameObjects that only needs a UILabel, without a UIPanel being created? And is it possible at all?

If you look at this screenshot:
http://grab.by/zo5Q

"CatapultGameStone" is being spawned about 40 times inside "CatapultGameScene" in an array of "stones" that each contains a value using UILabel. This causes 40 draw calls!

So I just want to add one UIPanel to "CatapultGameScene" and spawn only UILabels on the "CatapultGameStone".

How do I do that?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Spawning UILabels into one global UIPanel?
« Reply #1 on: August 12, 2014, 07:31:57 AM »
Widgets cannot exist without a managing panel. Think of widgets as meshes, and panels as renderers. You can't see a mesh. You can only see renderers.

Vicas

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Spawning UILabels into one global UIPanel?
« Reply #2 on: August 20, 2014, 01:12:45 AM »
But they would exist with a Panel, just first when they are actually spawned. Can this not be done? Doesn't this highly affect the modularity of one's workflow, if you cannot separate GameObjects into prefabs as much as you want?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Spawning UILabels into one global UIPanel?
« Reply #3 on: August 20, 2014, 03:25:26 PM »
You can do it just fine, provided you use NGUITools.AddChild to create it, adding it directly to the panel's hierarchy. If you use Object.Instantiate, you are likely to run into an issue where you'll be modifying a widget before its parent has been set, thus causing it to create a new panel.