playMaker

Author Topic: Set Mixer Float Value(s)  (Read 15067 times)

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Set Mixer Float Value(s)
« on: September 23, 2015, 06:18:55 AM »
Hi all,

as I could not find an easy way to access exposed audio mixer parameters with playmaker, I have written an action to set the value of an exposed parameter using the SetFloat function of the unity audio mixer. Then I tried to rewrite it so one can set the values of more than one parameter.

The background: Unfortunately unity's audio mixer snapshot system does not work properly with time scale set to 0 (maybe it will in the future). So you cannot use it in a game pause.
- EDIT (11-10-2017): Ability to transition AudioMixer snapshots by scaled and unscaled time added in Unity 5.3.6 (see Release Notes Unity 5.3.6 and ScriptingAPI-AudioMixer.updateMode) -

Both actions work. Nevertheless... these are my first actions and I have no experience in writing code. So it would be great if someone (maybe Jean) could tell me if there are any "bad", unusual, or unnecessary elements in my actions - especially the second one: I am not sure about the compound array thing and about introducing private variables.

EDIT (09-26-2015): Now both actions are available on the Ecosystem.

See the code on github:

AudioMixerSetFloatValue

AudioMixerSetMultiFloatValues

in the category AudioMixer.

A few things worth mentioning: To use these actions you have to manually expose parameters in the mixer first. Their names in the action editor field have to be written correctly (you can create a string variable if you want). When you set the values of exposed mixer parameters using SetFloat / using these actions, those parameters cannot be controlled by the snapshot system unless you use the ClearFloat function. Watch the unity tutorial (audio mixer exposed parameters).

EDIT (11-10-2017): Another AudioMixer action on the Ecosystem:
AudioMixerGetFloatValue (see code on GitHub: AudioMixerGetFloatValue).

Thank you.
Bye
« Last Edit: November 10, 2017, 03:37:21 PM by tropical »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Mixer Float Value(s)
« Reply #1 on: September 23, 2015, 09:50:22 AM »
Hi,

 This is great!

 Can I put these on the Ecosystem? It will be easier for people to get it. You can do it yourself as well, I can guide you, it's easy. Let me know what you prefer.


Bye,

 Jean

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Mixer Float Value(s)
« Reply #2 on: September 24, 2015, 03:06:48 AM »
Hi Jean,

yes, you can put the actions on the Ecosystem. Better you do it. If I touch the cs-files again, the temptation of opening them and changing a word in a tooltip line (or something like that) is too great for me.  :)

Thank you very much.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Mixer Float Value(s)
« Reply #3 on: September 24, 2015, 06:32:26 AM »
Hi,

 Ok, I have put them on the Ecosystem, Thanks :)

I renamed them for consistency, starting with the context: AudioMixerSetxxx

The code itself is fine, nothing wrong, I just put a check so that if the audioMixer is null it doesn't fire error if it's not defined.

 Bye,

 Jean

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Mixer Float Value(s)
« Reply #4 on: September 24, 2015, 11:33:51 AM »
Thanks, Jean!

I could edit my first post (replace the code/attachments with the changed version from the ecosystem), if you think that's necessary. Or should I leave it as it is?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Mixer Float Value(s)
« Reply #5 on: September 25, 2015, 07:24:12 AM »
Hi,

 I would edit the post yes and remove attachements and make direct links to the files, as well as mentioning they are accessible on Ecosystem.

https://github.com/PlayMakerEcosystem/PlayMakerCustomActions_U5/tree/master/Assets/PlayMaker%20Custom%20Actions/AudioMixer


 Bye,

 Jean

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Mixer Float Value(s)
« Reply #6 on: September 26, 2015, 07:02:27 AM »
Alright,
I've edited my first post.
Thanks Jean!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Mixer Float Value(s)
« Reply #7 on: September 28, 2015, 07:45:03 AM »
Hi,

 Thanks a lot

also, make sure for new content that you add also a new tag __PLAYMAKER__ as it will be needed soon for detecting playmaker content amongst other assets.


Bye,

 Jean

Gua

  • Beta Group
  • Sr. Member
  • *
  • Posts: 309
    • Andrii Vintsevych
Re: Set Mixer Float Value(s)
« Reply #8 on: September 22, 2017, 07:29:08 AM »
Is there a way to get AudioMixer float value?

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Mixer Float Value(s)
« Reply #9 on: September 24, 2017, 05:50:33 PM »
Is there a way to get AudioMixer float value?

Hello Gua!

Yes, there is (https://docs.unity3d.com/ScriptReference/Audio.AudioMixer.GetFloat.html). However, I don't think there is such a PM-action in the PM package / the ecosystem yet.

The respective action could look like this:

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
// original actions from Tropical: http://hutonggames.com/playmakerforum/index.php?topic=11218.msg52963#msg52963
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/


using UnityEngine;
using UnityEngine.Audio;
using HutongGames.PlayMaker;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Audio)]
[ActionTarget(typeof(AudioMixer), "theMixer")]
[Tooltip("Gets the float value of an exposed parameter for a Unity Audio Mixer. Prior to calling SetFloat and after ClearFloat has been called on this parameter the value returned will be that of the current snapshot or snapshot transition.")]
public class AudioMixerGetFloatValue : FsmStateAction
{
[RequiredField]
[ObjectType(typeof(AudioMixer))]
[Tooltip("The Audio Mixer with the exposed parameter.")]
public FsmObject theMixer;

[RequiredField]
[Tooltip("The name of the exposed parameter.")]
[Title("Name of Parameter")]
public FsmString exposedFloatName;

[RequiredField]
[UIHintAttribute(UIHint.Variable)]
[Tooltip("Store the Float value in a variable")]
public FsmFloat storeFloatValue;

public bool everyFrame;

public override void Reset()
{
theMixer = null;
exposedFloatName = null;
storeFloatValue = null;
everyFrame = false;
}

public override void OnEnter()
{
DoGetMixerFloatValue();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoGetMixerFloatValue();
}

public void DoGetMixerFloatValue()
{
var _TheMixer = theMixer.Value as AudioMixer;
var _ExposedFloatName = exposedFloatName.Value;

if (_TheMixer!=null && !string.IsNullOrEmpty(_ExposedFloatName))
{
var _storeFloatValue = 0F;
_TheMixer.GetFloat (_ExposedFloatName, out _storeFloatValue);
storeFloatValue.Value = _storeFloatValue;
}
}
}
}

The above code should work  (if you need the action right now...), no errors when testing - though I don't know if it's 'perfect'.

@Jean: The code contains the ECO/PLAYMAKER/ACTION flags (just copied the 3 top lines from the AudioMixerSetFloatValue-action). I haven't put any actions on the ecosystem myself yet. Maybe you could do that, once again :), if you consider the code adequate. Thanks.

Best regards
tropical
« Last Edit: September 24, 2017, 05:57:29 PM by tropical »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Mixer Float Value(s)
« Reply #10 on: September 26, 2017, 04:15:19 AM »
Hi,

 Cool :)

 you could put it yourself if you want to contribute? else I'll put it up, not a problem.

 Bye,

 Jean

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Mixer Float Value(s)
« Reply #11 on: October 02, 2017, 06:11:40 AM »
Hi Jean,

I would try to put it on the ecosystem myself. Can you give me some instructions? I haven't got a Github account (yet)...

Bye

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Mixer Float Value(s)
« Reply #12 on: October 20, 2017, 02:26:32 AM »
Hi,

1: Create a github account
2: Get sourcetree or github Client app
3: Clone the Unity 5 dedicated custom action rep: https://github.com/PlayMakerEcosystem/PlayMakerCustomActions_U5 on your computer ( this will be a local copy of that rep)
4: Open that local copy with Unity 5.6
5: Install PlayMaker ( you have to manually install it because of the errors you'll get, the install package is inside PlayMaker/Editor/Install )
6: Add your action inside Assets/PlayMaker Custom Actions/Audio/
7: verify that Unity compiles, verify your actions works as expected
8: in source tree or github client, commit and push that new action.

Let me know if you get stuck in one of these steps.

 Bye,

 Jean

tropical

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Mixer Float Value(s)
« Reply #13 on: October 31, 2017, 06:03:46 AM »
Hi Jean,

thanks a lot for your instructions and sorry for my late reply.
Steps 1 and 2 are completed :-) but I've got a question concerning the unity version:
4: Open that local copy with Unity 5.6
Does this mean Unity 5.6 or newer or does it mean 5.6 only? I'm using Unity 2017 (2017.1 at the moment). Can I open it with 2017?

Bye

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Mixer Float Value(s)
« Reply #14 on: November 01, 2017, 03:28:20 AM »
Hi,

 5.6 only, as you need to make sure it compiles for Unity 5.6

 if you want to host this action on a 2017 project, you then would work on the other github rep dedicated to 2017: https://github.com/PlayMakerEcosystem/PlayMakerCustomActions_U2017

but you should always use the lowest possible Unity version to have your action working on as much versions as possible.

Also, it's totally possible to install several versions of Unity on your computer. If you google for it you'll find plenty of explanations, are you on mac or windows?

 Bye,

 Jean