Author Topic: Add several UILabels through code for another camera?  (Read 2956 times)

steinhot

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Add several UILabels through code for another camera?
« on: June 23, 2012, 08:38:06 PM »
I need to add UILabels only through code for a variety of cameras in C#. 

I'm very familiar with C# and creating controls on the fly, but I have a lot of render textures that I need to add labels to and I don't want to do it through the UI designer.

Honestly this is the only reason I brought NGUI is to create these labels, however, I'm sure I will leverage it for other things using the designer.

However, I add a camera dynamically, set it to focus on a layer, and am already turning it into a RenderTexture.  All is good.  Now I want to dynamically add a series of UILabels and position them on the created camera so the text renders in the RenderTexture.

Can someone help me briefly explain the process?  What is the minimum NGUI controls I need to add labels to a camera.

Thank you!


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Add several UILabels through code for another camera?
« Reply #1 on: June 24, 2012, 12:21:37 AM »
All you need to draw text is a UILabel script attached to an object that has a parent. As long as this label has a font specified, it'll work. It will create a UIPanel automatically.

It won't receive events unless you also add a UICamera script to the camera that draws it.

My suggestion -- don't do it this way. Create prefabs instead -- prefabs of what your UI components will look like. You can then instantiate these prefabs and change their contents (for example changing the UITexture within the instantiated prefab). Helluva lot easier.

steinhot

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Add several UILabels through code for another camera?
« Reply #2 on: June 24, 2012, 04:01:44 PM »
Thank you very much!  Got it working.  In the end, I need to add panels too as I needed to move them to multiple cameras and it was giving me a message saying that "labels need to be in the same level as the panel" or something like that.

It was easier for me to generate them via code as I needed literally hundreds of them placed by math across many cameras.