好多新内容

This commit is contained in:
2026-07-22 05:35:53 +08:00
parent b5d1cdcbc5
commit 15649d02f8
128 changed files with 5956 additions and 673 deletions
@@ -5,34 +5,86 @@ public class HoldNoteController : MonoBehaviour
{
private bool isInsideJudgeZone = false;
public event Action<bool> OnJudgeZoneChanged;
// 去物理判定:几何驱动的进入/离开回调(替代 HoldNote 自身的 OnTriggerEnter2D/Exit2D)。
public event Action OnZoneEnterGeometry;
public event Action OnZoneExitGeometry;
private bool isMoving = false;
private float speed = 0f;
private float activationTime;
// 去物理判定:用几何阈值复现 Trigger 进入/离开时刻。
private Collider2D _col;
private float _enterY, _exitY;
private bool _thresholdsReady;
// Absolute positioning for hold segments (keeps segments connected under frame spikes)
private bool useAbsolutePositioning = false;
private Vector3 spawnPosition;
private float baseSpawnYOffset = 0f; // can be negative to offset upward for delayed segments
private float visualOffset = 0f; // additional Y offset for visual compensation
private void Awake()
{
_col = GetComponent<Collider2D>();
// 去物理判定:关闭 Rigidbody2D 模拟,消除每帧移动刚体的物理开销(判定改几何驱动)。
var rb = GetComponent<Rigidbody2D>();
if (rb != null) rb.simulated = false;
}
private void Update()
{
if (useAbsolutePositioning)
{
if (!isMoving) return;
ApplyAbsolutePosition(GameplayClock.NowSongTime);
return;
if (isMoving) ApplyAbsolutePosition(GameplayClock.NowSongTime);
}
else
{
// Start moving after activation time in legacy mode
if (!isMoving && GameplayClock.NowSongTime >= activationTime)
{
isMoving = true;
}
if (isMoving)
{
transform.Translate(Vector3.down * speed * Time.deltaTime);
}
}
// Start moving after activation time in legacy mode
if (!isMoving && GameplayClock.NowSongTime >= activationTime)
// 去物理判定:用几何阈值复现进入/离开判定区(替代 OnTriggerEnter2D/Exit2D)。
UpdateJudgeZoneByGeometry();
}
private void UpdateJudgeZoneByGeometry()
{
if (!_thresholdsReady)
{
isMoving = true;
if (!JudgeZoneGeometry.LineReady) return;
if (_col == null) _col = GetComponent<Collider2D>();
if (!JudgeZoneGeometry.TryGetThresholds(_col, transform, out _enterY, out _exitY)) return;
_thresholdsReady = true;
}
if (isMoving)
float noteY = transform.position.y;
if (!isInsideJudgeZone && noteY <= _enterY)
{
transform.Translate(Vector3.down * speed * Time.deltaTime);
isInsideJudgeZone = true;
// 顺序与原物理一致:先置 hasEnteredLine(OnJudgeZoneChanged),再跑 HoldNote 分段逻辑。
OnJudgeZoneChanged?.Invoke(true);
OnZoneEnterGeometry?.Invoke();
// 单帧穿透:一帧内越过整个判定区,立即补离开,行为与物理一致。
if (noteY <= _exitY)
{
isInsideJudgeZone = false;
OnJudgeZoneChanged?.Invoke(false);
OnZoneExitGeometry?.Invoke();
}
}
else if (isInsideJudgeZone && noteY <= _exitY)
{
isInsideJudgeZone = false;
OnJudgeZoneChanged?.Invoke(false);
OnZoneExitGeometry?.Invoke();
}
}
@@ -88,20 +140,13 @@ public class HoldNoteController : MonoBehaviour
visualOffset = 0f;
}
private void OnTriggerEnter2D(Collider2D collision)
// 去物理判定:进入/离开判定区改由 UpdateJudgeZoneByGeometry 驱动,原 OnTrigger 回调移除。
// 池化复用时重置几何判定状态。
public void ResetJudgeZoneGeometry()
{
if (!collision.CompareTag("JudgmentLine")) return;
isInsideJudgeZone = true;
OnJudgeZoneChanged?.Invoke(true);
}
private void OnTriggerExit2D(Collider2D collision)
{
if (!collision.CompareTag("JudgmentLine")) return;
isInsideJudgeZone = false;
OnJudgeZoneChanged?.Invoke(false);
_thresholdsReady = false;
}
public bool IsInsideJudgArea()