playMaker

Author Topic: Transition Between 2 Snapshots (Unity 5 Audio Mixer)[SOLVED]  (Read 9065 times)

MUX

  • Playmaker Newbie
  • *
  • Posts: 43
    • @stefstivala
Transition Between 2 Snapshots (Unity 5 Audio Mixer)[SOLVED]
« 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;

}

}
}
« Last Edit: March 30, 2016, 04:55:51 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
« Reply #1 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

MUX

  • Playmaker Newbie
  • *
  • Posts: 43
    • @stefstivala
Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
« Reply #2 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.

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
« Reply #3 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

MUX

  • Playmaker Newbie
  • *
  • Posts: 43
    • @stefstivala
Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
« Reply #4 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!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
« Reply #5 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

 Bye,

 Jean

gerickt

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Transition Between 2 Snapshots (Unity 5 Audio Mixer)
« Reply #6 on: March 17, 2016, 01:35:47 PM »
nice work MUX, works!