Author Topic: sending input to other classes  (Read 3839 times)

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
sending input to other classes
« on: May 10, 2013, 10:01:42 PM »
Pardon me if this topic has been covered well in this forum; I am a new member although I purchased NGUI 10 months ago. It's so overwhelming to switch from the OnGUI functions that I have created throughout my game project. I have a lot of functionality that is built in to my project which relies on lots of input from the GUI.

I want to switch my entire project to NGUI and remove all of Untiy's Native GUI. I don't quite understand the information flow. If I have 3 input labels and a button, how can I link that button to send the information from the labels to another place. I used to have it so that the OnGUI functions had references to other objects which would interperet the data. Is this the best way with NGUI? I'm seeing all kinds of function delegates and message sending that I don't really understand. Any help is greatly appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: sending input to other classes
« Reply #1 on: May 11, 2013, 12:55:58 AM »
I recommend writing a manager script sitting somewhere that will reference your controller types (buttons, inputs, etc). In its Start() function you can subscribe to events from those controllers. For example, to listen to OnClick, simply do this:

UIEventListener.Get(buttonGameObject).onClick = YourClickFunction;

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: sending input to other classes
« Reply #2 on: May 11, 2013, 01:10:51 PM »
Would I be able to use this manager to handle multiple buttons? It sounds like I should create a large input manager type of class that handles of the input from the game.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: sending input to other classes
« Reply #3 on: May 12, 2013, 12:59:33 PM »
I recommend keeping small managers for specific tasks, generally on a per-window basis. For example, a manager for the Options window that references buttons, popup lists and sliders within.