using UnityEngine;
using System.Linq;
using System.Collections.Generic;

[System.Serializable]
public class SoundEntry
{
    public string Name;
    public List<AudioClip> Sounds;
    public bool Optional;
    public float Volume = 1.0f;
}

public class RenderSounds : MonoBehaviour {

    public List<SoundEntry> Sounds;
    public float MasterVolume = 1.0f;

    public static void PlaySound(string name)
    {
        SoundEntry s = instance.Sounds.Where(e => e.Name == name).FirstOrDefault();
        if (s == null)
            return;

        instance.asrc.PlayOneShot(ListHelper.DrawFromAtRandom(s.Sounds), s.Volume);
    }

    public static RenderSounds instance;
    private AudioSource asrc;
    
    void Start()
    {
        instance = this;
        asrc = gameObject.AddComponent<AudioSource>();
    }
    
}
