2026-06-13 리듬게임 프로토타입

This commit is contained in:
skrwns304@gmail.com
2026-06-13 03:24:18 +09:00
parent e8086180a0
commit fab54e162e
8 changed files with 202 additions and 4 deletions

View File

@@ -17,6 +17,8 @@ public class RhythmManager : MonoBehaviour
[SerializeField] private float _goodWindow = 0.10f;
[SerializeField] private float _badWindow = 0.15f; // 이 밖이면 입력 무시(헛침)
[SerializeField] private GameObject StartButtonObj;
public float SongTime => _audioSource.time; // 모든 타이밍의 기준
private List<Note> SongNoteList;
@@ -25,6 +27,14 @@ public class RhythmManager : MonoBehaviour
private Func<float> _songTimeProvider; // 노트에 넘길 시간 제공자 (매 스폰마다 람다 재생성 방지용 캐시)
private readonly List<RhythmNoteInstance> _activeNotes = new(); // 화면에 떠 있는(아직 처리 안 된) 노트들
// 점수 상태 (HUD가 읽음). 누적 로직은 RhythmScore가 전담
public RhythmScore Score { get; } = new();
public event Action OnSongStarted; // 곡 시작 (ScoreHud 표시 / ResultHud 숨김)
public event Action<Result> OnJudged; // 노트 하나가 판정될 때마다 (HUD 연출용)
public event Action<RhythmScore> OnScoreChanged; // 점수/콤보가 바뀔 때 (실시간 HUD)
public event Action<RhythmScore> OnSongFinished; // 곡이 끝났을 때 (결과창)
private void Awake()
{
_songTimeProvider = () => SongTime; // 한 번만 만들어 모든 노트가 공유
@@ -80,6 +90,11 @@ public void StartSong()
_nextNoteIndex = 0;
_activeNotes.Clear();
Score.Reset();
OnSongStarted?.Invoke(); // ScoreHud 표시 / ResultHud 숨김
OnScoreChanged?.Invoke(Score); // HUD 초기화(0점)
StartButtonObj.SetActive(false);
_audioSource.Play();
_isPlaying = true;
@@ -90,17 +105,21 @@ public void StartSong()
// 곡 정지 + 주변음 복구
public void StopSong()
{
if (!_isPlaying) return; // 중복 호출 방지(결과창 두 번 뜨는 것 차단)
_audioSource.Stop();
_isPlaying = false;
if (SoundManager.Instance != null) SoundManager.Instance.ExitMinigameMode();
OnSongFinished?.Invoke(Score); // 결과창 표시
}
// 노트가 판정선을 지나쳐 스스로 Miss 처리될 때 호출 (노트는 이미 자기 파괴됨)
private void OnNoteMissed(RhythmNoteInstance note)
{
_activeNotes.Remove(note);
// TODO: 점수/콤보 시스템 연결 시 Miss 반영
ApplyJudge(Result.Miss);
Debug.Log("[Rhythm] Miss (지나침)");
}
@@ -134,10 +153,18 @@ public void OnPlayerInput()
_activeNotes.Remove(target);
Destroy(target.gameObject);
// TODO: 점수/콤보 시스템 연결 시 result 반영
ApplyJudge(result);
Debug.Log($"[Rhythm] {result} (diff {bestDiff:F3}s)");
}
// 판정 결과를 점수에 반영하고 이벤트로 알림
private void ApplyJudge(Result result)
{
Score.Apply(result);
OnJudged?.Invoke(result);
OnScoreChanged?.Invoke(Score);
}
// diff = 절대 시간차(초). 윈도우 안이면 Perfect/Good/Bad, 밖이면 Miss(입력 무시)
public Result Judge(float diff)
{