-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEcsAudioStorage.cs
More file actions
39 lines (35 loc) · 1.29 KB
/
EcsAudioStorage.cs
File metadata and controls
39 lines (35 loc) · 1.29 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
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Audio;
namespace Arc.ECSAudio
{
public static class EcsAudioStorage
{
public static Dictionary<Guid, AudioClip> RegisteredAudioClips = new Dictionary<Guid, AudioClip>();
public static Dictionary<Guid, AudioMixerGroup> RegisteredAudioMixerGroups =
new Dictionary<Guid, AudioMixerGroup>();
public static Dictionary<Guid, AnimationCurve> RegisteredCustomCurves =
new Dictionary<Guid, AnimationCurve>();
public static Guid Register<T>(T objectToRegister, Dictionary<Guid, T> register, Func<T, T, bool> areEqual)
{
var registeredObject = register.Where(pair =>
{
if (objectToRegister == null && pair.Value == null) return true;
if (objectToRegister == null || pair.Value == null) return false;
return areEqual(pair.Value, objectToRegister);
}).ToList();
if (registeredObject.Any())
{
return registeredObject.First().Key;
}
else
{
var guid = Guid.NewGuid();
register.Add(guid, objectToRegister);
return guid;
}
}
}
}