playMaker

Author Topic: uGui + SoundManagerPro - mute/unMute Music System  (Read 5306 times)

KrzysztofZuk

  • Playmaker Newbie
  • *
  • Posts: 16
uGui + SoundManagerPro - mute/unMute Music System
« on: November 08, 2014, 10:22:07 AM »
Hello, I want to show you how to create mute / unmute music system by using playmaker, ugui component named "toggle" and soundmanagerpro.

So we want to create system that give us chance to mute and unmute music by using  "Is On" property.

That system suport (memory) gameprefs, so if you turn of music, close game, and run again, the music will be still turned off.

Ok, at first create uGui toggle component. Name it "Music is on". There are property "Is On" and this should be checked on.

After that create empty game object and name it "MusicOnOffManager".

Create state, put there "PlayerPrefs Set Int" and as a Key use: "MusicIsOnKeyInt"
as a value us 1. And turn on scene. After that MusicIsOnKeyInt key will have "1" value at start - it will be save in project. Our project at first time will have music on so we need to make MusicIsOnKeyInt value = 1. Now you can delete thise state.

After that, in "MusicOnOffManager" empty object create this:



This system will run only one time, when you turn on your game/apps.
It will check gamprefs history to make your last decision to mute/unmute music and toggle on/off cmomponent.

Get Player Prefs states:



State 1 States:



Turn on music state:



Turn off music state:



Ok, so if you turn on your game/app this system will check MusicIsOnKeyInt value. If MusicIsOnKeyInt Key  value = 0 - system will  mute music / toggle off "Is On" property. If MusicIsOnKeyInt  key value = 1 - system will unmute music and toggle on "Is On" property

Be carefull to put good element to the Target Object area:



Now It's time to download iGui actions from here:

http://hutonggames.com/playmakerforum/index.php?topic=8452.0

Ok, now in "Toggle" object - where is toggle component create these states:



Wait for user interaction state is empty.


State 1 states:



Turning on music state:



Turning off music state:


Remember, "GlobalEnetKZ" is a Global event and global transition.

Ok, so if user press toggle component , that toggle component will run on "GlobalEventKZ" state. If  Toggle box is empty and user  will press it - scirpt will turn on music. If toggle box is checked and user press it - script will turn of music .

Now It's time to make interaction between pressed toggle and "GlobalEnetKZ" event. To make it work create this script:

Code: [Select]
using UnityEngine;
using System.Collections;
using uUI = UnityEngine.UI;
using HutongGames.PlayMaker;

public class PlayMaker : MonoBehaviour {

public PlayMakerFSM behavior;

public void wykonajto()
{
behavior.Fsm.Event("GlobalEventKZ");
}




}

After that connect this script to the object with toggle component (on the same object are playmaker states with GlobalEventKZ global event) . After that move object with your toggle compotent to "Behavior" area:



Now object with your toggle component know where are playmaker
states.

Ok, now last thing. In the toggle component at bottom,  move "Toggle object" to the event box:



After that choose "Playmaker" (name of our maded script) and "wykonajto" function.
Now, everytime user use toggle, GlobalEventKZ global event will be called.

That's everything. Cheers!