I want to create an List with all my audios so it can then be used as some kind of database of audio files to be played in the game.
Those audio clips are in a resource folder Resources/Audio/GameAudio/DirectorSentences
I want to populate my List automatically by reading the content of the folder and loading all the file in edit mode. So when I add new Audio Clips in my folder it updates my AudioClip List
Here is what I did:
public class DirectorInterventions : MonoBehaviour
{
public List<SoundAudioClip> DirectorAudio;
public string FolderName;
private void Awake()
{
GenerateSound(FolderName);
}
private void GenerateSound(string path)
{
string directory = "GameAudio/" + path;
foreach (AudioClip audioClip in Resources.LoadAll<AudioClip>(path))
{
Debug.Log(audioClip.name);
// adding audio files in my SoundAudioClip list
}
}
[System.Serializable]
public class SoundAudioClip
{
public string sound;
public AudioClip audioClip;
public SoundAudioClip(AudioClip clip)
{
this.sound = clip.name;
this.audioClip = clip;
}
}
}
But I still don’t understand How to make GenerateSound() execute in editor, without having to play the game.
Can you help me ?
Thank you in advance