Sync vehicle controls (ignition, engine, lights ...), stop forced starter sound, auto-reconnect after server restart or lost connection
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+28
-1
@@ -46,6 +46,7 @@ namespace MSCO
|
||||
class Snapshot
|
||||
{
|
||||
public float ReceivedAt;
|
||||
public bool Released; // nach dem Timeout einmal freigegeben
|
||||
public readonly Dictionary<int, bool> Lights = new Dictionary<int, bool>();
|
||||
public readonly Dictionary<int, AudioState> Audio = new Dictionary<int, AudioState>();
|
||||
public readonly Dictionary<int, Quaternion> Dials = new Dictionary<int, Quaternion>();
|
||||
@@ -161,11 +162,17 @@ namespace MSCO
|
||||
{
|
||||
foreach (KeyValuePair<int, Snapshot> kv in incoming)
|
||||
{
|
||||
if (Time.time - kv.Value.ReceivedAt > ApplyTimeout) continue;
|
||||
SyncedBody b = objects.Get(kv.Key);
|
||||
if (b == null || objects.IsLocalBody(b)) continue; // eigene Fahrzeuge simulieren wir selbst
|
||||
Components c = GetComponents(b);
|
||||
if (c == null) continue;
|
||||
if (Time.time - kv.Value.ReceivedAt > ApplyTimeout)
|
||||
{
|
||||
// Keine Daten mehr (Fahrer ausgestiegen o.ä.): einmal alles loslassen, was wir erzwungen haben -
|
||||
// sonst läuft z.B. das Anlasser-Geräusch endlos weiter ("orgelt")
|
||||
if (!kv.Value.Released) Release(kv.Value, c);
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<int, bool> l in kv.Value.Lights)
|
||||
{
|
||||
@@ -192,6 +199,26 @@ namespace MSCO
|
||||
}
|
||||
}
|
||||
|
||||
static void Release(Snapshot s, Components c)
|
||||
{
|
||||
s.Released = true;
|
||||
foreach (KeyValuePair<int, AudioState> a in s.Audio)
|
||||
{
|
||||
AudioSource src;
|
||||
if (a.Value.Playing && c.Audio.TryGetValue(a.Key, out src) && src != null && src.isPlaying) src.Stop();
|
||||
}
|
||||
foreach (KeyValuePair<int, bool> p in s.Particles)
|
||||
{
|
||||
ParticleSystem ps;
|
||||
if (p.Value && c.Particles.TryGetValue(p.Key, out ps) && ps != null && ps.isPlaying) ps.Stop();
|
||||
}
|
||||
foreach (KeyValuePair<int, bool> l in s.Lights)
|
||||
{
|
||||
Light light;
|
||||
if (l.Value && c.Lights.TryGetValue(l.Key, out light) && light != null) light.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void SetLight(Light light, bool on, Transform root)
|
||||
{
|
||||
if (!on)
|
||||
|
||||
Reference in New Issue
Block a user