-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathReplacementAudioClip.cs
121 lines (97 loc) · 3.51 KB
/
ReplacementAudioClip.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static LCSoundTool.Utilities.Extensions;
namespace LCSoundTool
{
public class ReplacementAudioClip
{
public List<RandomAudioClip> clips;
public string source = string.Empty;
public bool canPlay = true;
private bool initialized = false;
public ReplacementAudioClip(AudioClip clip, float chance, string source)
{
if (!initialized)
Initialize();
RandomAudioClip rClip = new RandomAudioClip(clip, chance);
if (!clips.ContainsThisRandomAudioClip(rClip))
{
clips.Add(rClip);
this.source = source;
}
else if (SoundTool.infoDebugging)
{
SoundTool.Instance.logger.LogDebug($"RandomAudioClip {rClip.clip.GetName()} ({Mathf.RoundToInt(chance * 100f)}%) already exists withing this AudioClipContainer!");
SoundTool.Instance.logger.LogDebug($"- This AudioClipContainer contains the following clip(s):");
for (int i = 0; i < clips.Count; i++)
{
SoundTool.Instance.logger.LogDebug($"-- Clip {i + 1} - {clips[i].clip.GetName()} with a chance of {Mathf.RoundToInt(clips[i].chance * 100f)}%");
}
}
}
public ReplacementAudioClip(string source)
{
Initialize();
this.source = source;
}
public ReplacementAudioClip()
{
Initialize();
source = string.Empty;
}
public void AddClip(AudioClip clip, float chance)
{
if (!initialized)
Initialize();
RandomAudioClip rClip = new RandomAudioClip(clip, chance);
if (!clips.ContainsThisRandomAudioClip(rClip))
{
clips.Add(rClip);
}
else if (SoundTool.infoDebugging)
{
SoundTool.Instance.logger.LogDebug($"RandomAudioClip {rClip.clip.GetName()} ({Mathf.RoundToInt(chance * 100f)}%) already exists withing this AudioClipContainer!");
SoundTool.Instance.logger.LogDebug($"- This AudioClipContainer contains the following clip(s):");
for (int i = 0; i < clips.Count; i++)
{
SoundTool.Instance.logger.LogDebug($"-- Clip {i + 1} - {clips[i].clip.GetName()} with a chance of {Mathf.RoundToInt(clips[i].chance * 100f)}%");
}
}
}
public bool Full()
{
if (!initialized)
Initialize();
float chance = 0f;
for (int i = 0; i < clips.Count; i++)
{
chance += clips[i].chance;
}
return chance >= 1f;
}
public bool ContainsClip(AudioClip clip, float chance)
{
if (!initialized)
Initialize();
RandomAudioClip rClip = new RandomAudioClip(clip, chance);
return clips.ContainsThisRandomAudioClip(rClip);
}
public float TotalChance()
{
if (!initialized)
Initialize();
float total = 0f;
for (int i = 0; i < clips.Count; i++)
{
total += clips[i].chance;
}
return total;
}
private void Initialize()
{
clips = new List<RandomAudioClip>();
initialized = true;
}
}
}