playMaker

Author Topic: How to use PlaymakerFSM/SendEvent for NGUI button click?  (Read 1554 times)

xtr33me

  • Playmaker Newbie
  • *
  • Posts: 9
How to use PlaymakerFSM/SendEvent for NGUI button click?
« on: March 04, 2019, 12:00:17 PM »
I'm using playmaker 1.9 and have an NGUI button with which I am trying to set the OnClick event for. I have my global playmaker states in my GameManager GameObject and when I drag the GameManager into the Notify property for the button OnClick I then proceed to select PlayMakerFSM/SendEvent. Now I thought I would then be able to send a string representing the event I wanted to call, but it asks for an Object Arg0. 

Any ideas on what I'm missing here?  I am going to see about doing this in code now as perhaps that is the only way to do this, but I just found it bizarre that I couldn't send the event name and would like to know if it is at all possible. 

Thanks!

Deek

  • Full Member
  • ***
  • Posts: 133
Re: How to use PlaymakerFSM/SendEvent for NGUI button click?
« Reply #1 on: March 06, 2019, 03:12:45 PM »
I agree that NGUI's event handling isn't very well thought out.
For the purpose of sending events based on UIButton input I've created a script a long time ago which you can find in the attachments.
It allows for sending an event to a specific PlayMaker FSM on click, on press down and/or on press up and optionally sets the current GameObject in a variable of the FSM, so that you know which GameObject did send the event.

The GameObject this component is attached to needs a UIButton and Collider/Collider2D component set as trigger (you might need to adjust some parameters on the UICamera in your scene so that it registers event on Collider's instead of RigidBody's and set it to be a 2D UI Camera - or one of the other options, I don't accurately remember).

I haven't tested it in a while but it should still work, as it's just using the default MonoBehavior functions for registering click events, but which also works on UIButton's.

xtr33me

  • Playmaker Newbie
  • *
  • Posts: 9
Re: How to use PlaymakerFSM/SendEvent for NGUI button click?
« Reply #2 on: March 06, 2019, 04:08:35 PM »
Thanks so much for this Deek! I ended up just changing over to Unity buttons in game due to this, but I am interested in trying this out.  I found old posts where there seemed to be some prefabs in the past, but couldnt find anything for the newer version.  Thanks for the help!