You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using FMODUnity;
|
|
using FMOD.Studio;
|
|
|
|
namespace Moloch
|
|
{
|
|
public class AudioManager : MonoBehaviour
|
|
{
|
|
public static AudioManager instance { get; private set; }
|
|
|
|
[SerializeField] public EventReference m_Soundtrack;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null)
|
|
Debug.LogError("Found more than one Audio Manager in the scene");
|
|
instance = this;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
StartSoundtrack();
|
|
}
|
|
|
|
public void StartSoundtrack()
|
|
{
|
|
if (!m_Soundtrack.IsNull)
|
|
{
|
|
RuntimeManager.PlayOneShot(m_Soundtrack);
|
|
}
|
|
}
|
|
|
|
public EventInstance PlaySound(EventReference sound)
|
|
{
|
|
EventInstance soundInst = RuntimeManager.CreateInstance(sound);
|
|
soundInst.start();
|
|
return soundInst;
|
|
}
|
|
|
|
public void StopSound(EventInstance soundInst)
|
|
{
|
|
soundInst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
|
|
soundInst.release();
|
|
soundInst.clearHandle();
|
|
}
|
|
}
|
|
}
|
|
|