Skip to content

Commit c009790

Browse files
Code cleanup and refactoring
1 parent 3865619 commit c009790

81 files changed

Lines changed: 3554 additions & 2230 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Components/AudioAnimEvent.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ public sealed class AudioAnimEvent : StateMachineBehaviour
1616
public Vector3 offset = Vector3.up;
1717
private uint handle;
1818

19+
public override void OnStateEnter(Animator animator, AnimatorStateInfo info, int layer)
20+
{
21+
KeyOn(animator);
22+
}
23+
24+
public override void OnStateExit(Animator animator, AnimatorStateInfo info, int layer)
25+
{
26+
KeyOff();
27+
}
28+
1929
public void KeyOn(Animator a)
2030
{
2131
bool looping;
@@ -30,15 +40,5 @@ public void KeyOff()
3040
handle = 0;
3141
}
3242
}
33-
34-
public override void OnStateEnter(Animator animator, AnimatorStateInfo info, int layer)
35-
{
36-
KeyOn(animator);
37-
}
38-
39-
public override void OnStateExit(Animator animator, AnimatorStateInfo info, int layer)
40-
{
41-
KeyOff();
42-
}
4343
}
4444
} // Appalachia.Core.Audio

src/Components/AudioEmitter.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,36 @@ public enum Controller
2222
[FormerlySerializedAs("assets")]
2323
public Patch[] patches;
2424

25-
private uint[] cueHandles;
26-
2725
[Range(0, 1)] public float volume = 1f;
2826

2927
public bool autoCue = true;
3028
public bool singleShot;
31-
private bool cuedOnce;
3229

3330
[HideInInspector] public Controller controller;
3431

35-
[Colorize] public RandomizationParams randomization = new RandomizationParams {chance = 1f};
32+
[Colorize] public RandomizationParams randomization = new() {chance = 1f};
3633

37-
[Colorize] public ModulationParams modulation = new ModulationParams {volume = new MinMaxFloat {min = 0.95f, max = 1.05f}};
34+
[Colorize]
35+
public ModulationParams modulation =
36+
new() {volume = new MinMaxFloat {min = 0.95f, max = 1.05f}};
3837

3938
[Colorize] public AttachmentParams attachment;
4039

4140
[Colorize] public AuxiliaryParams auxiliary;
4241

43-
[Colorize] public GizmoParams gizmo = new GizmoParams {color = Color.red};
42+
[Colorize] public GizmoParams gizmo = new() {color = Color.red};
43+
private bool cuedOnce;
4444

45-
internal AudioZone zone;
45+
private uint[] cueHandles;
4646
internal bool paused;
4747

48-
public bool isModulated => (modulation.custom != null) || (modulation.period > 0f);
48+
internal AudioZone zone;
4949

50-
public void SetPaused(bool p)
51-
{
52-
paused = p;
53-
}
50+
public bool isModulated => (modulation.custom != null) || (modulation.period > 0f);
5451

55-
public bool IsPaused()
52+
protected void Awake()
5653
{
57-
return paused;
54+
Reset();
5855
}
5956

6057
protected void Reset()
@@ -67,11 +64,6 @@ protected void Reset()
6764
enabled = controller != Controller.Zone;
6865
}
6966

70-
protected void Awake()
71-
{
72-
Reset();
73-
}
74-
7567
protected void OnEnable()
7668
{
7769
if (autoCue)
@@ -85,6 +77,16 @@ protected void OnDisable()
8577
CueOut();
8678
}
8779

80+
public void SetPaused(bool p)
81+
{
82+
paused = p;
83+
}
84+
85+
public bool IsPaused()
86+
{
87+
return paused;
88+
}
89+
8890
public void CueIn()
8991
{
9092
if (!singleShot || !cuedOnce)
@@ -139,6 +141,7 @@ public struct ModulationParams
139141
[MinMax(0, 2)] public MinMaxFloat volume;
140142
[Range(0, 1800)] public float period;
141143
public bool inverted;
144+
142145
// ReSharper disable once UnassignedField.Global
143146
internal CustomModulator custom;
144147
}

src/Components/AudioParameters.cs

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,30 @@ public struct AudioParameters
2424
public const float defaultSlapbackVolumeAttenuation = 0.4f;
2525
public const float defaultSlapbackPitchAttenuation = 0.8f;
2626

27-
public static readonly AudioParameters defaultAudioParameters = new AudioParameters
27+
public static readonly AudioParameters defaultAudioParameters = new()
2828
{
2929
loop = false,
30-
volume = new MinMaxFloat {min = defaultVolume - defaultVariation, max = defaultVolume + defaultVariation},
31-
pitch = new MinMaxFloat {min = defaultPitch - defaultVariation, max = defaultPitch + defaultVariation},
30+
volume =
31+
new MinMaxFloat
32+
{
33+
min = defaultVolume - defaultVariation,
34+
max = defaultVolume + defaultVariation
35+
},
36+
pitch =
37+
new MinMaxFloat
38+
{
39+
min = defaultPitch - defaultVariation,
40+
max = defaultPitch + defaultVariation
41+
},
3242
spatial =
3343
new SpatialParams
3444
{
3545
blend = defaultBlend,
36-
distance = new MinMaxFloat {min = defaultMinDistance, max = defaultMaxDistance},
46+
distance =
47+
new MinMaxFloat
48+
{
49+
min = defaultMinDistance, max = defaultMaxDistance
50+
},
3751
doppler = defaultDoppler
3852
},
3953
randomization = new RandomizationParams(),
@@ -50,15 +64,35 @@ public struct AudioParameters
5064

5165
[Range(-1, 1)] public float panning;
5266

67+
[Colorize] public EnvelopeParams envelope;
68+
69+
[Colorize] public SpatialParams spatial;
70+
71+
[Colorize] public RandomizationParams randomization;
72+
73+
[Colorize] public OcclusionParams occlusion;
74+
75+
[Colorize] public SlapbackParams slapback;
76+
77+
[Colorize] public RuntimeParams runtime;
78+
79+
public float GetVolume()
80+
{
81+
return volume.GetRandomValue();
82+
}
83+
84+
public float GetPitch()
85+
{
86+
return pitch.GetRandomValue();
87+
}
88+
5389
[Serializable]
5490
public struct EnvelopeParams
5591
{
5692
[Range(0, 60)] public float attack;
5793
[Range(0, 60)] public float release;
5894
}
5995

60-
[Colorize] public EnvelopeParams envelope;
61-
6296
[Serializable]
6397
public struct SpatialParams
6498
{
@@ -67,49 +101,29 @@ public struct SpatialParams
67101
[Range(0, 5)] public float doppler;
68102
}
69103

70-
[Colorize] public SpatialParams spatial;
71-
72104
[Serializable]
73105
public struct RandomizationParams
74106
{
75107
[MinMax(0, 1)] public MinMaxFloat distance;
76108
}
77109

78-
[Colorize] public RandomizationParams randomization;
79-
80110
[Serializable]
81111
public struct OcclusionParams
82112
{
83113
public OcclusionFunction function;
84114
}
85115

86-
[Colorize] public OcclusionParams occlusion;
87-
88116
[Serializable]
89117
public struct SlapbackParams
90118
{
91119
[FormerlySerializedAs("asset")]
92120
public Patch patch;
93121
}
94122

95-
[Colorize] public SlapbackParams slapback;
96-
97123
[Serializable]
98124
public struct RuntimeParams
99125
{
100126
public Priority priority;
101127
}
102-
103-
[Colorize] public RuntimeParams runtime;
104-
105-
public float GetVolume()
106-
{
107-
return volume.GetRandomValue();
108-
}
109-
110-
public float GetPitch()
111-
{
112-
return pitch.GetRandomValue();
113-
}
114128
}
115129
}

src/Components/AudioProgram.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ public class AudioProgram
1818

1919
[Colorize] public bool increment = true;
2020

21-
[HideInInspector] public WeightedDecay weighted;
22-
2321
[Space(10)] [Colorize] public AudioMixerGroup mixerGroup;
2422

25-
[Space(10)] [Colorize] public AudioParameters audioParameters = AudioParameters.defaultAudioParameters;
26-
27-
[NonSerialized] public int lastFrame;
23+
[Space(10)]
24+
[Colorize]
25+
public AudioParameters audioParameters = AudioParameters.defaultAudioParameters;
2826

2927
[NonSerialized] public int clipIndex;
3028

29+
[NonSerialized] public int lastFrame;
30+
3131
[NonSerialized] public Patch patch;
3232

33+
[HideInInspector] public WeightedDecay weighted;
34+
3335
public void Initialize()
3436
{
3537
lastFrame = -1;
@@ -86,7 +88,10 @@ Patch patch
8688
)
8789
{
8890
var delayed = !Mathf.Approximately(ap.delay, 0f);
89-
if (delayed || (!randomize && !increment) || (lastFrame != Time.frameCount) || !Application.isPlaying)
91+
if (delayed ||
92+
(!randomize && !increment) ||
93+
(lastFrame != Time.frameCount) ||
94+
!Application.isPlaying)
9095
{
9196
if (!delayed)
9297
{
@@ -116,7 +121,10 @@ Patch patch
116121
)
117122
{
118123
var delayed = !Mathf.Approximately(ap.delay, 0f);
119-
if (delayed || (!randomize && !increment) || (lastFrame != Time.frameCount) || !Application.isPlaying)
124+
if (delayed ||
125+
(!randomize && !increment) ||
126+
(lastFrame != Time.frameCount) ||
127+
!Application.isPlaying)
120128
{
121129
if (!delayed)
122130
{

src/Components/AudioSequence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AudioSequence
1717
[MinMax(0, 600, colorize = true)]
1818
public MinMaxFloat duration;
1919

20-
[Colorize] public RepeatParams repeat = new RepeatParams {forever = true};
20+
[Colorize] public RepeatParams repeat = new() {forever = true};
2121

2222
[NonSerialized] public uint lastHandle;
2323

0 commit comments

Comments
 (0)