using System; using System.Collections.Generic; using UnityEngine; public class RecordingManager : MonoBehaviour { public static RecordingManager instance; [Header("프리팹 설정")] [SerializeField] private GameObject playerPrefab; [SerializeField] private GameObject ghostPrefab; [Header("스폰 위치")] public Transform spawnPoint; private List> allRecordedFrames = new List>(); private List activeGhostList = new List(); private InputRecorder currentPlayerRecorder; private GameObject currentPlayer; private int currentReplayIndex; private bool isPlaying = false; private void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); } } private void Start() { PlayerAllRecord(); } private void FixedUpdate() { if (!isPlaying) { return; } for (int i = 0; i < activeGhostList.Count; i++) { ActiveGhost ghost = activeGhostList[i]; if (currentReplayIndex < ghost.recordedFrames.Count) { ghost.controller.GhostRunInput(ghost.recordedFrames[currentReplayIndex]); } else { ghost.controller.StopGhost(); } } currentReplayIndex++; } public void PlayerAllRecord() { isPlaying = true; currentReplayIndex = 0; currentPlayer = Instantiate(playerPrefab, spawnPoint.position, Quaternion.identity); currentPlayerRecorder = currentPlayer.GetComponent(); currentPlayerRecorder.StartRecording(); activeGhostList.Clear(); if (!(allRecordedFrames.Count > 0)) { return; } foreach (var record in allRecordedFrames) { // for(int i = 0 ;i < 1; i++) // { GameObject ghost = Instantiate(ghostPrefab, spawnPoint.position, Quaternion.identity); GhostController ghostController = ghost.GetComponent(); ActiveGhost addedGhost = new ActiveGhost(); addedGhost.controller = ghostController; addedGhost.recordedFrames = record; activeGhostList.Add(addedGhost); // } } } public void StopPlayingRecord() { isPlaying = false; currentPlayerRecorder.StopRecording(); List inputFrames = currentPlayerRecorder.GetInputFrames(); allRecordedFrames.Add(inputFrames); Destroy(currentPlayer); foreach (var ghost in activeGhostList) { Destroy(ghost.controller.gameObject); } activeGhostList.Clear(); Invoke("PlayerAllRecord", 1f); } } [System.Serializable] public class ActiveGhost { public GhostController controller; public List recordedFrames; }