wangguan
2020-12-25 b35c810d34558ac4bcdbe382fae6db4cb3e3b545
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using Core.Health;
using UnityEngine;
 
namespace ActionGameFramework.Audio
{
    /// <summary>
    /// Health change sound selector
    /// </summary>
    [Serializable]
    public class HealthChangeSoundSelector
    {
        /// <summary>
        /// The array of health change sounds
        /// This array should be in ascending order of Health Difference
        /// </summary>
        [Tooltip("Health change should be in ascending order")]
        public List<HealthChangeSound> healthChangeSounds;
 
        /// <summary>
        /// Gets a value indicating whether this <see cref="ActionGameFramework.Audio.HealthChangeSoundSelector" /> is set up.
        /// </summary>
        /// <value><c>true</c> if there are Health Change Sounds; otherwise, <c>false</c>.</value>
        public bool isSetUp
        {
            get { return healthChangeSounds.Count > 0; }
        }
 
        /// <summary>
        /// Gets the clip from health change info.
        /// </summary>
        /// <returns>The clip from health change info.</returns>
        /// <param name="info">The HealthChangeInfo</param>
        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;
        }
    }
}