|
Post by nitrox32 on Nov 25, 2020 22:24:53 GMT
I'm converting a project over to MA. I've deleted all of the audio sources in a scene. However the sounds on certain objects are now not working. I expected this however some objects such as the Emerald AI enemies will not allow their audio sources to be removed. When I try, I get errors that says an AudioSource can be removed because a script depends it. Since I tried to removed the audio sources the sound of my Emerald AI characters no longer play even though they still have audio sources on them.
Here is what I noticed, if I begin the game at its start scene the problem arises. This is the scene where I have my MasterAudio prefab (set to persist through scenes). This is where I also have my audio listener (also persisting) in the scene. When I go to a game scene from the start scene, all of my Emerald AI characters loose their sound. However if I load a game scene separately, add an audio listener to that scene and start it, the Emerald AI has sound. Any thoughts on this?
|
|
|
Post by DarkTonic Dev on Nov 25, 2020 23:10:18 GMT
I am not familiar with Emerald AI. I believe you will need to remove the dependency in one of the Emerald AI scripts so that it lets you remove the Audio Sources too. Then you'll need to replace any code in Emerald AI that assumes there's an Audio Source there to: MasterAudio.PlaySound3D type commands.
If you have any issues, you should contact the author of Emerald AI. Maybe he will consider writing integration for Master Audio? I'd be happy to contact him and ask if you'd prefer.
Thanks, -Brian
|
|
|
Post by nitrox32 on Nov 26, 2020 3:35:18 GMT
I've been able to identify the code in Emerald AI that deals with sound. There are about a dozen functions that all basically look the same. Any thoughts on how I would replace these to MA commands?
public void PlayAttackSound() { if (EmeraldComponent.AttackSounds.Count > 0) { if (!EmeraldComponent.m_AudioSource.isPlaying) { EmeraldComponent.m_AudioSource.volume = EmeraldComponent.AttackVolume; EmeraldComponent.m_AudioSource.PlayOneShot(EmeraldComponent.AttackSounds[Random.Range(0, EmeraldComponent.AttackSounds.Count)]); } else { EmeraldComponent.m_SecondaryAudioSource.volume = EmeraldComponent.AttackVolume; EmeraldComponent.m_SecondaryAudioSource.PlayOneShot(EmeraldComponent.AttackSounds[Random.Range(0, EmeraldComponent.AttackSounds.Count)]); } }
|
|
|
Post by DarkTonic Dev on Nov 26, 2020 4:41:29 GMT
You'd need to put the attack sounds into a Sound Group. Then add: [SoundGroup] public string AttackSound;
From which you select the Sound Group from a dropdown in the Inspector.
Then replace the volume and PlayOneShot with:
MasterAudio.PlaySound3DAtTransform(AttackSound, EmeraldComponent.AttackVolume);
|
|
|
Post by nitrox32 on Nov 27, 2020 16:26:13 GMT
So I have successfully be able to integrate Emerald AI''s audio functions. I did this by doing what you suggested by replacing the PlayOneShot with "MasterAudio.PlaySound3DAtTransform(AttackSound, EmeraldComponent.AttackVolume)". The problem I ran into was that simply adding "[SoundGroup], public string AttackSound;" to the EmeraldAI script proved more difficult because Emerald AI has it's own interface that is not allowing me to simply add a public variable and have it be seen in the editor. My solution was to create a separate script that included the [SoundGroup] code and change the string to static that could be called from the MasterAudio.PlaySound3DAtTransform(AttackSound, EmeraldComponent.AttackVolume) in the EmeraldAI script. I would attach this script to an empty object, select my sounds and everything worked. This is the code that collects the sounds:public class MasterAudioEmeraldAIBridge : MonoBehaviour {
[SoundGroup] public string[] attackSounds; public static string[] MAEmeraldAttackSounds;
[SoundGroup] public string[] impactSounds; public static string[] MAEmeraldImpactSounds;
[SoundGroup] public string[] warningSounds; public static string[] MAEmeraldWarningSounds;
[SoundGroup] public string[] idleSounds; public static string[] MAEmeraldIdleSounds;
[SoundGroup] public string[] injuredSounds; public static string[] MAEmeraldInjuredSounds;
[SoundGroup] public string[] deathSounds; public static string[] MAEmeraldDeathSounds;
private void Start() { MAEmeraldAttackSounds = attackSounds; MAEmeraldImpactSounds = impactSounds; MAEmeraldWarningSounds = warningSounds; MAEmeraldIdleSounds = idleSounds; MAEmeraldInjuredSounds = injuredSounds; MAEmeraldDeathSounds = deathSounds; } }
This is what is called in the Emerald AI code:
public void PlayAttackSound() { if (MasterAudioEmeraldAIBridge.MAEmeraldAttackSounds.Length > 0) { int randomSoundFromList = Random.Range(0, MasterAudioEmeraldAIBridge.MAEmeraldAttackSounds.Length); MasterAudio.PlaySound3DAtTransform(MasterAudioEmeraldAIBridge.MAEmeraldAttackSounds[randomSoundFromList], gameObject.transform); } }
The problem with using static variables is that every enemy will have the same sounds. I'm not very experienced at coding, is there a better way that would allow me to use a similar approach but only have the variables visible to the scripts only attached to that enemy so that each enemy will have it's own sounds?
|
|
|
Post by DarkTonic Dev on Nov 27, 2020 18:13:17 GMT
If they have used Custom Inspectors so that you can't have public variables, you will need a workaround as you have done.
You do not need to add "randomize" code to your script. Master Audio does that for you. Just list the Sound Group, not an array, and that Sound Group will contain all the Variation sounds.
|
|