谱面改进
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AK.Wwise;
|
||||
using Sirenix.OdinInspector;
|
||||
using SLSUtilities.WwiseAssistance;
|
||||
using UnityEngine;
|
||||
@@ -21,6 +22,9 @@ namespace Ichni
|
||||
public Event ResumeMusicEvent; // 恢复播放背景音乐的事件
|
||||
public Event PauseMusicEvent; // 暂停播放背景音乐的事件
|
||||
public Event StopMusicEvent; // 停止播放背景音乐的事件
|
||||
|
||||
public RTPC HighPassFilter;
|
||||
public RTPC LowPassFilter;
|
||||
|
||||
private uint _playingId;
|
||||
public float songTimeSegment = 0;
|
||||
@@ -36,6 +40,7 @@ namespace Ichni
|
||||
InformationTransistor.instance.songSwitch.SetValue(gameObject);
|
||||
isLoading = true;
|
||||
isStarting = false;
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -73,12 +78,31 @@ namespace Ichni
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
// 获取底层 Wwise 的当前正确时间
|
||||
float currentSongSegment = PlaySegment() / 1000f - (judgeOffset / 1000f);
|
||||
|
||||
if (recordedSongSeg < currentSongSegment)
|
||||
// 1. 让游戏时间先基于引擎渲染帧线性平滑推进
|
||||
songTimeSegment += Time.deltaTime * Time.timeScale;
|
||||
|
||||
// 2. 计算当前平滑时间与底层实际音频时间的误差
|
||||
float difference = currentSongSegment - songTimeSegment;
|
||||
|
||||
// 3. 时间校准逻辑
|
||||
// 如果偏差非常大(例如超过 50ms),说明游戏发生过卡顿停顿,强行同步消除误差
|
||||
if (Mathf.Abs(difference) > 0.05f)
|
||||
{
|
||||
songTimeSegment = currentSongSegment;
|
||||
recordedSongSeg = currentSongSegment;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果在正常范围内,使用微调去柔和追击这个误差,避免肉眼看到跳变(Jitter)
|
||||
songTimeSegment += difference * 0.1f;
|
||||
}
|
||||
|
||||
// 保证时间不要神奇地倒退影响铺面逻辑
|
||||
if (songTimeSegment > recordedSongSeg)
|
||||
{
|
||||
recordedSongSeg = songTimeSegment;
|
||||
}
|
||||
}
|
||||
else if (isPausing)
|
||||
@@ -155,7 +179,7 @@ namespace Ichni
|
||||
int PlaySegment()
|
||||
{
|
||||
AkSegmentInfo segmentInfo = new AkSegmentInfo();
|
||||
AkSoundEngine.GetPlayingSegmentInfo(_playingId, segmentInfo,true);
|
||||
AkUnitySoundEngine.GetPlayingSegmentInfo(_playingId, segmentInfo,true);
|
||||
|
||||
return segmentInfo.iCurrentPosition;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user