This is the FMOD_AudioManager script. I added this to a GameManager gameObject that is in my scene.
It uses the EventHandler that comes with Character Controller to listen for an event to play the sound and then uses the FMOD Unity integration to play it at that spot.
C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Events;
public class FMOD_AudioManager : MonoBehaviour
{
private static FMOD_AudioManager s_Instance;
public static FMOD_AudioManager Instance
{
get
{
if (!s_Initialized)
{
s_Instance = new GameObject("FMOD Audio Manager").AddComponent<FMOD_AudioManager>();
s_Initialized = true;
}
return s_Instance;
}
}
private static bool s_Initialized;
private void Awake()
{
EventHandler.RegisterEvent<Transform, string>("PlayFMODSound", Play);
}
public void Play(Transform location, string eventName)
{
FMODUnity.RuntimeManager.PlayOneShot(eventName, location.position);
}
public void OnDestroy()
{
EventHandler.UnregisterEvent<Transform, string>("PlayFMODSound", Play);
}
}
Then I edited the AudioManager script starting at line 468 inside the PlayInternal method. Since all sounds that are played by the controller go through this script, it looks at the name of the audioClip to see if it has "FMOD" in the string. If it does then it creates the FMOD Event Reference string using the name of the audio clips and executes the event on the FMOD_AudioManager script that plays the sound.
C#:
/* CUSTOM CODE */
if (clip.name.IndexOf("FMOD") == 0)
{
string eventName = clip.name.Replace("FMOD_", "");
eventName = "event:/" + eventName.Replace("_", "/");
Debug.Log(eventName);
EventHandler.ExecuteEvent("PlayFMODSound", gameObject.transform, eventName);
} else {
/* END CUSTOM CODE */
In FMOD I have my events in a folder structure like this...
View attachment 1816
In Unity I took an existing .wav file and simply renamed it so that the name matched the naming convention needed by the Audio Manager. Then I duplicated that file and just changed the name.
View attachment 1817
Then I just assigned those audio files to the Start and Stop AudioClip fields on Character Controller. I also added the Shoot, Reload, and DryFire audio files to my weapons.
View attachment 1818
You can also use this method for Surface Effects. And as I said, I used the standard FMODUnity components for all other sounds like music, environmental elements and pickups. With this method, anywhere that you use an audioClip in Character Controller you can use this method.
Let me know if you need anything else.