using System;
using System.Collections.Generic;
using Core.Health;
using UnityEngine;
namespace ActionGameFramework.Audio
{
///
/// Health change sound selector
///
[Serializable]
public class HealthChangeSoundSelector
{
///
/// The array of health change sounds
/// This array should be in ascending order of Health Difference
///
[Tooltip("Health change should be in ascending order")]
public List healthChangeSounds;
///
/// Gets a value indicating whether this is set up.
///
/// true if there are Health Change Sounds; otherwise, false.
public bool isSetUp
{
get { return healthChangeSounds.Count > 0; }
}
///
/// Gets the clip from health change info.
///
/// The clip from health change info.
/// The HealthChangeInfo
public virtual AudioClip GetClipFromHealthChangeInfo(HealthChangeInfo info)
{
int count = healthChangeSounds.Count;
for (int i = 0; i < count; i++)
{
HealthChangeSound sound = healthChangeSounds[i];
// if the absolute health change is less than the sound health change
// then this is the sound clip to use
if (info.absHealthDifference <= sound.healthChange)
{
return sound.sound;
}
}
Debug.LogFormat("Could not find sound for healthChange of {0}", info.absHealthDifference);
return null;
}
}
}