-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioSourceTracker.cs
85 lines (73 loc) · 2.37 KB
/
AudioSourceTracker.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
using GameManagement;
using ReplayEditor;
using System.Collections.Generic;
using UnityEngine;
namespace walking_mod
{
class AudioSourceTimeTracker
{
public List<float> time = new List<float>();
public List<bool> play_state = new List<bool>();
public void pushState(float time, bool isPlaying)
{
this.time.Add(time);
this.play_state.Add(isPlaying);
}
public void Shift()
{
this.time.RemoveAt(0);
this.play_state.RemoveAt(0);
}
}
class AudioSourceTracker : MonoBehaviour
{
public AudioSourceTimeTracker tracker;
public float nextRecordTime;
public float spf = 24f;
public AudioSource audio_source;
public int BufferFrameCount;
public void Start()
{
tracker = new AudioSourceTimeTracker();
audio_source = GetComponent<AudioSource>();
BufferFrameCount = Mathf.RoundToInt(ReplaySettings.Instance.FPS * ReplaySettings.Instance.MaxRecordedTime);
ResetAudio();
}
public void Update()
{
if (GameStateMachine.Instance.CurrentState.GetType() == typeof(ReplayState))
{
int index = getFrame();
if (tracker.play_state[index] && !audio_source.isPlaying)
{
audio_source.Play(0);
audio_source.pitch = ReplayEditorController.Instance.playbackController.TimeScale;
}
if (!tracker.play_state[index] && audio_source.isPlaying)
{
audio_source.Stop();
}
}
if (GameStateMachine.Instance.CurrentState.GetType() == typeof(PlayState))
{
tracker.pushState(PlayTime.time, audio_source.isPlaying);
if (tracker.time.Count >= BufferFrameCount)
{
tracker.Shift();
}
}
}
float last_time, last_anim_time;
public void ResetAudio()
{
}
public int getFrame()
{
for (int i = tracker.time.Count - 1; i >= 0; i--)
{
if (tracker.time[i] <= ReplayEditorController.Instance.playbackController.CurrentTime) return i;
}
return -1;
}
}
}