Apply sync rate on start

This commit is contained in:
in0finite 2019-05-24 17:09:31 +02:00
parent 06af108c8e
commit 0e6f471db6
2 changed files with 17 additions and 2 deletions

View file

@ -183,6 +183,11 @@ namespace SanAndreasUnity.Behaviours.Vehicles
s_vehicles.Remove(this);
}
void Start()
{
this.ApplySyncRate(VehicleManager.Instance.vehicleSyncRate);
}
public void SetColors(params int[] clrIndices)
{
for (var i = 0; i < 4 && i < clrIndices.Length; ++i)
@ -423,5 +428,16 @@ namespace SanAndreasUnity.Behaviours.Vehicles
if (blinkerMode != VehicleBlinkerMode.None)
blinkerMode = VehicleBlinkerMode.None;
}
public void ApplySyncRate(float syncRate)
{
foreach (var comp in this.GetComponents<Mirror.NetworkBehaviour>())
comp.syncInterval = 1.0f / syncRate;
// also assign it to NetworkTransform, because it may be disabled
if (this.NetTransform != null)
this.NetTransform.syncInterval = 1.0f / syncRate;
}
}
}

View file

@ -110,8 +110,7 @@ namespace SanAndreasUnity.Settings {
VehicleManager.Instance.vehicleSyncRate = syncRate;
foreach (var v in Vehicle.AllVehicles)
{
foreach (var comp in v.GetComponents<Mirror.NetworkBehaviour>())
comp.syncInterval = 1.0f / syncRate;
v.ApplySyncRate(syncRate);
}
}