hello,
Im currently in the process of writing a sfx player which I will use to play my custom sfx’s. Each sfx has their own set of audioClips which can be played at random or in order. The sfx manager creates a pool of AudioSources connected to these sfx’s but the user can optionally provide an AudioSource when playing the sfx.
So I started using method overloading for the Play() method. I was wondering if this could be simplified and if this looks reasonable or that im overcomplicating things:
public void Play(string name)
{
Play(name, Style.None, false);
}
public void Play(string name, Style style)
{
Play(name, style, false);
}
public void Play(string name, bool fadeIn)
{
Play(name, Style.None, fadeIn);
}
public void Play(string name, Style style, bool fadeIn)
{
//DO ALL LOGIC WITH DEFAULT AUDIOSOURCE
}
public void Play(string name, AudioSource source)
{
Play(name, source, Style.None, false);
}
public void Play(string name, AudioSource source, Style style)
{
Play(name, source, style, false);
}
public void Play(string name, AudioSource source, bool fadeIn)
{
Play(name, source, Style.None, fadeIn);
}
public void Play(string name, AudioSource source, Style style, bool fadeIn)
{
//DO ALL LOGIC WITH PROVIDED AUDIOSOURCE
}
Would it okay to add a null as parameter so i onyl have to deal once with the logic?
public void Play(string name, Style style, bool fadeIn)
{
Play(name, null, style, fadeIn);
}