Author Topic: OnClick for a 'Set of Controls', not just 1 per button  (Read 10030 times)

sean_microburst

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
OnClick for a 'Set of Controls', not just 1 per button
« on: May 06, 2014, 02:32:32 AM »
How can I create a Script than I can use for a "Set Of Controls".  I noticed that in OnClick you can get UICamera.currentTouchId.

Is there a way I can use that to create a 'Script' for a full Menu, instead of creating a script per button?

I am fairly new to NGUI, so this may just be a stupid question.

Thanks,
sean_microburst

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #1 on: May 06, 2014, 09:17:02 PM »
On Click notification on the buttons can trigger any remote function, so I am not quite sure what you're asking here. Are you asking about the OnClick event? The actual event is sent to a single object by NGUI. Button handles that event and triggers the On Click Notification. The notification can call any remote function, or even several functions as you see fit.

daybson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #2 on: May 23, 2014, 03:12:04 PM »
Same doubt here.

I have a window with several buttons.
I don't want to put one script in each button to implement his OnClick event.

What I want is to put ONE script at my Window (on top of hierarchy, with childrens buttons) and my buttons will doesn't have none script attached. At the Window script, I want to check which button was clicked and activate an method at my way.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #3 on: May 23, 2014, 05:31:08 PM »
You don't need to attach any scripts to use the built-in On Click notification on the UIButton.

daybson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #4 on: May 23, 2014, 07:11:52 PM »
Well, I'm missing something then.
Can you explain me how do I do this? Several buttons activating different functions without any script attached to they?
Or in my case, only one script in my window?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #5 on: May 23, 2014, 09:33:56 PM »
Select your button and examine the UIButton component. Do you see the On Click notification? Drag in your game object that has the script whos method you want to call. Now choose that method in the drop-down list.

daybson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #6 on: May 26, 2014, 07:46:25 AM »
Drag in your game object that has the script whos method you want to call. Now choose that method in the drop-down list.

I did not understand. Drag the method? Drag what to where? I'm using the 2.6.4 version, and I did not see this 'OnClick notification'.

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #7 on: May 26, 2014, 08:05:45 AM »
lol,

The version that you use is 1 year old ... you should upgrad your NGUI to the last version, but be careful ... ngui has been reworked since the 3.X.X version, you will have to migrate your work.
Graphicstream Dev.

daybson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #8 on: May 26, 2014, 08:10:34 AM »
I can not migrate without rewrite some classes at my project, and this will be very traumatic. For my needs, this version still works (I hope). I'm waiting to Unity 4.6 with the new GUI system, to analyse if will worth migrate to it.

devandart

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
    • devandart
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #9 on: May 26, 2014, 08:22:05 AM »
But what's easier?
Hacking around in a old NGUI version or migrating the latest version? Hm...

daybson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #10 on: May 26, 2014, 08:33:16 AM »
For now, it's easier usgin the old version. I have no time to migrate.  =/

daybson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: OnClick for a 'Set of Controls', not just 1 per button
« Reply #11 on: May 26, 2014, 12:55:57 PM »
Well, it's solved!  ;)

I Added a UICheckbox script to the button.
I created a ComponentManager script and I have attached it to a empty gameobject. This script contains the functions that I need to each button of my window. I used it as the the Eventreceiver on UICheckBoxand of a button and wrote the name of my desired method (implemented on my manager) for this button in the FunctionName field.