playMaker

Author Topic: Gui Advanced Button - String + Int + Audio  (Read 3157 times)

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Gui Advanced Button - String + Int + Audio
« on: January 15, 2013, 06:53:28 PM »
an advanced button Action that compounds several standard features into one button
removing the need for Transition states and a build up of actions as a work around, this fixes that potential mess by conforming them into one simple button

Enjoy  ;)
it could do with some improvements and fine tweaking but this is ready for release
if you do update it, let me know and post the code here


digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Gui Advanced Button - String + Int + Audio
« Reply #1 on: January 15, 2013, 06:56:41 PM »
my only qualm is that String Variable and Int Variable should be looking for variables by default, but I don't know the FSM type to set that
and I'd like some sort of 'break' between the audio section and the Button settings

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Gui Advanced Button - String + Int + Audio
« Reply #2 on: January 18, 2013, 08:04:25 PM »
Potential Bug/problem

after messing with it, it seems that i cant use the current audio setup because if you simply play a sound on the camera where the games music is from, it will replace the sound of the camera with the button sound and it would effectively stop the music

so I've removed the play Audio option until some sort of work around could be made so the button sounds can play without interrupting other sounds

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GUI)]
[Tooltip("GUI button. Sends an Event when pressed. Optionally store the button state in a Bool Variable.")]
public class GUIAdvancedButton : GUIContentAction
{
public FsmEvent sendEvent;
[UIHint(UIHint.Variable)]
public FsmBool storeButtonState;
//
[ActionSection("Store String Value?")]
public FsmString stringVariable;
public FsmString stringValue;
//
[ActionSection("Store Int Value?")]
public FsmInt intVariable;
public FsmInt intValue;

//
public override void Reset()
{
base.Reset();
sendEvent = null;
storeButtonState = null;
style = "Button";

}

public override void OnGUI()
{
base.OnGUI();

bool pressed = false;


if (GUI.Button(rect, content, style.Value))
{
Fsm.Event(sendEvent);
stringVariable.Value = stringValue.Value;
intVariable.Value = intValue.Value;
pressed = true;


}

if (storeButtonState != null)
{
storeButtonState.Value = pressed;
}
}
}
}

save as GUIAdvancedButton