好多新内容
This commit is contained in:
@@ -157,6 +157,13 @@ public class Note : BaseNote
|
||||
float.NaN);
|
||||
}
|
||||
|
||||
// 缓存本音符的实例ID字符串:GameObject 实例ID终身不变(池化复用也不变),
|
||||
// 缓存后避免每次判定/进出判定区都 GetInstanceID().ToString() 分配字符串(热路径 GC)。
|
||||
private string _cachedId;
|
||||
private string CachedId => _cachedId ?? (_cachedId = gameObject.GetInstanceID().ToString());
|
||||
// 供 NoteController 等复用同一缓存id(避免它们各自再 ToString 分配)。
|
||||
public string GetCachedInstanceId() => CachedId;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
anim = AnimationController.Global;
|
||||
@@ -207,7 +214,7 @@ public class Note : BaseNote
|
||||
// Release lock if we still hold it
|
||||
if (hasLock)
|
||||
{
|
||||
TrackKeyManager.Instance?.UnlockTrackForJudge(TrackIndex, gameObject.GetInstanceID().ToString());
|
||||
TrackKeyManager.Instance?.UnlockTrackForJudge(TrackIndex, CachedId);
|
||||
hasLock = false;
|
||||
}
|
||||
}
|
||||
@@ -237,7 +244,7 @@ public class Note : BaseNote
|
||||
{
|
||||
if (isJudged) return;
|
||||
|
||||
string myId = gameObject.GetInstanceID().ToString();
|
||||
string myId = CachedId;
|
||||
|
||||
// Acquire the track lock to stay compatible with the existing single-judge-per-track invariants.
|
||||
bool locked = false;
|
||||
@@ -322,7 +329,7 @@ public class Note : BaseNote
|
||||
if (isJudged || key != keyToPress)
|
||||
return;
|
||||
|
||||
string myId = gameObject.GetInstanceID().ToString();
|
||||
string myId = CachedId;
|
||||
|
||||
// Try to acquire lock for this note (prevents multiple notes on same track being judged at once)
|
||||
if (TrackKeyManager.Instance != null && !TrackKeyManager.Instance.TryLockTrackForJudge(TrackIndex, myId))
|
||||
@@ -502,7 +509,7 @@ public class Note : BaseNote
|
||||
}
|
||||
|
||||
// Remove from per-track queue immediately so following notes become head
|
||||
string myId = gameObject.GetInstanceID().ToString();
|
||||
string myId = CachedId;
|
||||
TrackKeyManager.Instance?.UnregisterKey(TrackIndex, myId);
|
||||
|
||||
// Release lock if we held it
|
||||
@@ -584,7 +591,7 @@ public class Note : BaseNote
|
||||
InputManager.OnKeyPressed -= HandlePress;
|
||||
|
||||
// CRITICAL: Always release lock and unregister before deactivating
|
||||
string myId = gameObject.GetInstanceID().ToString();
|
||||
string myId = CachedId;
|
||||
|
||||
// Release lock if we still hold it
|
||||
ReleaseTrackLock(myId);
|
||||
|
||||
Reference in New Issue
Block a user