리플레이 코드 수정

500마리 아직 버겁지만 이젠 돌아는 간다
This commit is contained in:
백민승_crow 2026-02-02 09:48:51 +09:00
parent 0e4d33c341
commit cd59821b0e
13 changed files with 78 additions and 46 deletions

View File

@ -11,7 +11,7 @@ GameObject:
- component: {fileID: 8354061827391739510} - component: {fileID: 8354061827391739510}
- component: {fileID: 8460095861745857899} - component: {fileID: 8460095861745857899}
- component: {fileID: 5965616281446492719} - component: {fileID: 5965616281446492719}
m_Layer: 6 m_Layer: 7
m_Name: Foot m_Name: Foot
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
@ -307,7 +307,7 @@ GameObject:
- component: {fileID: 1806536103398767836} - component: {fileID: 1806536103398767836}
- component: {fileID: 4853694680767308140} - component: {fileID: 4853694680767308140}
- component: {fileID: 1591313861624791812} - component: {fileID: 1591313861624791812}
m_Layer: 0 m_Layer: 7
m_Name: Hang m_Name: Hang
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}

View File

@ -256,7 +256,7 @@ GameObject:
- component: {fileID: 7944902203221672218} - component: {fileID: 7944902203221672218}
- component: {fileID: 6414477000461253142} - component: {fileID: 6414477000461253142}
- component: {fileID: 6481877445078531268} - component: {fileID: 6481877445078531268}
m_Layer: 0 m_Layer: 6
m_Name: Hang m_Name: Hang
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}

View File

@ -70,6 +70,7 @@ public class PlayerMovement : MonoBehaviour
{ {
isHanging = false; isHanging = false;
_rigidbody2D.bodyType = RigidbodyType2D.Dynamic; _rigidbody2D.bodyType = RigidbodyType2D.Dynamic;
transform.parent = null;
} }
private void HangingObject() private void HangingObject()

View File

@ -4,50 +4,30 @@ using System.Collections.Generic;
public class GhostController : MonoBehaviour public class GhostController : MonoBehaviour
{ {
private PlayerMovement _playerMovement; private PlayerMovement _playerMovement;
private Queue<InputFrame> inputFrames;
private bool isPlaying = false;
private void Awake() private void Awake()
{ {
_playerMovement = GetComponent<PlayerMovement>(); _playerMovement = GetComponent<PlayerMovement>();
} }
public void Init(List<InputFrame> recordedData) public void GhostRunInput(InputFrame inputFrame)
{ {
inputFrames = new Queue<InputFrame>(recordedData); _playerMovement.SetMoveInput(new Vector2(inputFrame.moveX, 0));
isPlaying = true; if (inputFrame.isJumpPressed)
}
private void FixedUpdate()
{
if (!isPlaying)
{
return;
}
if (inputFrames.Count > 0)
{
InputFrame frame = inputFrames.Dequeue();
_playerMovement.SetMoveInput(new Vector2(frame.moveX, 0));
if (frame.isJumpPressed)
{ {
_playerMovement.TryJump(); _playerMovement.TryJump();
} }
if (frame.isHangPressed) if (inputFrame.isHangPressed)
{ {
_playerMovement.TryHang(); _playerMovement.TryHang();
} }
} }
else
{
_playerMovement.SetMoveInput(Vector2.zero);
isPlaying = false;
// 제거할지 아니면 멈출지 고민해보기? ㅋㅋ public void StopGhost()
} {
GhostRunInput(new InputFrame(0f, false, false));
} }
} }

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -13,10 +14,13 @@ public class RecordingManager : MonoBehaviour
public Transform spawnPoint; public Transform spawnPoint;
private List<List<InputFrame>> allRecordedFrames = new List<List<InputFrame>>(); private List<List<InputFrame>> allRecordedFrames = new List<List<InputFrame>>();
private List<ActiveGhost> activeGhostList = new List<ActiveGhost>();
private InputRecorder currentPlayerRecorder; private InputRecorder currentPlayerRecorder;
private GameObject currentPlayer; private GameObject currentPlayer;
private List<GameObject> ghostList = new List<GameObject>(); private int currentReplayIndex;
private bool isPlaying = false;
private void Awake() private void Awake()
{ {
@ -35,38 +39,85 @@ public class RecordingManager : MonoBehaviour
PlayerAllRecord(); 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() public void PlayerAllRecord()
{ {
isPlaying = true;
currentReplayIndex = 0;
currentPlayer = Instantiate(playerPrefab, spawnPoint.position, Quaternion.identity); currentPlayer = Instantiate(playerPrefab, spawnPoint.position, Quaternion.identity);
currentPlayerRecorder = currentPlayer.GetComponent<InputRecorder>(); currentPlayerRecorder = currentPlayer.GetComponent<InputRecorder>();
currentPlayerRecorder.StartRecording(); currentPlayerRecorder.StartRecording();
activeGhostList.Clear();
if (!(allRecordedFrames.Count > 0)) if (!(allRecordedFrames.Count > 0))
{ {
return; return;
} }
foreach (var record in allRecordedFrames) foreach (var record in allRecordedFrames)
{
for(int i = 0 ;i < 500; i++)
{ {
GameObject ghost = Instantiate(ghostPrefab, spawnPoint.position, Quaternion.identity); GameObject ghost = Instantiate(ghostPrefab, spawnPoint.position, Quaternion.identity);
ghostList.Add(ghost); GhostController ghostController = ghost.GetComponent<GhostController>();
ghost.GetComponent<GhostController>().Init(record);
ActiveGhost addedGhost = new ActiveGhost();
addedGhost.controller = ghostController;
addedGhost.recordedFrames = record;
activeGhostList.Add(addedGhost);
}
} }
} }
public void StopPlayingRecord() public void StopPlayingRecord()
{ {
isPlaying = false;
currentPlayerRecorder.StopRecording(); currentPlayerRecorder.StopRecording();
List<InputFrame> inputFrames = currentPlayerRecorder.GetInputFrames(); List<InputFrame> inputFrames = currentPlayerRecorder.GetInputFrames();
allRecordedFrames.Add(inputFrames); allRecordedFrames.Add(inputFrames);
Destroy(currentPlayer); Destroy(currentPlayer);
foreach (GameObject ghost in ghostList) foreach (var ghost in activeGhostList)
{ {
Destroy(ghost); Destroy(ghost.controller.gameObject);
} }
activeGhostList.Clear();
Invoke("PlayerAllRecord", 1f); Invoke("PlayerAllRecord", 1f);
} }
} }
[System.Serializable]
public class ActiveGhost
{
public GhostController controller;
public List<InputFrame> recordedFrames;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB