private void InitialiseCheckpointsIntoReplay() { // SUPER EXPENSIVE!! THIS SHOULD BE BAKED DURING BUILDING, NOT RAN EVERY PLAY :( if (replaySnapshots == null) { return; } int index = 0; List <Checkpoint> checkpoints = GameObject.FindObjectsOfType <Checkpoint>().ToList(); float minSqrDistance = float.PositiveInfinity; for (int i = 0; i != replaySnapshots.Count; i++) { Recorder.Snapshot snapshot = replaySnapshots[i]; float currentMinSqrDistance = float.PositiveInfinity; Checkpoint nearestCheckpoint = null; foreach (Checkpoint checkpoint in checkpoints) { float sqrDistance = (checkpoint.spawn.transform.position - snapshot.position).sqrMagnitude; if (sqrDistance < currentMinSqrDistance) { nearestCheckpoint = checkpoint; currentMinSqrDistance = sqrDistance; } } if (currentMinSqrDistance > minSqrDistance) { nearestCheckpoint.Index = index; nearestCheckpoint.SnapshotIndex = i; index++; checkpoints.Remove(nearestCheckpoint); minSqrDistance = float.PositiveInfinity; } else { minSqrDistance = currentMinSqrDistance; } if (!checkpoints.Any()) { break; } } }
void moveToNextSnapshot() { currentSnapshot = Snapshots[snapshotIndex]; previousSnapshot = null; nextSnapshot = null; previousVelocity = Vector3.zero; if (snapshotIndex > 0) { previousSnapshot = Snapshots[snapshotIndex - 1]; previousVelocity = (currentSnapshot.position - previousSnapshot.position); } if (snapshotIndex + 1 < Snapshots.Count) { nextSnapshot = Snapshots[snapshotIndex + 1]; nextVelocity = (nextSnapshot.position - currentSnapshot.position); } snapshotIndex++; }
public void StopPlayback() { playback = false; snapshotIndex = 0; currentSnapshot = null; }