Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: MUX on August 28, 2015, 07:18:43 AM

Title: Transition Between 2 Snapshots (Unity 5 Audio Mixer)[SOLVED]
Post by: MUX on August 28, 2015, 07:18:43 AM
was in need of this today, an official action doesn't exist so i created one..
the bool variable is to allow the facility to quickly transition back if event is called again, the float is the time to transitions.

not used to sharing actions, any recommended improvements?

Code: [Select]
using UnityEngine;
using UnityEngine.Audio;
using HutongGames.PlayMaker;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Audio)]
public class TransitionToSnapshot : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmBool boolVariable;

[RequiredField]
public AudioMixerSnapshot AudioSnapshotA;
[RequiredField]
public AudioMixerSnapshot AudioSnapshotB;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat TransitionTime;

public override void Reset()
{
boolVariable = null;
TransitionTime = null;
AudioSnapshotB = null;
AudioSnapshotA = null;
}

public override void OnEnter()
{
DoBoolOperator();
Finish();
}

void DoBoolOperator()
{
var Bool = boolVariable.Value;
var _TransitionTime = TransitionTime.Value;

if(!Bool){
AudioSnapshotB.TransitionTo(_TransitionTime);
} else {
AudioSnapshotA.TransitionTo(_TransitionTime);
}

boolVariable.Value = !boolVariable.Value;

}

}
}
Title: Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
Post by: jeanfabre on September 02, 2015, 01:37:56 AM
Hi,

 Great, one thing to typically improve the action:

 audioSnapShot public properties should become FsmObject of type "audioSnapShot", then developer can reference that snapshot outside the fsm logic, in a variable, expose it in the inspector and work with it in variosu places, with the action as is currently, you end up with having to drag and drop on every action which is not ideal for clarity and long term flexibility and maintenance of your project.

If you're ok with this changes, let me know, when it's done and I'll put it on the ecosystem. Else I could do it so you understand what I mean?

Bye,

 Jean
Title: Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
Post by: MUX on September 02, 2015, 02:18:21 AM
thanks jean, i will try to improve with your suggestion and resubmit.
think it would also be better if i leave the bool logic out of the action itself though to make it more straight forward, then the dev can set up a custom bool logic in there own fsm.
Title: Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
Post by: tropical on September 17, 2015, 06:57:21 PM
Hi,

I wonder why the TransitionTime variable in this Action (Version: August 28) has the [UIHint(UIHint.Variable)]-thing? I don't know much about all that, but I think it forces you to input a variable as the value and doesn't let you just type a number. Sorry, if I'm wrong.

Bye,
Jay
Title: Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
Post by: MUX on September 17, 2015, 07:23:45 PM
think you are right. Not used to writing custom actions, so modified something different and worked for my scenario.

sorry haven't yet had time to improve this action to make it more flexible!
Title: Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
Post by: jeanfabre on September 18, 2015, 03:03:20 AM
Hi,

 no worries, just give me a shout when you have, an dI'll post it on the Ecosystem (http://j.mp/1Esn1mF)

 Bye,

 Jean
Title: Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
Post by: gerickt on March 17, 2016, 01:35:47 PM
nice work MUX, works!