Bär wartet nach aufwachen etc
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SoundEffectLibrary : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private SoundEffectGroup[] soundEffectGroups;
|
||||
private Dictionary<string, List<AudioClip>> soundDictionary;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitializeDictionary();
|
||||
}
|
||||
|
||||
private void InitializeDictionary()
|
||||
{
|
||||
soundDictionary = new Dictionary<string, List<AudioClip>>();
|
||||
foreach (SoundEffectGroup soundEffectGroup in soundEffectGroups)
|
||||
{
|
||||
soundDictionary[soundEffectGroup.name] = soundEffectGroup.audioClips;
|
||||
}
|
||||
}
|
||||
|
||||
public AudioClip GetRandomClip(string name)
|
||||
{
|
||||
if (!soundDictionary.ContainsKey(name))
|
||||
{
|
||||
List<AudioClip> audioClips = soundDictionary[name];
|
||||
if(audioClips.Count > 0)
|
||||
{
|
||||
return audioClips[UnityEngine.Random.Range(0, audioClips.Count)];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct SoundEffectGroup
|
||||
{
|
||||
public string name;
|
||||
public List<AudioClip> audioClips;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 423f4b81219a67a41be9c759a8db5448
|
||||
Reference in New Issue
Block a user