using System;
using UnityEngine;
namespace SK.Framework
{
///
/// 声音
///
[Serializable]
public class Sound
{
///
/// 声音来源
///
public SoundSource source = SoundSource.AudioClip;
///
/// 音频片段
///
public AudioClip audioClip;
///
/// 音频库名称(来源为音频库时起作用)
///
public string databaseName;
///
/// 音频数据名称(来源为音频库时起作用)
///
public string audioDataName;
public AudioClip GetAudioClip()
{
switch (source)
{
case SoundSource.AudioClip: return audioClip;
case SoundSource.Datebase:
AudioDatabase database = Audio.Database.Get(databaseName);
if (database == null) Audio.Database.Load(databaseName, out database);
return database.GetClip(audioDataName);
default: return null;
}
}
///
/// 播放
///
public void Play()
{
switch (source)
{
case SoundSource.AudioClip:
Audio.SFX.Play(audioClip);
break;
case SoundSource.Datebase:
AudioDatabase database = Audio.Database.Get(databaseName);
if (database == null)
{
Audio.Database.Load(databaseName, out database);
}
if (database != null)
{
AudioData data = database[audioDataName];
if (data != null)
{
Audio.SFX.Play(data.clip, database.outputAudioMixerGroup);
}
}
break;
default:
break;
}
}
}
}