heavy
heavy copied to clipboard
Mapping UI Slide to Hv AudioLib parameters
Hi Joe, i am making a UI for the FM PD patch in Unity I am having some problems understanding why i dont see the Hv AudioLib UI parameters from the UI Slide event Horizontal and Vertical. (please see pics)
do i need to create another script to access the Hv AudioLib UI parameters from the slider event? Thanks Joe,
Yeah, I didn't think about this, so I might need to revisit the AudioLib interface add some point to enable this kind of support.
But you're right, you can write a wrapper script to forward your event updates to the AudioLib script.
Say you have a public float parameter
public class MyForwarder : MonoBehavior {
private Hv_example_AudioLib script;
public static float myParam
{
get{return script.GetFloatParameter(Hv_example_AudioLib.Parameter.myParam); }
set
{
script.SetFloatParameter(Hv_example_AudioLib.Parameter.myParam, value);
}
}
public Awake() {
script = GetComponent<Hv_example_AudioLib>();
}
}
And attach this script at the same level as the AudioLib component on your gameobject.
Note: this is untested code but this is how I would probably attempt it!
Amazing, thanks Joe will try this.
Hi Joe, I have tried your code, it works! i can see the parameters now. the only thing i had to add to the script was static to private Hv_FM_test_AudioLib script; I am going to map away now .. and report back.thanks alot
public class WrapperTest : MonoBehaviour {
private static Hv_FM_test_AudioLib script;
public static float Amp
{
get{return script.GetFloatParameter(Hv_FM_test_AudioLib.Parameter.Amp); }
set
{
script.SetFloatParameter(Hv_FM_test_AudioLib.Parameter.Amp, value);
}
}
public void Awake() {
script = GetComponent<Hv_FM_test_AudioLib>();
}
public static float Carrier
{
get{return script.GetFloatParameter(Hv_FM_test_AudioLib.Parameter.Amp); }
set
{
script.SetFloatParameter(Hv_FM_test_AudioLib.Parameter.Carrier, value);
}
}
}
Cool! Ahh yeah that makes sense, you probably don't want it static
, if you remove the static
keyword from the public static float Amp
declaration then you should be able to avoid setting the AudioLib to static.
coolio, I have changed it, no errors, happy times, thanks Joe
Was unable to get this working. This was sending this error to the log.
Assets/Plugins/MacOSX/PortForward.cs(17,12): error CS1520: Class, struct, or interface method must have a return type
I ended up solving this issue with this. I am able to access the value and edit it in a UI Slider OnValueChanged as a Dynamic Float.
public class FloatForward : MonoBehaviour {
public void TestValue(float value)
{
Hv_helloWorld_AudioLib script = GetComponent<Hv_helloWorld_AudioLib>();
script.SetFloatParameter(Hv_helloWorld_AudioLib.Parameter.Freq, value);
}
}
Just a warning, but for some reason changing the slider value in the editor will just throw up warnings and not work. Seems like a long standing issue with Unity.
SendMessage cannot be called during Awake, CheckConsistency, or OnValidate UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)