Audio Management + Animations
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using FMODUnity;
|
||||
using FMOD.Studio;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
private List<EventInstance> eventInstances;
|
||||
|
||||
private EventInstance musicEventInstance;
|
||||
public static AudioManager instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
Debug.LogError("Found more than one Audio Manager in the scene");
|
||||
}
|
||||
instance = this;
|
||||
|
||||
eventInstances = new List<EventInstance>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InitializeMusic(FMODEvents.instance.music);
|
||||
}
|
||||
|
||||
private void InitializeMusic(EventReference musicEventReference)
|
||||
{
|
||||
musicEventInstance = CreateEventInstance(musicEventReference);
|
||||
musicEventInstance.start();
|
||||
}
|
||||
|
||||
public void PlayOneShot(EventReference sound, Vector3 worldPos)
|
||||
{
|
||||
RuntimeManager.PlayOneShot(sound, worldPos);
|
||||
}
|
||||
|
||||
public void PauseMusic()
|
||||
{
|
||||
musicEventInstance.setPaused(true);
|
||||
}
|
||||
|
||||
|
||||
public void PlayMusic()
|
||||
{
|
||||
musicEventInstance.setPaused(false);
|
||||
}
|
||||
|
||||
public void StopMusic()
|
||||
{
|
||||
musicEventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
|
||||
}
|
||||
|
||||
|
||||
public EventInstance CreateEventInstance(EventReference eventReference)
|
||||
{
|
||||
EventInstance eventInstance = RuntimeManager.CreateInstance(eventReference);
|
||||
eventInstances.Add(eventInstance);
|
||||
return eventInstance;
|
||||
}
|
||||
|
||||
private void CleanUp()
|
||||
{
|
||||
foreach (EventInstance eventInstance in eventInstances)
|
||||
{
|
||||
eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
|
||||
eventInstance.release();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2d525624a4586c4f903a2f0f33d0529
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using FMODUnity;
|
||||
|
||||
public class FMODEvents : MonoBehaviour
|
||||
{
|
||||
[field: Header("Jump SFX")]
|
||||
[field: SerializeField] public EventReference jumped { get; private set; }
|
||||
[field: Header("Die SFX")]
|
||||
[field: SerializeField] public EventReference died { get; private set; }
|
||||
[field: Header("Level Music")]
|
||||
[field: SerializeField] public EventReference music { get; private set; }
|
||||
|
||||
public static FMODEvents instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance!=null)
|
||||
{
|
||||
Debug.LogError("Found more than one FMOD Events instance in the scene.");
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5400e43894b6a144aa6916a101fbf724
|
||||
Reference in New Issue
Block a user