Author Topic: need to script a FW BW button  (Read 4903 times)

Dennis_N

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
need to script a FW BW button
« on: January 23, 2014, 04:26:29 PM »
Hi there.
Just picking my way through NGUI here. My experience with C# is next to nill.
I have a few textures that I want to browse through the use of two buttons that go backward and forward.
I have no idea how to achieve this, other than theoretically.
For example there needs to be a page counter var, that goes +1 with one button and -1 with the other.
Then depending on the var value, the alpha of the specific numbered texture goes from 0 to 1.
However as I said, I'm not familiar with C# and I don't know how to connect things.

Please help. Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: need to script a FW BW button
« Reply #1 on: January 24, 2014, 10:30:58 AM »
I wouldn't even know where to begin to answer something like this, in part because I don't understand what you're trying to do. What does "a few textures that I want to browse through the use of two buttons that go backward and forward" mean?

If you're not familiar with C#, you can always use javascript.

Dennis_N

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: need to script a FW BW button
« Reply #2 on: January 24, 2014, 06:29:51 PM »
By textures I mean some images to flip through like a slideshow, and a couple of buttons to go back and forth. Pretty simple. They could go in and out of view, or fade in and out. I thought a simple fade in out would work nice.

I figured I need to use UIEventListener to listen to the buttons but I'm not familiar with the whole delegate concept at this point. I was going through the example scenes but I couldn't find a single connection example between an eventlistener and the objects it listens to. But maybe I was looking at the wrong places.
I'm pretty sure its simple, but when someone explains something to me in phrases that I understand 1 out of 5 words, then I need to take a step back and learn what those other 4 words mean first! Any help is much appreciated.

Dennis_N

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: need to script a FW BW button
« Reply #3 on: January 24, 2014, 09:41:16 PM »
Ok after many minutes trying random stuff I made it work. It can listen to a click a button makes.
next question would be
if I have this line:
UIEventListener.Get(mybutton).onClick += doThis;

do I have to repeat it for all the target buttons that I assign to that script? or is there a way to handle them all through one line of code?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: need to script a FW BW button
« Reply #4 on: January 24, 2014, 10:23:20 PM »
UIEventListener lets you subscribe to events on a remote object and trigger a local delegate when an event occurs. You can handle this event in a script directly attached to that object instead. In either case if you want many events to come to the same place, then yes, UIEventListener is the best approach.

Also... keep in mind that UIButton script has the "on click" event notification field you can set in inspector. So you can do this visually instead of having to write code.