리플레이 코드 수정

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: 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}

View File

@ -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}

View File

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

View File

@ -4,50 +4,30 @@ using System.Collections.Generic;
public class GhostController : MonoBehaviour
{
private PlayerMovement _playerMovement;
private Queue<InputFrame> inputFrames;
private bool isPlaying = false;
private void Awake()
{
_playerMovement = GetComponent<PlayerMovement>();
}
public void Init(List<InputFrame> recordedData)
public void GhostRunInput(InputFrame inputFrame)
{
inputFrames = new Queue<InputFrame>(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));
}
}

View File

@ -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<List<InputFrame>> allRecordedFrames = new List<List<InputFrame>>();
private List<ActiveGhost> activeGhostList = new List<ActiveGhost>();
private InputRecorder currentPlayerRecorder;
private GameObject currentPlayer;
private List<GameObject> ghostList = new List<GameObject>();
private int currentReplayIndex;
private bool isPlaying = false;
private void Awake()
{
@ -35,12 +39,40 @@ 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<InputRecorder>();
currentPlayerRecorder.StartRecording();
activeGhostList.Clear();
if (!(allRecordedFrames.Count > 0))
{
return;
@ -48,25 +80,44 @@ public class RecordingManager : MonoBehaviour
foreach (var record in allRecordedFrames)
{
GameObject ghost = Instantiate(ghostPrefab, spawnPoint.position, Quaternion.identity);
ghostList.Add(ghost);
ghost.GetComponent<GhostController>().Init(record);
for(int i = 0 ;i < 500; i++)
{
GameObject ghost = Instantiate(ghostPrefab, spawnPoint.position, Quaternion.identity);
GhostController ghostController = ghost.GetComponent<GhostController>();
ActiveGhost addedGhost = new ActiveGhost();
addedGhost.controller = ghostController;
addedGhost.recordedFrames = record;
activeGhostList.Add(addedGhost);
}
}
}
public void StopPlayingRecord()
{
isPlaying = false;
currentPlayerRecorder.StopRecording();
List<InputFrame> 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<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