fix: stats jamais envoyees - OnDisconnected avant Cleanup + cache du nom joueur

NetworkManager: inverser ordre OnDisconnected/Cleanup pour que les listeners
aient encore acces a LocalPlayerName au moment du callback.

StatsTracker: mettre en cache le nom a la connexion comme fallback supplementaire.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-17 21:55:01 +02:00
parent b3651f8027
commit 385b4f690e
2 changed files with 9 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ public class StatsTracker : MonoBehaviour
private Vector3 _lastPos;
private bool _trackingActive;
private string _cachedName = "";
private PlayerController _pc;
private Rigidbody _rb;
@@ -119,6 +120,7 @@ public class StatsTracker : MonoBehaviour
private void OnConnected()
{
_cachedName = NetworkManager.Instance?.LocalPlayerName ?? "";
_lastPos = transform.position;
_trackingActive = true;
}
@@ -163,9 +165,13 @@ public class StatsTracker : MonoBehaviour
private void SendStats()
{
// Prefer live name, fall back to cached (useful on disconnect where name is cleared)
var nm = NetworkManager.Instance;
if (nm == null || string.IsNullOrEmpty(nm.LocalPlayerName)) return;
StartCoroutine(DoSendStats(nm.LocalPlayerName));
string name = (nm != null && !string.IsNullOrEmpty(nm.LocalPlayerName))
? nm.LocalPlayerName
: _cachedName;
if (string.IsNullOrEmpty(name)) return;
StartCoroutine(DoSendStats(name));
}
private IEnumerator DoSendStats(string playerName)