diff --git a/Assets/Prefabs/Ghost.prefab b/Assets/Prefabs/Ghost.prefab index 1acd1d7..36c6acb 100644 --- a/Assets/Prefabs/Ghost.prefab +++ b/Assets/Prefabs/Ghost.prefab @@ -11,7 +11,7 @@ GameObject: - component: {fileID: 8354061827391739510} - component: {fileID: 8460095861745857899} - component: {fileID: 5965616281446492719} - m_Layer: 6 + m_Layer: 7 m_Name: Foot m_TagString: Untagged m_Icon: {fileID: 0} @@ -307,7 +307,7 @@ GameObject: - component: {fileID: 1806536103398767836} - component: {fileID: 4853694680767308140} - component: {fileID: 1591313861624791812} - m_Layer: 0 + m_Layer: 7 m_Name: Hang m_TagString: Untagged m_Icon: {fileID: 0} diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 982ad04..991dbaf 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -256,7 +256,7 @@ GameObject: - component: {fileID: 7944902203221672218} - component: {fileID: 6414477000461253142} - component: {fileID: 6481877445078531268} - m_Layer: 0 + m_Layer: 6 m_Name: Hang m_TagString: Untagged m_Icon: {fileID: 0} diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index bd704c9..cdd458e 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -70,6 +70,7 @@ public class PlayerMovement : MonoBehaviour { isHanging = false; _rigidbody2D.bodyType = RigidbodyType2D.Dynamic; + transform.parent = null; } private void HangingObject() diff --git a/Assets/Scripts/Replay/GhostController.cs b/Assets/Scripts/Replay/GhostController.cs index 88baff0..9424405 100644 --- a/Assets/Scripts/Replay/GhostController.cs +++ b/Assets/Scripts/Replay/GhostController.cs @@ -4,50 +4,30 @@ using System.Collections.Generic; public class GhostController : MonoBehaviour { private PlayerMovement _playerMovement; - private Queue inputFrames; - - private bool isPlaying = false; private void Awake() { _playerMovement = GetComponent(); } - public void Init(List recordedData) + public void GhostRunInput(InputFrame inputFrame) { - inputFrames = new Queue(recordedData); - isPlaying = true; + _playerMovement.SetMoveInput(new Vector2(inputFrame.moveX, 0)); + if (inputFrame.isJumpPressed) + { + _playerMovement.TryJump(); + } + + if (inputFrame.isHangPressed) + { + _playerMovement.TryHang(); + } } - private void FixedUpdate() + public void StopGhost() { - if (!isPlaying) - { - return; - } - - if (inputFrames.Count > 0) - { - InputFrame frame = inputFrames.Dequeue(); - - _playerMovement.SetMoveInput(new Vector2(frame.moveX, 0)); - - if (frame.isJumpPressed) - { - _playerMovement.TryJump(); - } - - if (frame.isHangPressed) - { - _playerMovement.TryHang(); - } - } - else - { - _playerMovement.SetMoveInput(Vector2.zero); - isPlaying = false; - - // 제거할지 아니면 멈출지 고민해보기? ㅋㅋ - } + GhostRunInput(new InputFrame(0f, false, false)); } } + + diff --git a/Assets/Scripts/Replay/RecordingManager.cs b/Assets/Scripts/Replay/RecordingManager.cs index 64ba8c4..223de9c 100644 --- a/Assets/Scripts/Replay/RecordingManager.cs +++ b/Assets/Scripts/Replay/RecordingManager.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; @@ -13,10 +14,13 @@ public class RecordingManager : MonoBehaviour public Transform spawnPoint; private List> allRecordedFrames = new List>(); + private List activeGhostList = new List(); private InputRecorder currentPlayerRecorder; private GameObject currentPlayer; - private List ghostList = new List(); + private int currentReplayIndex; + + private bool isPlaying = false; private void Awake() { @@ -34,39 +38,86 @@ public class RecordingManager : MonoBehaviour { 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) { - GameObject ghost = Instantiate(ghostPrefab, spawnPoint.position, Quaternion.identity); - ghostList.Add(ghost); - ghost.GetComponent().Init(record); + for(int i = 0 ;i < 500; 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 (GameObject ghost in ghostList) + foreach (var ghost in activeGhostList) { - Destroy(ghost); + Destroy(ghost.controller.gameObject); } + activeGhostList.Clear(); Invoke("PlayerAllRecord", 1f); } } + +[System.Serializable] +public class ActiveGhost +{ + public GhostController controller; + public List recordedFrames; +} diff --git a/ProfilerCaptures/tmp_2026-02-02_08-37-54.bc7 b/ProfilerCaptures/tmp_2026-02-02_08-37-54.bc7 new file mode 100644 index 0000000..21014e4 Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-37-54.bc7 differ diff --git a/ProfilerCaptures/tmp_2026-02-02_08-37-54.data b/ProfilerCaptures/tmp_2026-02-02_08-37-54.data new file mode 100644 index 0000000..0e657f1 Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-37-54.data differ diff --git a/ProfilerCaptures/tmp_2026-02-02_08-37-54.highlights b/ProfilerCaptures/tmp_2026-02-02_08-37-54.highlights new file mode 100644 index 0000000..1439a3c Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-37-54.highlights differ diff --git a/ProfilerCaptures/tmp_2026-02-02_08-37-54.png b/ProfilerCaptures/tmp_2026-02-02_08-37-54.png new file mode 100644 index 0000000..235e446 Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-37-54.png differ diff --git a/ProfilerCaptures/tmp_2026-02-02_08-38-07.bc7 b/ProfilerCaptures/tmp_2026-02-02_08-38-07.bc7 new file mode 100644 index 0000000..21014e4 Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-38-07.bc7 differ diff --git a/ProfilerCaptures/tmp_2026-02-02_08-38-07.data b/ProfilerCaptures/tmp_2026-02-02_08-38-07.data new file mode 100644 index 0000000..0e657f1 Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-38-07.data differ diff --git a/ProfilerCaptures/tmp_2026-02-02_08-38-07.highlights b/ProfilerCaptures/tmp_2026-02-02_08-38-07.highlights new file mode 100644 index 0000000..1439a3c Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-38-07.highlights differ diff --git a/ProfilerCaptures/tmp_2026-02-02_08-38-07.png b/ProfilerCaptures/tmp_2026-02-02_08-38-07.png new file mode 100644 index 0000000..235e446 Binary files /dev/null and b/ProfilerCaptures/tmp_2026-02-02_08-38-07.png differ