-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioEntry.cs
More file actions
60 lines (54 loc) · 1.68 KB
/
AudioEntry.cs
File metadata and controls
60 lines (54 loc) · 1.68 KB
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
56
57
58
59
60
using System.Collections.Generic;
using UnityEngine;
namespace Framework.Utilities.AudioManager
{
[CreateAssetMenu(fileName = "AudioCatalog", menuName = "Framework/Audio/Audio Catalog")]
public class AudioCatalogSO : ScriptableObject
{
public List<SoundEntry> entries = new();
public Dictionary<string, SoundEntry> entriesDict = new();
// NOTE: 在编辑器中保持同步,以及统计数量一样不代表内容一致
private void EnsureMap()
{
if (entries.Count != entriesDict.Count)
{
entriesDict.Clear();
foreach (var e in entries)
{
if (!entriesDict.ContainsKey(e.id))
{
entriesDict.Add(e.id, e);
}
}
}
}
public SoundEntry GetSoundEntry(string id)
{
EnsureMap();
return entriesDict.TryGetValue(id, out var entry) ? entry : null;
}
public AudioClip GetAudioClip(string id)
{
EnsureMap();
return entriesDict.TryGetValue(id, out var entry) ? entry.clip : null;
}
#if UNITY_EDITOR
public void EditorRebuild()
{
entriesDict.Clear();
EnsureMap();
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
[System.Serializable]
public class SoundEntry
{
public string id;
public AudioClip clip;
[Range(0f, 1f)] public float defaultVolume = 1f;
[Range(0.5f, 2f)] public float defaultPitch = 1f;
public bool spatial = false;
public bool loop = false;
}
}