Author Topic: How add new widget during runtime?  (Read 9284 times)

jongsan83

  • Guest
How add new widget during runtime?
« on: April 17, 2012, 04:32:51 AM »
I want add widget during runtime by scripting.

How add new widget by scripting?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How add new widget during runtime?
« Reply #1 on: April 17, 2012, 04:35:11 AM »
  1. UISprite newSprite = NGUITools.AddWidget<UISprite>(parentGameObject);

jongsan83

  • Guest
Re: How add new widget during runtime?
« Reply #2 on: April 17, 2012, 05:05:59 AM »
I want add button, add checkbox, set atlas, etc... by scripting.

I tried find example, but nothing.

If you know site that contains example, write site address plz.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How add new widget during runtime?
« Reply #3 on: April 17, 2012, 05:14:01 AM »
Look inside UICreateWidgetWizard. Every single widget added via the Create Widget Tool is created via code, and it's all inside that file.

jongsan83

  • Guest
Re: How add new widget during runtime?
« Reply #4 on: April 17, 2012, 05:42:02 AM »
Aha! Thanks!

alics

  • Guest
Re: How add new widget during runtime?
« Reply #5 on: February 06, 2013, 12:26:48 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: How add new widget during runtime?
« Reply #6 on: February 06, 2013, 10:14:25 PM »
It's an editor script, so you wouldn't be able to call its functions at run-time. I highly suggest you not even trying to. Simply create a prefab out of an ideal item (for example create a single row in a table, then save it as a prefab). Then when you instantiate this prefab using NGUITools.AddChild, just change its values. It's hell of a lot easier than adding widgets by code.

However... if you do insist on adding things via code -- just copy/paste logic from inside that script. You will need to translate it from C# to Javascript though.