블랙잭 지형 복구 저장
This commit is contained in:
47
Assets/02_Scripts/Rhythm/RhythmNoteInstance.cs
Normal file
47
Assets/02_Scripts/Rhythm/RhythmNoteInstance.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class RhythmNoteInstance : MonoBehaviour
|
||||
{
|
||||
public float HitTime; // 이 노트의 도달 시각
|
||||
|
||||
[SerializeField] private float _missWindow = 0.15f; // 판정선을 이만큼 지나면 자동 Miss
|
||||
|
||||
private Vector3 _start; // 출발점
|
||||
private Vector3 _target; // 목적지(판정선)
|
||||
private float _spawnTime; // 생성된 시각 (= HitTime - leadTime)
|
||||
private Func<float> _songTime; // 오디오 기준 현재 곡 시간 제공자
|
||||
private Action<RhythmNoteInstance> _onMiss; // 지나쳐서 Miss 났을 때 통지
|
||||
|
||||
// 스폰 시 목적지·타이밍 주입 (B 방식)
|
||||
public void Setup(Vector3 start, Vector3 target, float spawnTime, float hitTime,
|
||||
Func<float> songTime, Action<RhythmNoteInstance> onMiss = null)
|
||||
{
|
||||
_start = start;
|
||||
_target = target;
|
||||
_spawnTime = spawnTime;
|
||||
HitTime = hitTime;
|
||||
_songTime = songTime;
|
||||
_onMiss = onMiss;
|
||||
|
||||
transform.position = start;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_songTime == null) return;
|
||||
|
||||
float now = _songTime();
|
||||
|
||||
// SongTime 기반 보간: spawnTime → HitTime 구간을 0→1로
|
||||
float t = Mathf.InverseLerp(_spawnTime, HitTime, now);
|
||||
transform.position = Vector3.LerpUnclamped(_start, _target, t);
|
||||
|
||||
// 판정선을 missWindow 이상 지나치면 Miss 처리 후 자기 파괴
|
||||
if (now > HitTime + _missWindow)
|
||||
{
|
||||
_onMiss?.Invoke(this);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Rhythm/RhythmNoteInstance.cs.meta
Normal file
2
Assets/02_Scripts/Rhythm/RhythmNoteInstance.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 546c777d5bfdff84aa0ddda3f54f256a
|
||||
19
Assets/02_Scripts/Rhythm/RhythmNoteSpawner.cs
Normal file
19
Assets/02_Scripts/Rhythm/RhythmNoteSpawner.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class RhythmNoteSpawner : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RhythmNoteInstance _notePrefab; // 생성할 노트 프리팹
|
||||
[SerializeField] private Transform _spawnPoint; // 노트가 생겨나는 위치(미지정 시 자기 위치)
|
||||
[SerializeField] private Transform _judgmentLine; // 목적지(판정선)
|
||||
|
||||
// 노트 프리팹 생성, 목적지·타이밍 주입
|
||||
public RhythmNoteInstance SpawnNote(Note note, float spawnTime,
|
||||
Func<float> songTime, Action<RhythmNoteInstance> onMiss = null)
|
||||
{
|
||||
Transform origin = _spawnPoint != null ? _spawnPoint : transform;
|
||||
RhythmNoteInstance instance = Instantiate(_notePrefab, origin.position, origin.rotation, transform);
|
||||
instance.Setup(origin.position, _judgmentLine.position, spawnTime, note.Time, songTime, onMiss);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Rhythm/RhythmNoteSpawner.cs.meta
Normal file
2
Assets/02_Scripts/Rhythm/RhythmNoteSpawner.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abb0f221706db8046bb92ddda946d65b
|
||||
Reference in New Issue
Block a user