Author Topic: add item in runtime  (Read 5790 times)

rastinrasini

  • Guest
add item in runtime
« on: May 25, 2012, 07:47:00 AM »
hi all
if have many items and want to add they to an panel in runtime in button mode then in click of anyone it send name of button.
how can do this?
thankful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: add item in runtime
« Reply #1 on: May 25, 2012, 10:22:03 AM »
Use UIButtonMessage, it passes its game object as the parameter.

rastinrasini

  • Guest
Re: add item in runtime
« Reply #2 on: May 25, 2012, 10:54:47 AM »
How?
can add an example?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: add item in runtime
« Reply #3 on: May 25, 2012, 10:56:25 AM »
Example of what? Attach UIButtonMessage to your button, set its event listener and the function it will call on the event listener, and that's it. When you click it, the function will be called.

rastinrasini

  • Guest
Re: add item in runtime
« Reply #4 on: May 26, 2012, 02:17:58 AM »
Hi All
i have many icons in a folder in resources.
i want to add they in a panel in runtime?
for example:
Add 25 button with 25 Icon in Resources/Icons and when each of then is clicked print its order in panel.
how can do this?
Thankful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: add item in runtime
« Reply #5 on: May 26, 2012, 11:23:00 AM »
If they are not in an atlas, use UITexture to draw them.

rastinrasini

  • Guest
Re: add item in runtime
« Reply #6 on: May 28, 2012, 08:32:41 AM »
hi all
in unity gui we coding :
for (int i = 9; i < 18; i++) {
            if(GUI.Button(new Rect( 50*(i-3),
                                   14,50,50),
                          new GUIContent(Resources.Load(SpellTexturePath+i.ToString())as Texture2D)))            
            {
               if(_playerCombat._isReady)
                  _playerCombat.ShootArrow(i);
               else
                  _playerCombat.RangeAttack(i);
            }
         }

i want similor code in when i want use ngui.
how can i implement code above with ngui?

thankful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: add item in runtime
« Reply #7 on: May 28, 2012, 12:48:22 PM »
All I can suggest is read the written tutorials and watch the tutorial videos in order to learn how NGUI works first. You will have a lot of trouble converting OnGUI code to NGUI. They are completely different systems.