Author Topic: Create UI "on-the-fly" (programmatically)  (Read 8808 times)

frarees

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Create UI "on-the-fly" (programmatically)
« on: November 22, 2012, 04:17:12 PM »
Hi,

Is there any way to create a full GUI just from code? Every time I need to create a GUI have to do it with the UI Wizard, and I'd like to know if dynamically generating the UI is possible/factible.

Thanks!

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Create UI "on-the-fly" (programmatically)
« Reply #1 on: November 22, 2012, 06:00:35 PM »
Of course.  You'd just create gameobjects in a hierarchy and attach the script components in proper sequence.  You can set all of the component variables and settings via code, too.

Caveat:  Aren might correct the statements above if there is some under the hood magic that I'm not aware of.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Create UI "on-the-fly" (programmatically)
« Reply #2 on: November 22, 2012, 11:00:17 PM »
Just look at the code of the UICreateWidgetWizard. All these widgets you're creating via the menu are created programmatically, and the code is available for you to examine, just like the rest of NGUI.

Echo

  • Guest
Re: Create UI "on-the-fly" (programmatically)
« Reply #3 on: November 23, 2012, 10:41:47 PM »
You can also instantiate a prefab containing the GUI to the correct panel. You might need to do some code scaling though.

alics

  • Guest
Re: Create UI "on-the-fly" (programmatically)
« Reply #4 on: February 06, 2013, 12:27:41 PM »
Is there a way to add widgets during runtime using Javascript?

UICreateWidgetWizard is in C#

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Create UI "on-the-fly" (programmatically)
« Reply #5 on: February 06, 2013, 10:15:56 PM »
I answered you in the other thread. No need to ask twice.