Playmaker Forum

PlayMaker Help & Tips => PlayMaker Tips & Tricks => Topic started by: KrzysztofZuk on October 21, 2014, 06:32:30 AM

Title: Playmaker & iGui integration - activate/deactivate button
Post by: KrzysztofZuk on October 21, 2014, 06:32:30 AM
Hello, I  tryed to create simple mute/unmute music system with iGui and Playmaker.

I Created Two buttons on the same location:
- Music is on press to turn off (button1)
- Music is off press to turn on (button2)

So when you press one button it will make some "mute" actions , deactivate byself and activate second button.

But I had problems with activate/deactivate iGui buttons by using Playmaker.

I tryed to call event and use Set Propery action to enable/disable button:

(http://beenek.webd.pl/pforum/Enable1.jpg)

But this don't work. It's should toogle On/Off "Enable" box but when I used that, it's only  enabled/disabled iGuiButton script :(.

When it's disabled iGuiButton script, the button is still visibile...
Even if i disable whole Button 1 object  in Hierarhy it's still visible...
I tryed to give button Layer and disable  this layer in camera culling mask, but guess - button is still visible... iGui is very funny with this problem...

So I created playmaker system that by pressing  button it will change opacity, passive and order states for both buttons.

First you must to create a two buttons by using iGui.
After that  in the inspector,  check Passive box to true, set opacity to 0, and set order to 0 for button 2:

(http://beenek.webd.pl/pforum/disable_button.jpg)

It will "disable" this button on the start:).

For the button 1 set "order" value to 1.

After that you must enter code into iGui Root Script -  that will call events
( I wrote "//add this" too mark, where I put new code:)

Code: [Select]
using UnityEngine;
using System.Collections;
using iGUI;
using HutongGames.PlayMaker;  //add this

public class iGUICode_PlayMakerPlusIgui : MonoBehaviour{
[HideInInspector]
public iGUIButton button2;
[HideInInspector]
public iGUIButton button1;
[HideInInspector]
public iGUIPanel panel1;
[HideInInspector]
public iGUIRoot root1;

public PlayMakerFSM behavior; //add this



static iGUICode_PlayMakerPlusIgui instance;
void Awake(){
instance=this;
}
public static iGUICode_PlayMakerPlusIgui getInstance(){
return instance;
}

public void button1_Click(iGUIButton caller){


behavior.Fsm.Event("TurnOffButton1TurnOnButton2Event"); //add this

}

public void button2_Click(iGUIButton caller){
behavior.Fsm.Event("TurnOffButton2TurnOnButton1Event"); //add this
}

}

After inserted that codes to the iGui Root script you must move object with playmaker actions to the iGui Root, Behavior area:

(http://beenek.webd.pl/pforum/move_obj.jpg)

Ok, now I will show you what I have made in playmaker:

(http://beenek.webd.pl/pforum/playmakertree.jpg)

So if you press button 1 it will call "TurnOffButton1TurnOnButton2Event"
If you press button 2 it will call TurnOffButton2TurnOnButton1Event"

Those both events are global events.

"Wait for global event" is empty.

Init and Init2 events:

(http://beenek.webd.pl/pforum/init_event.jpg)

Turning On Button 2 Event:

(http://beenek.webd.pl/pforum/TurnOnButton2event.jpg)

Remember to put into Set Property action in "Target object" area not a Button object but "IGUIButton" component:

(http://beenek.webd.pl/pforum/iguicomponent_ok.jpg)

Turning Off Button 1 Event:

(http://beenek.webd.pl/pforum/TurningOffbutton1.jpg)


Turning On Button 1 Event:

(http://beenek.webd.pl/pforum/turning_on_button_1.jpg)

Turning Off Button 2 Event:

(http://beenek.webd.pl/pforum/turning_off_button_2.jpg)

"Wait for global event" and "Wait for global event 2" are empty events.

Mayby it will be useful for somebody :)

Cheers!