playMaker

Author Topic: Sending an event back to Playmaker from NGUI?[SOLVED]  (Read 4678 times)

redmotion

  • Playmaker Newbie
  • *
  • Posts: 8
  • Independent game developer using Unity and ShiVa
    • redmotion.com
Sending an event back to Playmaker from NGUI?[SOLVED]
« on: September 28, 2013, 07:37:32 PM »
How is this done?

I have two buttons on my NGUI ui.

I have installed the package from here and done steps 1-4 setting ONCLICK
https://hutonggames.fogbugz.com/default.asp?W1111

Now, I can't work out what I need to do to get the buttons sending events back to Playmaker? Do I need to add a script to each button or is it something simpler?

(NGUI using 2.7.0 - the package has errors with 3.)

Thanks.
« Last Edit: October 01, 2013, 03:17:28 AM by jeanfabre »

redmotion

  • Playmaker Newbie
  • *
  • Posts: 8
  • Independent game developer using Unity and ShiVa
    • redmotion.com
Re: Sending an event back to Playmaker from NGUI?
« Reply #1 on: September 29, 2013, 06:14:01 AM »
So, to get this working I've gone for complete spaghetti...

I got rid all the scripts I'm supposed to use (which seem to have no comprehensive documentation or forum discussions to learn from) and instead:-

Added an empty gameobject to the scene called"ButtonReceiver" with this script:-
Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;

public class GetButtonMessage : MonoBehaviour {

public PlayMakerFSM the_fsm;

void Start () {

}

void Update () {

}

void ButtonMessageRecieveLeft () {
the_fsm.Fsm.Event("LeftButtonPressed");
}

void ButtonMessageRecieveRight () {
the_fsm.Fsm.Event("RightButtonPressed");
}
}

On the NGUI buttons I'm using called "Left" and "Right", I added standard script "UIButtonMessage"  which targets the "ButtonReceiver" Gameobject and the respective functions (above) called "ButtonMessageRecieveLeft" and "ButtonMessageRecieveRight".

Of course, I then have to drag my Fsm object into the public variable "the_fsm".

So, Is there a way to attach the GetButtonMessage directly to the FSM object and automatically reference the FSM rather than having to use a public variable to make the connection?

(I'm basically not sure of the Csharp syntax to reference the FSM attached to the same object as the script)

PS: I'm happy to revert back to the "correct" way, if someone can explain how it all goes together!

Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending an event back to Playmaker from NGUI?
« Reply #2 on: September 30, 2013, 01:45:56 AM »
Hi,

 Have you followed the instructions provided on that ngui wiki page? are you able to make that work?

 Thanks for the info on ngui update that breaks things, I'll check it out.

bye,

 JEan

redmotion

  • Playmaker Newbie
  • *
  • Posts: 8
  • Independent game developer using Unity and ShiVa
    • redmotion.com
Re: Sending an event back to Playmaker from NGUI?
« Reply #3 on: September 30, 2013, 02:49:40 AM »
Cannot find any info on the NGUI site. Just this entry here:

https://hutonggames.fogbugz.com/default.asp?W1111

But this seems to stop just when more detail is needed on how to read NGUI events.

Any chance of a link on the NGUI site?

Thanks
« Last Edit: September 30, 2013, 03:06:54 AM by redmotion »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending an event back to Playmaker from NGUI?
« Reply #4 on: September 30, 2013, 04:47:44 AM »
Hi

 It's not on the gui site, it's on that wiki page:

Listening to NGUI Events

1: Drag the "NGUI PlayMaker Proxy" prefab into your scene. It will make available a set of global events "NGUI / XXX"

1: In your GameObject target where you want to listen to nGui events, add the "NGuiEventsToPlaymakerFsmEvents" script

3: Set the "NGuiEventsToPlaymakerFsmEvents" component to target the fsm of your choice ( it will pick the first one attached if it finds one)

4: In the Fsm, add the ngui global event you want from the context menu. for example "NGUI / ON SUBMIT", and NGuiEventsToPlaymakerFsmEvents component will turn the submit event green so you know it's properly set up on that front.


Have you done that?

Also, have you studied the examples provided? it's downloadable on that wiki page too.

Bye,

 Jean

redmotion

  • Playmaker Newbie
  • *
  • Posts: 8
  • Independent game developer using Unity and ShiVa
    • redmotion.com
Re: Sending an event back to Playmaker from NGUI?[SOLVED]
« Reply #5 on: September 30, 2013, 03:34:29 PM »
Hi Jean,

Ok I got it working the right way. What wasn't clear from the steps on the wiki is that the "gameobject target" is actually the NGUI item you want to read events from. I stuck the "NGuiEventsToPlaymakerFsmEvents" script and an FSM onto each button and added the onClick event to the states for each button and everything is working fine.

Cheers.
« Last Edit: October 01, 2013, 03:17:09 AM by jeanfabre »