修复问题,优化bug和游戏,resource资源拆迁
This commit is contained in:
@@ -38,8 +38,25 @@ public class NoteSpawner : MonoBehaviour
|
||||
public int calibrateChecks = 2;
|
||||
[Tooltip("Interval (seconds realtime) between calibration checks.")]
|
||||
public float calibrateInterval = 0.01f;
|
||||
private WaitForSecondsRealtime calibrateWait;
|
||||
private float calibrateWaitSeconds = float.NaN;
|
||||
private class NoteCalibrationJob
|
||||
{
|
||||
public NoteController controller;
|
||||
public GameObject obj;
|
||||
public int remaining;
|
||||
public float nextTime;
|
||||
}
|
||||
|
||||
private class HoldCalibrationJob
|
||||
{
|
||||
public HoldNote hold;
|
||||
public Vector3 spawnPos;
|
||||
public int remaining;
|
||||
public float nextTime;
|
||||
}
|
||||
|
||||
private readonly List<NoteCalibrationJob> noteCalibrationJobs = new List<NoteCalibrationJob>();
|
||||
private readonly List<HoldCalibrationJob> holdCalibrationJobs = new List<HoldCalibrationJob>();
|
||||
private Coroutine calibrationRunner;
|
||||
|
||||
// Documentation text normalized.
|
||||
[Header("Early compensation (experimental)")]
|
||||
@@ -183,6 +200,7 @@ public class NoteSpawner : MonoBehaviour
|
||||
Debug.LogError("加载的谱面为空!");
|
||||
return;
|
||||
}
|
||||
noteIndexToHoldId.Clear();
|
||||
|
||||
// initialize JudgeManager total note count (count each NoteData as one logical note;
|
||||
// long notes are counted once as a single logical note)
|
||||
@@ -320,8 +338,7 @@ public class NoteSpawner : MonoBehaviour
|
||||
noteController.ConfigureAbsolutePositioning(initialPosition, realtimeHit, travelTime, 0f);
|
||||
}
|
||||
|
||||
// Schedule calibration for short note to correct any drift
|
||||
StartCoroutine(CalibrateNoteAfterSpawn(noteController));
|
||||
EnqueueNoteCalibration(noteController);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -424,7 +441,7 @@ public class NoteSpawner : MonoBehaviour
|
||||
// Immediately calibrate position and schedule additional checks to correct any offset
|
||||
Vector3 calibSpawnPos = spawnPoint.position;
|
||||
holdSeg.CalibratePosition(calibSpawnPos, calibrateTolerance);
|
||||
StartCoroutine(CalibrateAfterSpawn(holdSeg, calibSpawnPos));
|
||||
EnqueueHoldCalibration(holdSeg, calibSpawnPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -456,7 +473,7 @@ public class NoteSpawner : MonoBehaviour
|
||||
// schedule calibration for end as well to be safe
|
||||
Vector3 calibEndPos = spawnPoint.position;
|
||||
holdEnd.CalibratePosition(calibEndPos, calibrateTolerance);
|
||||
StartCoroutine(CalibrateAfterSpawn(holdEnd, calibEndPos));
|
||||
EnqueueHoldCalibration(holdEnd, calibEndPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -598,47 +615,108 @@ public class NoteSpawner : MonoBehaviour
|
||||
}
|
||||
|
||||
// --- end of duplicated methods removal ---
|
||||
private IEnumerator CalibrateAfterSpawn(HoldNote seg, Vector3 spawnPos)
|
||||
private void EnqueueNoteCalibration(NoteController noteController)
|
||||
{
|
||||
if (seg == null) yield break;
|
||||
for (int i = 0; i < Mathf.Max(1, calibrateChecks); i++)
|
||||
if (noteController == null) return;
|
||||
int checks = Mathf.Max(1, calibrateChecks);
|
||||
if (checks <= 0) return;
|
||||
GameObject obj = noteController.gameObject;
|
||||
noteCalibrationJobs.Add(new NoteCalibrationJob
|
||||
{
|
||||
yield return GetCalibrateWait();
|
||||
if (seg == null || !seg.gameObject.activeSelf) yield break;
|
||||
seg.CalibratePosition(spawnPos, calibrateTolerance);
|
||||
}
|
||||
controller = noteController,
|
||||
obj = obj,
|
||||
remaining = checks,
|
||||
nextTime = Time.unscaledTime + Mathf.Max(0f, calibrateInterval)
|
||||
});
|
||||
StartCalibrationRunner();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Documentation text normalized.
|
||||
private IEnumerator CalibrateNoteAfterSpawn(NoteController noteController)
|
||||
private void EnqueueHoldCalibration(HoldNote hold, Vector3 spawnPos)
|
||||
{
|
||||
if (noteController == null) yield break;
|
||||
|
||||
GameObject noteObj = noteController.gameObject;
|
||||
for (int i = 0; i < Mathf.Max(1, calibrateChecks); i++)
|
||||
if (hold == null) return;
|
||||
int checks = Mathf.Max(1, calibrateChecks);
|
||||
if (checks <= 0) return;
|
||||
holdCalibrationJobs.Add(new HoldCalibrationJob
|
||||
{
|
||||
yield return GetCalibrateWait();
|
||||
if (noteObj == null || !noteObj.activeSelf) yield break;
|
||||
|
||||
Vector3 expected = noteController.GetExpectedPosition(Time.time);
|
||||
float distanceDeviation = Vector3.Distance(noteObj.transform.position, expected);
|
||||
if (distanceDeviation > calibrateTolerance)
|
||||
hold = hold,
|
||||
spawnPos = spawnPos,
|
||||
remaining = checks,
|
||||
nextTime = Time.unscaledTime + Mathf.Max(0f, calibrateInterval)
|
||||
});
|
||||
StartCalibrationRunner();
|
||||
}
|
||||
|
||||
private void StartCalibrationRunner()
|
||||
{
|
||||
if (calibrationRunner != null) return;
|
||||
calibrationRunner = StartCoroutine(CalibrationRunner());
|
||||
}
|
||||
|
||||
private IEnumerator CalibrationRunner()
|
||||
{
|
||||
while (noteCalibrationJobs.Count > 0 || holdCalibrationJobs.Count > 0)
|
||||
{
|
||||
float now = Time.unscaledTime;
|
||||
|
||||
for (int i = noteCalibrationJobs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
noteObj.transform.position = expected;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[NoteSpawner] Calibrated short note position, deviation was {distanceDeviation:F4}");
|
||||
}
|
||||
}
|
||||
}
|
||||
var job = noteCalibrationJobs[i];
|
||||
if (job == null || job.controller == null || job.obj == null || !job.obj.activeSelf)
|
||||
{
|
||||
noteCalibrationJobs.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
private WaitForSecondsRealtime GetCalibrateWait()
|
||||
{
|
||||
if (calibrateWait == null || calibrateWaitSeconds != calibrateInterval)
|
||||
{
|
||||
calibrateWaitSeconds = calibrateInterval;
|
||||
calibrateWait = new WaitForSecondsRealtime(calibrateInterval);
|
||||
if (now >= job.nextTime)
|
||||
{
|
||||
Vector3 expected = job.controller.GetExpectedPosition(Time.time);
|
||||
float distanceDeviation = Vector3.Distance(job.obj.transform.position, expected);
|
||||
if (distanceDeviation > calibrateTolerance)
|
||||
{
|
||||
job.obj.transform.position = expected;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[NoteSpawner] Calibrated short note position, deviation was {distanceDeviation:F4}");
|
||||
}
|
||||
|
||||
job.remaining--;
|
||||
if (job.remaining <= 0)
|
||||
{
|
||||
noteCalibrationJobs.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
job.nextTime = now + Mathf.Max(0f, calibrateInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = holdCalibrationJobs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var job = holdCalibrationJobs[i];
|
||||
if (job == null || job.hold == null || !job.hold.gameObject.activeSelf)
|
||||
{
|
||||
holdCalibrationJobs.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now >= job.nextTime)
|
||||
{
|
||||
job.hold.CalibratePosition(job.spawnPos, calibrateTolerance);
|
||||
job.remaining--;
|
||||
if (job.remaining <= 0)
|
||||
{
|
||||
holdCalibrationJobs.RemoveAt(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
job.nextTime = now + Mathf.Max(0f, calibrateInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
return calibrateWait;
|
||||
|
||||
calibrationRunner = null;
|
||||
}
|
||||
|
||||
private float CalculateSpeed(float noteTravelTime)
|
||||
|
||||
Reference in New Issue
Block a user