joshmond
Topic Author
Posts: 38
Joined: 02 Jun 2018, 00:10

Playing Audio from Unity with NoesisGUI

31 Oct 2022, 15:54

Hello guys, I have a question regarding audio in NoesisGUI. I'm workin on a system that is similar to a communication wheel where there are different options when clicked such as playing voicelines and eventually generating pings in world. Right now I am focused on implementing different sound queues for my project and I was wondering how I would go about integrating Unity's audio system into the XAML. For example, on the radial menu demo, you have this:
 <b:DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="True">
         <b:PlaySoundAction Source="Sounds/AudioName.mp3" Volume="1.0" IsEnabled="False"/>
  </b:DataTrigger>
  
I was wondering if it were possible to bind Unity'd AudioClip, to this. So I have something like this instead

 <b:DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Value="True">
	 <b:PlaySoundAction Source="{Binding AudioFile}" Volume="1.0" IsEnabled="False"/>
</b:DataTrigger>

public class Callout
{
    public string Name { get; set; }
    public ImageSource Icon { get; set; }

    public AudioClip AudioFile { get; set; }
}


The view model that I am using is a Monobehaviour but I am wondering if I can use Unity's Audio system for some sort of XAML click event and how I would go about doing that?

I'm not sure if the " PlaySoundAction" on the XAML is using the same audio source as Unity (I assume they would be different)?

Any help is appreciated
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Playing Audio from Unity with NoesisGUI

01 Nov 2022, 12:23

PlayAudio is implemented using PlayClipAtPoint. Source code is available in NoesisProviders.cs.
public void PlayAudio(string uri, float volume)
{
    Value v;
    if (_audios.TryGetValue(uri, out v) && v.audio != null)
    {
        UnityEngine.AudioSource.PlayClipAtPoint(v.audio, UnityEngine.Vector3.zero, volume);
    }
    else
    {
        UnityEngine.Debug.LogError("AudioClip not found '" + uri + "'");
    }
}
But yes, nothing stops you from creating your own solution with more control.

Who is online

Users browsing this forum: Google [Bot] and 69 guests