-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSubtitledSound.cs
More file actions
54 lines (42 loc) · 1.08 KB
/
SubtitledSound.cs
File metadata and controls
54 lines (42 loc) · 1.08 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
using Godot;
public partial class SubtitledSound : AudioStreamPlayer3D
{
[Export]
private string subtitle;
[Export(PropertyHint.Range, "0,5,")]
private float visualVolumeMultiplier = 1;
[Export]
private float fuzziness = 0f;
private bool curPlaying = false;
private int id = 0;
public override void _Ready()
{
TreeExiting += StopOnExit;
Finished += StopSubtitle;
}
public override void _Process(double delta)
{
if(curPlaying && !Playing)
StopSubtitle();
else if(!curPlaying && Playing)
StartSubtitle();
}
private void StartSubtitle()
{
curPlaying = true;
float m = MaxDistance;
//Right now, the loudness of the sound is set via the visual volume multiplier property.
//I'll change it to automatically detecting it based on the sound once I figure out how to do it.
id = SubtitleManager.StartSubtitle(this, VolumeDb, UnitSize * visualVolumeMultiplier, m, subtitle, fuzziness:fuzziness);
}
private void StopSubtitle()
{
curPlaying = false;
SubtitleManager.StopSubtitle(id);
}
private void StopOnExit()
{
if(curPlaying)
StopSubtitle();
}
}