修复短音符延迟
This commit is contained in:
@@ -5,23 +5,35 @@ public class NoteController : MonoBehaviour
|
||||
{
|
||||
private float speed;
|
||||
private bool isMoving = true;
|
||||
private bool isInJudgeZone = false; // �������
|
||||
private bool isInJudgeZone = false; // 判定范围内
|
||||
|
||||
private ParticleSystem hitEffect;
|
||||
private Note linkedNote;
|
||||
|
||||
// For absolute position tracking instead of relative translate
|
||||
private Vector3 spawnPosition;
|
||||
private float activationTime = -1f; // When the note should start moving (hitTime - travelTime)
|
||||
private float baseSpawnYOffset = 0f; // Initial Y offset from compensation at spawn time
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
hitEffect = GetComponentInChildren<ParticleSystem>();
|
||||
linkedNote = GetComponent<Note>();
|
||||
spawnPosition = transform.position;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isMoving)
|
||||
if (isMoving && activationTime >= 0f)
|
||||
{
|
||||
transform.Translate(Vector3.down * speed * Time.deltaTime);
|
||||
// Use absolute positioning based on elapsed time since activation
|
||||
float elapsedSinceActivation = Time.time - activationTime;
|
||||
float travelDistance = speed * Mathf.Max(0f, elapsedSinceActivation);
|
||||
|
||||
// Position = spawnPoint + initial offset + downward travel
|
||||
Vector3 newPos = spawnPosition;
|
||||
newPos.y -= (baseSpawnYOffset + travelDistance);
|
||||
transform.position = newPos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,14 +55,28 @@ public class NoteController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configure timing for absolute position tracking.
|
||||
/// Call this from NoteSpawner after the note is spawned.
|
||||
/// </summary>
|
||||
public void ConfigureAbsolutePositioning(Vector3 initialSpawnPos, float hitTime, float travelTime, float initialYOffset)
|
||||
{
|
||||
spawnPosition = initialSpawnPos;
|
||||
activationTime = hitTime - travelTime;
|
||||
baseSpawnYOffset = initialYOffset;
|
||||
|
||||
if (GameConfig.verboseLogs)
|
||||
Debug.Log($"[NoteController] Configured: spawnPos={spawnPosition}, activationTime={activationTime:F3}, initialYOffset={initialYOffset:F4}");
|
||||
}
|
||||
|
||||
public void ResetState()
|
||||
{
|
||||
speed = 0f;
|
||||
isMoving = true;
|
||||
isInJudgeZone = false;
|
||||
activationTime = -1f;
|
||||
baseSpawnYOffset = 0f;
|
||||
spawnPosition = transform.position;
|
||||
|
||||
if (hitEffect != null)
|
||||
{
|
||||
@@ -59,8 +85,6 @@ public class NoteController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// �� OnTriggerEnter2D �� OnTriggerExit2D ������ Controller ��
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.CompareTag("JudgmentLine"))
|
||||
@@ -68,8 +92,8 @@ public class NoteController : MonoBehaviour
|
||||
if (linkedNote != null)
|
||||
{
|
||||
isInJudgeZone = true;
|
||||
TrackKeyManager.Instance.RegisterKey(linkedNote.GetTrackIndex(), linkedNote.GetKey());
|
||||
|
||||
// register note by instance id so TrackKeyManager can prioritize
|
||||
TrackKeyManager.Instance.RegisterKey(linkedNote.GetTrackIndex(), linkedNote.gameObject.GetInstanceID().ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,18 +105,14 @@ public class NoteController : MonoBehaviour
|
||||
if (linkedNote != null)
|
||||
{
|
||||
isInJudgeZone = false;
|
||||
TrackKeyManager.Instance.UnregisterKey(linkedNote.GetTrackIndex(), linkedNote.GetKey());
|
||||
TrackKeyManager.Instance.UnregisterKey(linkedNote.GetTrackIndex(), linkedNote.gameObject.GetInstanceID().ToString());
|
||||
linkedNote.SetJudgeZone(isInJudgeZone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// �� Note ��ѯ�Ƿ����ж�����
|
||||
/// Query Note whether it's in judge zone
|
||||
/// </summary>
|
||||
public bool IsInJudgeZone()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user