fixed audio sync issues
This commit is contained in:
parent
eb7826c7c7
commit
3df705dfe5
|
@ -73,7 +73,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
Path: Assets/FMOD/Desktop/Master.bank
|
||||
Name: Master
|
||||
lastModified: 637455820886389038
|
||||
lastModified: 637456045920000000
|
||||
LoadResult: 0
|
||||
FileSizes: []
|
||||
Exists: 1
|
||||
|
@ -122,7 +122,7 @@ MonoBehaviour:
|
|||
- {fileID: -4840949124066270359}
|
||||
StringsBanks:
|
||||
- {fileID: 2930724805879487167}
|
||||
stringsBankWriteTime: 637455820886398947
|
||||
stringsBankWriteTime: 637456045920000000
|
||||
cacheVersion: 4
|
||||
--- !u!114 &2930724805879487167
|
||||
MonoBehaviour:
|
||||
|
@ -138,7 +138,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
Path: Assets/FMOD/Desktop/Master.strings.bank
|
||||
Name: Master.strings
|
||||
lastModified: 637455820886398947
|
||||
lastModified: 637456045920000000
|
||||
LoadResult: 0
|
||||
FileSizes:
|
||||
- Name:
|
||||
|
|
|
@ -135,6 +135,6 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 331122d8907f44ed9b0f8f2337d176b9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
beatsBeforeMove: 160
|
||||
beatsBeforeMove: 16
|
||||
scaleAmount: 1.5
|
||||
numBeatsAfterScale: 0
|
||||
|
|
|
@ -243,9 +243,9 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 4f8399031f014bee928b07d26fe8ee4c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
pauseOnBeat: 160
|
||||
pauseLengthInBeats: 72
|
||||
beatOffset: 16
|
||||
pauseOnBeat: 16
|
||||
pauseLengthInBeats: 8
|
||||
beatOffset: 2
|
||||
--- !u!20 &502054319 stripped
|
||||
Camera:
|
||||
m_CorrespondingSourceObject: {fileID: 3397488660173986648, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
|
||||
|
@ -527,7 +527,7 @@ PrefabInstance:
|
|||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 2085.424
|
||||
value: 1847.5209
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
|
||||
propertyPath: m_LocalScale.y
|
||||
|
@ -774,9 +774,9 @@ MonoBehaviour:
|
|||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
shootOnBeat: 160
|
||||
noTargetLengthInBeats: 72
|
||||
beatOffset: 16
|
||||
shootOnBeat: 16
|
||||
noTargetLengthInBeats: 8
|
||||
beatOffset: 2
|
||||
--- !u!1 &1215971662
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -1,32 +1,51 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using FMOD;
|
||||
using FMODUnity;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
public class AudioBeatManager : MonoBehaviour, IAudioBeatManager
|
||||
{
|
||||
[SerializeField] private float bpm;
|
||||
public float TimeBetweenBeats => _bps * Time.deltaTime;
|
||||
public float TimeBetweenBeats => _secPerBeat;
|
||||
|
||||
private float _bps;
|
||||
private int _currentBeat = 0;
|
||||
private float _timer;
|
||||
|
||||
private float _secPerBeat;
|
||||
|
||||
[SerializeField] [FormerlySerializedAs("OnBeat")]
|
||||
private IntEvent _onBeat;
|
||||
|
||||
public IntEvent OnBeat => _onBeat;
|
||||
public event Action<int> OnBeatEvent;
|
||||
|
||||
private ChannelGroup _channelGroup;
|
||||
private ulong _dspClock;
|
||||
private int _sampleRate;
|
||||
private float _initialPower;
|
||||
|
||||
public float DspTime => _dspClock / (float)_sampleRate;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_bps = bpm / 60f;
|
||||
_secPerBeat = 60f / bpm;
|
||||
_timer = 0;
|
||||
RuntimeManager.CoreSystem.getMasterChannelGroup(out _channelGroup);
|
||||
RuntimeManager.CoreSystem.getSoftwareFormat(out _sampleRate, out _, out _);
|
||||
DOTween.SetTweensCapacity(2000,100);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
_channelGroup.getDSPClock(out _dspClock, out _);
|
||||
_timer += Time.deltaTime;
|
||||
if (_timer >= TimeBetweenBeats)
|
||||
{
|
||||
|
|
|
@ -32,8 +32,8 @@ public class DisableOnDeath : MonoBehaviour
|
|||
var oldName = gameObject.name;
|
||||
gameObject.name = "disabled";
|
||||
_renderer.material.DOColor(Color.white, 0.1f);
|
||||
_renderer.material.DOFade(0, 0.2f).SetDelay(0.3f);
|
||||
transform.DOScale(Vector3.one * 1.5f, 0.5f).SetEase(Ease.OutQuint).OnComplete(() =>
|
||||
_renderer.material.DOFade(0, 0.1f).SetDelay(0.2f);
|
||||
transform.DOScale(Vector3.one * 1.5f, 0.3f).SetEase(Ease.OutQuint).OnComplete(() =>
|
||||
{
|
||||
gameObject.name = oldName;
|
||||
gameObject.SetActive(false);
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
using Utils;
|
||||
|
||||
public class MoveAfterDelay : MonoBehaviour
|
||||
{
|
||||
|
@ -33,10 +31,50 @@ public class MoveAfterDelay : MonoBehaviour
|
|||
{
|
||||
if (beat % beatsBeforeMove != 0) return;
|
||||
|
||||
DOTween.Sequence()
|
||||
.Append(transform.DOScale(Vector3.one * scaleAmount, _audio.TimeBetweenBeats*16).SetEase(Ease.InQuint))
|
||||
.Append(transform.DOScale(Vector3.one, _audio.TimeBetweenBeats*16).SetEase(Ease.OutQuint))
|
||||
.Append(transform.DOMoveZ(-30, 1.0f).SetEase(Ease.InOutQuint).SetDelay(_audio.TimeBetweenBeats * numBeatsAfterScale))
|
||||
.Play();
|
||||
var pos = transform.localPosition;
|
||||
pos.z = 0;
|
||||
var dir = pos.normalized;
|
||||
pos = transform.localPosition;
|
||||
|
||||
DoAnim(pos, dir).Run();
|
||||
}
|
||||
|
||||
private IEnumerator DoAnim(Vector3 pos, Vector3 dir)
|
||||
{
|
||||
var keepGoing = true;
|
||||
var startTime = _audio.DspTime;
|
||||
var targetDSPTime = _audio.TimeBetweenBeats * .25f;
|
||||
|
||||
while (keepGoing)
|
||||
{
|
||||
var currentDSPTime = _audio.DspTime - startTime;
|
||||
|
||||
var t = currentDSPTime / targetDSPTime;
|
||||
transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * scaleAmount, 1 - Mathf.Pow(1 - t, 5));
|
||||
transform.localPosition = Vector3.Lerp(pos, pos + dir * 4, t);
|
||||
if (currentDSPTime >= targetDSPTime)
|
||||
keepGoing = false;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
startTime = _audio.DspTime;
|
||||
keepGoing = true;
|
||||
targetDSPTime = _audio.TimeBetweenBeats * .25f;
|
||||
|
||||
while (keepGoing)
|
||||
{
|
||||
var currentDSPTime = _audio.DspTime - startTime;
|
||||
|
||||
var t = currentDSPTime / targetDSPTime;
|
||||
transform.localScale = Vector3.Lerp(Vector3.one* scaleAmount, Vector3.one, t*t*t*t*t);
|
||||
transform.localPosition = Vector3.Lerp(pos + dir * 4, pos, t);
|
||||
if (currentDSPTime >= targetDSPTime)
|
||||
keepGoing = false;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(_audio.TimeBetweenBeats);
|
||||
|
||||
transform.DOMoveZ(-30, _audio.TimeBetweenBeats * 2).SetEase(Ease.OutQuint);
|
||||
}
|
||||
}
|
|
@ -106,7 +106,7 @@ MonoBehaviour:
|
|||
m_Bits: 64
|
||||
accuracy: 0
|
||||
zone:
|
||||
numToSpawn: 1
|
||||
numToSpawn: 10
|
||||
offset: {x: 0, y: 0}
|
||||
spawnType: 0
|
||||
spawnDir: 0
|
||||
|
|
|
@ -128,7 +128,9 @@ PlayerSettings:
|
|||
16:9: 1
|
||||
Others: 1
|
||||
bundleVersion: 0.1
|
||||
preloadedAssets: []
|
||||
preloadedAssets:
|
||||
- {fileID: 0}
|
||||
- {fileID: 0}
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
m_HolographicPauseOnTrackingLoss: 1
|
||||
|
|
Loading…
Reference in New Issue